| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_DER_PARSER_H_ | 5 #ifndef NET_DER_PARSER_H_ |
| 6 #define NET_DER_PARSER_H_ | 6 #define NET_DER_PARSER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 bool ReadConstructed(Tag tag, Parser* out) WARN_UNUSED_RESULT; | 138 bool ReadConstructed(Tag tag, Parser* out) WARN_UNUSED_RESULT; |
| 139 | 139 |
| 140 // A more specific form of ReadConstructed that expects the current tag | 140 // A more specific form of ReadConstructed that expects the current tag |
| 141 // to be 0x30 (SEQUENCE). | 141 // to be 0x30 (SEQUENCE). |
| 142 bool ReadSequence(Parser* out) WARN_UNUSED_RESULT; | 142 bool ReadSequence(Parser* out) WARN_UNUSED_RESULT; |
| 143 | 143 |
| 144 // Expects the current tag to be kInteger, and calls ParseUint64 on the | 144 // Expects the current tag to be kInteger, and calls ParseUint64 on the |
| 145 // current value. Note that DER-encoded integers are arbitrary precision, | 145 // current value. Note that DER-encoded integers are arbitrary precision, |
| 146 // so this method will fail for valid input that represents an integer | 146 // so this method will fail for valid input that represents an integer |
| 147 // outside the range of an int64. | 147 // outside the range of an int64. |
| 148 // |
| 149 // Note that on failure the Parser is left in an undefined state (the |
| 150 // input may or may not have been advanced). |
| 148 bool ReadUint64(uint64_t* out) WARN_UNUSED_RESULT; | 151 bool ReadUint64(uint64_t* out) WARN_UNUSED_RESULT; |
| 149 | 152 |
| 153 // Reads a BIT STRING. On success |bytes| is set to the octet string |
| 154 // containing the bits, and |unused_bits| is set to the number of |
| 155 // bits (in the range 0-7) that are unused. |
| 156 // |
| 157 // The bits are ordered within each octet of |bytes| from most to |
| 158 // least significant, as in the DER encoding. |
| 159 // |
| 160 // Note that on failure the Parser is left in an undefined state (the |
| 161 // input may or may not have been advanced). |
| 162 bool ReadBitString(Input* bytes, uint8_t* unused_bits) WARN_UNUSED_RESULT; |
| 163 |
| 164 // Same as ReadBitString() except it will only succeed when the number of |
| 165 // bits in the bit string is a multiple of 8. In other words, there can be |
| 166 // no unused bits in the octet string |*bytes|. |
| 167 bool ReadBitStringNoUnusedBits(Input* bytes) WARN_UNUSED_RESULT; |
| 168 |
| 150 // Lower level methods. The previous methods couple reading data from the | 169 // Lower level methods. The previous methods couple reading data from the |
| 151 // input with advancing the Parser's internal pointer to the next TLV; these | 170 // input with advancing the Parser's internal pointer to the next TLV; these |
| 152 // lower level methods decouple those two steps into methods that read from | 171 // lower level methods decouple those two steps into methods that read from |
| 153 // the current TLV and a method that advances the internal pointer to the | 172 // the current TLV and a method that advances the internal pointer to the |
| 154 // next TLV. | 173 // next TLV. |
| 155 | 174 |
| 156 // Reads the current TLV from the input, putting the tag in |tag| and the raw | 175 // Reads the current TLV from the input, putting the tag in |tag| and the raw |
| 157 // value in |out|, but does not advance the input. Returns true if the tag | 176 // value in |out|, but does not advance the input. Returns true if the tag |
| 158 // and length are successfully read and the output exists. | 177 // and length are successfully read and the output exists. |
| 159 bool PeekTagAndValue(Tag* tag, Input* out) WARN_UNUSED_RESULT; | 178 bool PeekTagAndValue(Tag* tag, Input* out) WARN_UNUSED_RESULT; |
| 160 | 179 |
| 161 // Advances the input to the next TLV. This method only needs to be called | 180 // Advances the input to the next TLV. This method only needs to be called |
| 162 // after PeekTagAndValue; all other methods will advance the input if they | 181 // after PeekTagAndValue; all other methods will advance the input if they |
| 163 // read something. | 182 // read something. |
| 164 bool Advance(); | 183 bool Advance(); |
| 165 | 184 |
| 166 private: | 185 private: |
| 167 ByteReader input_; | 186 ByteReader input_; |
| 168 Mark advance_mark_; | 187 Mark advance_mark_; |
| 169 | 188 |
| 170 DISALLOW_COPY(Parser); | 189 DISALLOW_COPY(Parser); |
| 171 }; | 190 }; |
| 172 | 191 |
| 173 } // namespace der | 192 } // namespace der |
| 174 | 193 |
| 175 } // namespace net | 194 } // namespace net |
| 176 | 195 |
| 177 #endif // NET_DER_PARSER_H_ | 196 #endif // NET_DER_PARSER_H_ |
| OLD | NEW |