chromium/third_party/boringssl/src/pki/parse_name.h

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BSSL_PKI_PARSE_NAME_H_
#define BSSL_PKI_PARSE_NAME_H_

#include <vector>

#include <openssl/base.h>
#include <openssl/bytestring.h>

#include "input.h"
#include "parser.h"

BSSL_NAMESPACE_BEGIN

// id-at-commonName: 2.5.4.3 (RFC 5280)
inline constexpr uint8_t kTypeCommonNameOid[] =;
// id-at-surname: 2.5.4.4 (RFC 5280)
inline constexpr uint8_t kTypeSurnameOid[] =;
// id-at-serialNumber: 2.5.4.5 (RFC 5280)
inline constexpr uint8_t kTypeSerialNumberOid[] =;
// id-at-countryName: 2.5.4.6 (RFC 5280)
inline constexpr uint8_t kTypeCountryNameOid[] =;
// id-at-localityName: 2.5.4.7 (RFC 5280)
inline constexpr uint8_t kTypeLocalityNameOid[] =;
// id-at-stateOrProvinceName: 2.5.4.8 (RFC 5280)
inline constexpr uint8_t kTypeStateOrProvinceNameOid[] =;
// street (streetAddress): 2.5.4.9 (RFC 4519)
inline constexpr uint8_t kTypeStreetAddressOid[] =;
// id-at-organizationName: 2.5.4.10 (RFC 5280)
inline constexpr uint8_t kTypeOrganizationNameOid[] =;
// id-at-organizationalUnitName: 2.5.4.11 (RFC 5280)
inline constexpr uint8_t kTypeOrganizationUnitNameOid[] =;
// id-at-title: 2.5.4.12 (RFC 5280)
inline constexpr uint8_t kTypeTitleOid[] =;
// id-at-name: 2.5.4.41 (RFC 5280)
inline constexpr uint8_t kTypeNameOid[] =;
// id-at-givenName: 2.5.4.42 (RFC 5280)
inline constexpr uint8_t kTypeGivenNameOid[] =;
// id-at-initials: 2.5.4.43 (RFC 5280)
inline constexpr uint8_t kTypeInitialsOid[] =;
// id-at-generationQualifier: 2.5.4.44 (RFC 5280)
inline constexpr uint8_t kTypeGenerationQualifierOid[] =;
// dc (domainComponent): 0.9.2342.19200300.100.1.25 (RFC 4519)
inline constexpr uint8_t kTypeDomainComponentOid[] =;
// RFC 5280 section A.1:
//
// pkcs-9 OBJECT IDENTIFIER ::=
//   { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 9 }
//
// id-emailAddress      AttributeType ::= { pkcs-9 1 }
//
// In dotted form: 1.2.840.113549.1.9.1
inline constexpr uint8_t kTypeEmailAddressOid[] =;

// X509NameAttribute contains a representation of a DER-encoded RFC 2253
// "AttributeTypeAndValue".
//
// AttributeTypeAndValue ::= SEQUENCE {
//     type  AttributeType,
//     value AttributeValue
// }
struct OPENSSL_EXPORT X509NameAttribute {};

RelativeDistinguishedName;
RDNSequence;

// Parses all the ASN.1 AttributeTypeAndValue elements in |parser| and stores
// each as an AttributeTypeAndValue object in |out|.
//
// AttributeTypeAndValue is defined in RFC 5280 section 4.1.2.4:
//
// AttributeTypeAndValue ::= SEQUENCE {
//   type     AttributeType,
//   value    AttributeValue }
//
// AttributeType ::= OBJECT IDENTIFIER
//
// AttributeValue ::= ANY -- DEFINED BY AttributeType
//
// DirectoryString ::= CHOICE {
//       teletexString           TeletexString (SIZE (1..MAX)),
//       printableString         PrintableString (SIZE (1..MAX)),
//       universalString         UniversalString (SIZE (1..MAX)),
//       utf8String              UTF8String (SIZE (1..MAX)),
//       bmpString               BMPString (SIZE (1..MAX)) }
//
// The type of the component AttributeValue is determined by the AttributeType;
// in general it will be a DirectoryString.
[[nodiscard]] OPENSSL_EXPORT bool ReadRdn(der::Parser *parser,
                                          RelativeDistinguishedName *out);

// Parses a DER-encoded "Name" as specified by 5280. Returns true on success
// and sets the results in |out|.
[[nodiscard]] OPENSSL_EXPORT bool ParseName(der::Input name_tlv,
                                            RDNSequence *out);
// Parses a DER-encoded "Name" value (without the sequence tag & length) as
// specified by 5280. Returns true on success and sets the results in |out|.
[[nodiscard]] OPENSSL_EXPORT bool ParseNameValue(der::Input name_value,
                                                 RDNSequence *out);

// Formats a RDNSequence |rdn_sequence| per RFC2253 as an ASCII string and
// stores the result into |out|, and returns whether the conversion was
// successful.
[[nodiscard]] OPENSSL_EXPORT bool ConvertToRFC2253(
    const RDNSequence &rdn_sequence, std::string *out);
BSSL_NAMESPACE_END

#endif  // BSSL_PKI_PARSE_NAME_H_