ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / net / der / parse_values.h
blobb525a64662e23fc9b9b362b3aa920f6c3f414032
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
3 // found in the LICENSE file.
5 #ifndef NET_DER_PARSE_VALUES_H_
6 #define NET_DER_PARSE_VALUES_H_
8 #include "base/compiler_specific.h"
9 #include "net/base/net_export.h"
10 #include "net/der/input.h"
12 namespace net {
14 namespace der {
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
18 // read.
19 NET_EXPORT bool ParseBool(const Input& in, bool* out) WARN_UNUSED_RESULT;
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.
23 NET_EXPORT bool ParseBoolRelaxed(const Input& in, bool* out) WARN_UNUSED_RESULT;
25 // 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
27 // 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
29 // uint64_t. This function returns false if the value is too big to fit in a
30 // uint64_t, is negative, or if there is an error reading the integer.
31 NET_EXPORT bool ParseUint64(const Input& in, uint64_t* out) WARN_UNUSED_RESULT;
33 // Reads a DER-encoded ASN.1 BIT STRING value from |in| and puts the resulting
34 // octet string into |bytes|, and the number of unused bits into |unused_bits|.
36 // The bits are ordered within each octet of |bytes| from most to
37 // least significant, as in the DER encoding.
39 // Returns true on success, otherwise returns false and does not modify the
40 // out-parameters.
42 // On success it can be assumed that:
43 // * |*unused_bits| < 8
44 // * The final byte of |bytes| has its |*unused_bits| least significant bits
45 // set to 0.
46 NET_EXPORT bool ParseBitString(const Input& in,
47 Input* bytes,
48 uint8_t* unused_bits) WARN_UNUSED_RESULT;
50 struct GeneralizedTime {
51 uint16_t year;
52 uint8_t month;
53 uint8_t day;
54 uint8_t hours;
55 uint8_t minutes;
56 uint8_t seconds;
59 NET_EXPORT_PRIVATE bool operator<(const GeneralizedTime& lhs,
60 const GeneralizedTime& rhs);
62 // Reads a DER-encoded ASN.1 UTCTime value from |in| and puts the resulting
63 // value in |out|, returning true if the UTCTime could be parsed successfully.
64 NET_EXPORT bool ParseUTCTime(const Input& in,
65 GeneralizedTime* out) WARN_UNUSED_RESULT;
67 // Like ParseUTCTime, but it is more lenient in what is accepted. DER requires
68 // a UTCTime to be in the format YYMMDDhhmmssZ; this function will accept both
69 // that and YYMMDDhhmmZ, which is a valid BER encoding of a UTCTime which
70 // sometimes incorrectly appears in X.509 certificates.
71 NET_EXPORT bool ParseUTCTimeRelaxed(const Input& in,
72 GeneralizedTime* out) WARN_UNUSED_RESULT;
74 // Reads a DER-encoded ASN.1 GeneralizedTime value from |in| and puts the
75 // resulting value in |out|, returning true if the GeneralizedTime could
76 // be parsed sucessfully. This function is even more restrictive than the
77 // DER rules - it follows the rules from RFC5280, which does not allow for
78 // fractional seconds.
79 NET_EXPORT bool ParseGeneralizedTime(const Input& in,
80 GeneralizedTime* out) WARN_UNUSED_RESULT;
82 } // namespace der
84 } // namespace net
86 #endif // NET_DER_PARSE_VALUES_H_