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_PARSE_VALUES_H_ | 5 #ifndef NET_DER_PARSE_VALUES_H_ |
6 #define NET_DER_PARSE_VALUES_H_ | 6 #define NET_DER_PARSE_VALUES_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "net/base/net_export.h" | 9 #include "net/base/net_export.h" |
10 #include "net/der/input.h" | 10 #include "net/der/input.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 namespace der { | 14 namespace der { |
15 | 15 |
16 // Reads a DER-encoded ASN.1 BOOLEAN value from |in| and puts the resulting | 16 // Reads a DER-encoded ASN.1 BOOLEAN value from |in| and puts the resulting |
17 // value in |out|. Returns whether the encoded value could successfully be | 17 // value in |out|. Returns whether the encoded value could successfully be |
18 // read. | 18 // read. |
19 NET_EXPORT bool ParseBool(const Input& in, bool* out) WARN_UNUSED_RESULT; | 19 NET_EXPORT bool ParseBool(const Input& in, bool* out) WARN_UNUSED_RESULT; |
20 | 20 |
21 // Like ParseBool, except it is more relaxed in what inputs it accepts: Any | 21 // Like ParseBool, except it is more relaxed in what inputs it accepts: Any |
22 // value that is a valid BER encoding will be parsed successfully. | 22 // value that is a valid BER encoding will be parsed successfully. |
23 NET_EXPORT bool ParseBoolRelaxed(const Input& in, bool* out) WARN_UNUSED_RESULT; | 23 NET_EXPORT bool ParseBoolRelaxed(const Input& in, bool* out) WARN_UNUSED_RESULT; |
24 | 24 |
25 // Checks the validity of a DER-encoded ASN.1 INTEGER value from |in|, and | |
26 // determines the sign and length of the number. Returns true on success and | |
27 // fills |negative| and |numeric_length|. Otherwise returns false and does not | |
28 // modify any outputs. | |
29 // | |
30 // in: The value portion of an INTEGER. | |
31 // negative: Out parameter that is set to true if the number is negative, | |
32 // and false otherwise (zero counts as !negative). | |
33 // numeric_length: The minimum number of bytes needed to represent this | |
34 // INTEGER using either a signed or unsigned twos-complement | |
35 // representation. For negative INTEGERs the numeric_length will always | |
36 // be in.Length(). However for non-negative numbers the numeric_length | |
37 // may be one less than in.Length(). This happens because the first byte | |
38 // may be entirely zero simply to indicate that it is not negative. | |
39 NET_EXPORT bool ParseInteger(const Input& in, | |
nharper
2015/08/14 22:23:41
All of the other Parse* functions here are of the
eroman
2015/08/14 23:19:38
Done. Renamed to IsValidInteger().
| |
40 bool* negative, | |
41 size_t* numeric_length) WARN_UNUSED_RESULT; | |
42 | |
25 // Reads a DER-encoded ASN.1 INTEGER value from |in| and puts the resulting | 43 // Reads a DER-encoded ASN.1 INTEGER value from |in| and puts the resulting |
26 // value in |out|. ASN.1 INTEGERs are arbitrary precision; this function is | 44 // value in |out|. ASN.1 INTEGERs are arbitrary precision; this function is |
27 // provided as a convenience when the caller knows that the value is unsigned | 45 // provided as a convenience when the caller knows that the value is unsigned |
28 // and is between 0 and 2^63-1. This function does not support the full range of | 46 // and is between 0 and 2^64-1. This function returns false if the value is too |
29 // uint64_t. This function returns false if the value is too big to fit in a | 47 // big to fit in a uint64_t, is negative, or if there is an error reading the |
30 // uint64_t, is negative, or if there is an error reading the integer. | 48 // integer. |
31 NET_EXPORT bool ParseUint64(const Input& in, uint64_t* out) WARN_UNUSED_RESULT; | 49 NET_EXPORT bool ParseUint64(const Input& in, uint64_t* out) WARN_UNUSED_RESULT; |
32 | 50 |
33 // The BitString class is a helper for representing a valid parsed BIT STRING. | 51 // The BitString class is a helper for representing a valid parsed BIT STRING. |
34 // | 52 // |
35 // * The bits are ordered within each octet of bytes() from most to least | 53 // * The bits are ordered within each octet of bytes() from most to least |
36 // significant, as in the DER encoding. | 54 // significant, as in the DER encoding. |
37 // | 55 // |
38 // * There may be at most 7 unused bits. | 56 // * There may be at most 7 unused bits. |
39 class NET_EXPORT BitString { | 57 class NET_EXPORT BitString { |
40 public: | 58 public: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 // DER rules - it follows the rules from RFC5280, which does not allow for | 111 // DER rules - it follows the rules from RFC5280, which does not allow for |
94 // fractional seconds. | 112 // fractional seconds. |
95 NET_EXPORT bool ParseGeneralizedTime(const Input& in, | 113 NET_EXPORT bool ParseGeneralizedTime(const Input& in, |
96 GeneralizedTime* out) WARN_UNUSED_RESULT; | 114 GeneralizedTime* out) WARN_UNUSED_RESULT; |
97 | 115 |
98 } // namespace der | 116 } // namespace der |
99 | 117 |
100 } // namespace net | 118 } // namespace net |
101 | 119 |
102 #endif // NET_DER_PARSE_VALUES_H_ | 120 #endif // NET_DER_PARSE_VALUES_H_ |
OLD | NEW |