// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "parse_values.h" #include <stdlib.h> #include <tuple> #include <openssl/base.h> #include <openssl/bytestring.h> #include <openssl/mem.h> BSSL_NAMESPACE_BEGIN namespace der { namespace { bool ParseBoolInternal(Input in, bool *out, bool relaxed) { … } // Reads a positive decimal number with |digits| digits and stores it in // |*out|. This function does not check that the type of |*out| is large // enough to hold 10^digits - 1; the caller must choose an appropriate type // based on the number of digits they wish to parse. template <typename UINT> bool DecimalStringToUint(ByteReader &in, size_t digits, UINT *out) { … } // Checks that the values in a GeneralizedTime struct are valid. This involves // checking that the year is 4 digits, the month is between 1 and 12, the day // is a day that exists in that month (following current leap year rules), // hours are between 0 and 23, minutes between 0 and 59, and seconds between // 0 and 60 (to allow for leap seconds; no validation is done that a leap // second is on a day that could be a leap second). bool ValidateGeneralizedTime(const GeneralizedTime &time) { … } // Returns the number of bytes of numeric precision in a DER encoded INTEGER // value. |in| must be a valid DER encoding of an INTEGER for this to work. // // Normally the precision of the number is exactly in.size(). However when // encoding positive numbers using DER it is possible to have a leading zero // (to prevent number from being interpreted as negative). // // For instance a 160-bit positive number might take 21 bytes to encode. This // function will return 20 in such a case. size_t GetUnsignedIntegerLength(Input in) { … } } // namespace bool ParseBool(Input in, bool *out) { … } // BER interprets any non-zero value as true, while DER requires a bool to // have either all bits zero (false) or all bits one (true). To support // malformed certs, we recognized the BER encoding instead of failing to // parse. bool ParseBoolRelaxed(Input in, bool *out) { … } // ITU-T X.690 section 8.3.2 specifies that an integer value must be encoded // in the smallest number of octets. If the encoding consists of more than // one octet, then the bits of the first octet and the most significant bit // of the second octet must not be all zeroes or all ones. bool IsValidInteger(Input in, bool *negative) { … } bool ParseUint64(Input in, uint64_t *out) { … } bool ParseUint8(Input in, uint8_t *out) { … } BitString::BitString(Input bytes, uint8_t unused_bits) : … { … } bool BitString::AssertsBit(size_t bit_index) const { … } std::optional<BitString> ParseBitString(Input in) { … } bool GeneralizedTime::InUTCTimeRange() const { … } bool operator<(const GeneralizedTime &lhs, const GeneralizedTime &rhs) { … } bool operator>(const GeneralizedTime &lhs, const GeneralizedTime &rhs) { … } bool operator<=(const GeneralizedTime &lhs, const GeneralizedTime &rhs) { … } bool operator>=(const GeneralizedTime &lhs, const GeneralizedTime &rhs) { … } bool ParseUTCTime(Input in, GeneralizedTime *value) { … } bool ParseGeneralizedTime(Input in, GeneralizedTime *value) { … } bool ParseIA5String(Input in, std::string *out) { … } bool ParseVisibleString(Input in, std::string *out) { … } bool ParsePrintableString(Input in, std::string *out) { … } bool ParseTeletexStringAsLatin1(Input in, std::string *out) { … } bool ParseUniversalString(Input in, std::string *out) { … } bool ParseBmpString(Input in, std::string *out) { … } } // namespace der BSSL_NAMESPACE_END