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 of the number. Returns true on success and |
| 27 // fills |negative|. Otherwise returns false and does not modify the out |
| 28 // parameter. |
| 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 is non-negative). |
| 33 NET_EXPORT bool IsValidInteger(const Input& in, |
| 34 bool* negative) WARN_UNUSED_RESULT; |
| 35 |
25 // Reads a DER-encoded ASN.1 INTEGER value from |in| and puts the resulting | 36 // 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 | 37 // 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 | 38 // 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 | 39 // 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 | 40 // 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. | 41 // integer. |
31 NET_EXPORT bool ParseUint64(const Input& in, uint64_t* out) WARN_UNUSED_RESULT; | 42 NET_EXPORT bool ParseUint64(const Input& in, uint64_t* out) WARN_UNUSED_RESULT; |
32 | 43 |
33 // The BitString class is a helper for representing a valid parsed BIT STRING. | 44 // The BitString class is a helper for representing a valid parsed BIT STRING. |
34 // | 45 // |
35 // * The bits are ordered within each octet of bytes() from most to least | 46 // * The bits are ordered within each octet of bytes() from most to least |
36 // significant, as in the DER encoding. | 47 // significant, as in the DER encoding. |
37 // | 48 // |
38 // * There may be at most 7 unused bits. | 49 // * There may be at most 7 unused bits. |
39 class NET_EXPORT BitString { | 50 class NET_EXPORT BitString { |
40 public: | 51 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 | 104 // DER rules - it follows the rules from RFC5280, which does not allow for |
94 // fractional seconds. | 105 // fractional seconds. |
95 NET_EXPORT bool ParseGeneralizedTime(const Input& in, | 106 NET_EXPORT bool ParseGeneralizedTime(const Input& in, |
96 GeneralizedTime* out) WARN_UNUSED_RESULT; | 107 GeneralizedTime* out) WARN_UNUSED_RESULT; |
97 | 108 |
98 } // namespace der | 109 } // namespace der |
99 | 110 |
100 } // namespace net | 111 } // namespace net |
101 | 112 |
102 #endif // NET_DER_PARSE_VALUES_H_ | 113 #endif // NET_DER_PARSE_VALUES_H_ |
OLD | NEW |