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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
14 #include "net/der/input.h" | 14 #include "net/der/input.h" |
15 #include "net/der/tag.h" | 15 #include "net/der/tag.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 namespace der { | 19 namespace der { |
20 | 20 |
21 class BitString; | 21 class BitString; |
| 22 struct GeneralizedTime; |
22 | 23 |
23 // Parses a DER-encoded ASN.1 structure. DER (distinguished encoding rules) | 24 // Parses a DER-encoded ASN.1 structure. DER (distinguished encoding rules) |
24 // encodes each data value with a tag, length, and value (TLV). The tag | 25 // encodes each data value with a tag, length, and value (TLV). The tag |
25 // indicates the type of the ASN.1 value. Depending on the type of the value, | 26 // indicates the type of the ASN.1 value. Depending on the type of the value, |
26 // it could contain arbitrary bytes, so the length of the value is encoded | 27 // it could contain arbitrary bytes, so the length of the value is encoded |
27 // after the tag and before the value to indicate how many bytes of value | 28 // after the tag and before the value to indicate how many bytes of value |
28 // follow. DER also defines how the values are encoded for particular types. | 29 // follow. DER also defines how the values are encoded for particular types. |
29 // | 30 // |
30 // This Parser places a few restrictions on the DER encoding it can parse. The | 31 // This Parser places a few restrictions on the DER encoding it can parse. The |
31 // largest restriction is that it only supports tags which have a tag number | 32 // largest restriction is that it only supports tags which have a tag number |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Note that on failure the Parser is left in an undefined state (the | 155 // Note that on failure the Parser is left in an undefined state (the |
155 // input may or may not have been advanced). | 156 // input may or may not have been advanced). |
156 bool ReadUint64(uint64_t* out) WARN_UNUSED_RESULT; | 157 bool ReadUint64(uint64_t* out) WARN_UNUSED_RESULT; |
157 | 158 |
158 // Reads a BIT STRING. On success fills |out| and returns true. | 159 // Reads a BIT STRING. On success fills |out| and returns true. |
159 // | 160 // |
160 // Note that on failure the Parser is left in an undefined state (the | 161 // Note that on failure the Parser is left in an undefined state (the |
161 // input may or may not have been advanced). | 162 // input may or may not have been advanced). |
162 bool ReadBitString(BitString* out) WARN_UNUSED_RESULT; | 163 bool ReadBitString(BitString* out) WARN_UNUSED_RESULT; |
163 | 164 |
| 165 // Reads a GeneralizeTime. On success fills |out| and returns true. |
| 166 // |
| 167 // Note that on failure the Parser is left in an undefined state (the |
| 168 // input may or may not have been advanced). |
| 169 bool ReadGeneralizedTime(GeneralizedTime* out) WARN_UNUSED_RESULT; |
| 170 |
164 // Lower level methods. The previous methods couple reading data from the | 171 // Lower level methods. The previous methods couple reading data from the |
165 // input with advancing the Parser's internal pointer to the next TLV; these | 172 // input with advancing the Parser's internal pointer to the next TLV; these |
166 // lower level methods decouple those two steps into methods that read from | 173 // lower level methods decouple those two steps into methods that read from |
167 // the current TLV and a method that advances the internal pointer to the | 174 // the current TLV and a method that advances the internal pointer to the |
168 // next TLV. | 175 // next TLV. |
169 | 176 |
170 // Reads the current TLV from the input, putting the tag in |tag| and the raw | 177 // Reads the current TLV from the input, putting the tag in |tag| and the raw |
171 // value in |out|, but does not advance the input. Returns true if the tag | 178 // value in |out|, but does not advance the input. Returns true if the tag |
172 // and length are successfully read and the output exists. | 179 // and length are successfully read and the output exists. |
173 bool PeekTagAndValue(Tag* tag, Input* out) WARN_UNUSED_RESULT; | 180 bool PeekTagAndValue(Tag* tag, Input* out) WARN_UNUSED_RESULT; |
174 | 181 |
175 // Advances the input to the next TLV. This method only needs to be called | 182 // Advances the input to the next TLV. This method only needs to be called |
176 // after PeekTagAndValue; all other methods will advance the input if they | 183 // after PeekTagAndValue; all other methods will advance the input if they |
177 // read something. | 184 // read something. |
178 bool Advance(); | 185 bool Advance(); |
179 | 186 |
180 private: | 187 private: |
181 ByteReader input_; | 188 ByteReader input_; |
182 Mark advance_mark_; | 189 Mark advance_mark_; |
183 | 190 |
184 DISALLOW_COPY(Parser); | 191 DISALLOW_COPY(Parser); |
185 }; | 192 }; |
186 | 193 |
187 } // namespace der | 194 } // namespace der |
188 | 195 |
189 } // namespace net | 196 } // namespace net |
190 | 197 |
191 #endif // NET_DER_PARSER_H_ | 198 #endif // NET_DER_PARSER_H_ |
OLD | NEW |