Botan 2.19.3
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::X509_DN Class Referencefinal

#include <pkix_types.h>

Inheritance diagram for Botan::X509_DN:
Botan::ASN1_Object

Public Member Functions

void add_attribute (const OID &oid, const ASN1_String &val)
 
void add_attribute (const OID &oid, const std::string &val)
 
void add_attribute (const std::string &key, const std::string &val)
 
std::vector< uint8_t > BER_encode () const
 
std::multimap< std::string, std::string > contents () const
 
void decode_from (BER_Decoder &) override
 
const std::vector< std::pair< OID, ASN1_String > > & dn_info () const
 
bool empty () const
 
void encode_into (DER_Encoder &) const override
 
std::vector< std::string > get_attribute (const std::string &attr) const
 
std::multimap< OID, std::string > get_attributes () const
 
const std::vector< uint8_t > & get_bits () const
 
ASN1_String get_first_attribute (const OID &oid) const
 
std::string get_first_attribute (const std::string &attr) const
 
bool has_field (const OID &oid) const
 
bool has_field (const std::string &attr) const
 
std::string to_string () const
 
 X509_DN ()=default
 
 X509_DN (const std::multimap< OID, std::string > &args)
 
 X509_DN (const std::multimap< std::string, std::string > &args)
 

Static Public Member Functions

static std::string deref_info_field (const std::string &key)
 
static size_t lookup_ub (const OID &oid)
 

Detailed Description

Distinguished Name

Definition at line 42 of file pkix_types.h.

Constructor & Destructor Documentation

◆ X509_DN() [1/3]

Botan::X509_DN::X509_DN ( )
default

◆ X509_DN() [2/3]

Botan::X509_DN::X509_DN ( const std::multimap< OID, std::string > &  args)
inlineexplicit

Definition at line 47 of file pkix_types.h.

48 {
49 for(auto i : args)
50 add_attribute(i.first, i.second);
51 }
void add_attribute(const std::string &key, const std::string &val)
Definition x509_dn.cpp:23

◆ X509_DN() [3/3]

Botan::X509_DN::X509_DN ( const std::multimap< std::string, std::string > &  args)
inlineexplicit

Definition at line 53 of file pkix_types.h.

54 {
55 for(auto i : args)
56 add_attribute(i.first, i.second);
57 }

Member Function Documentation

◆ add_attribute() [1/3]

void Botan::X509_DN::add_attribute ( const OID oid,
const ASN1_String val 
)

Definition at line 32 of file x509_dn.cpp.

33 {
34 if(str.empty())
35 return;
36
37 m_rdn.push_back(std::make_pair(oid, str));
38 m_dn_bits.clear();
39 }

References Botan::ASN1_String::empty().

◆ add_attribute() [2/3]

void Botan::X509_DN::add_attribute ( const OID oid,
const std::string &  val 
)
inline

Definition at line 85 of file pkix_types.h.

86 {
87 add_attribute(oid, ASN1_String(val));
88 }

◆ add_attribute() [3/3]

void Botan::X509_DN::add_attribute ( const std::string &  key,
const std::string &  val 
)

Definition at line 23 of file x509_dn.cpp.

25 {
27 }
static OID from_string(const std::string &str)
Definition asn1_oid.cpp:62
MechanismType type

References add_attribute(), Botan::OID::from_string(), and type.

Referenced by add_attribute(), Botan::create_dn(), decode_from(), and Botan::operator>>().

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 16 of file asn1_obj.cpp.

17 {
18 std::vector<uint8_t> output;
19 DER_Encoder der(output);
20 this->encode_into(der);
21 return output;
22 }
virtual void encode_into(DER_Encoder &to) const =0

References Botan::ASN1_Object::encode_into().

Referenced by Botan::PSSR::config_for_x509(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::Certificate_Store_In_SQL::revoke_cert().

◆ contents()

std::multimap< std::string, std::string > Botan::X509_DN::contents ( ) const

Definition at line 56 of file x509_dn.cpp.

57 {
58 std::multimap<std::string, std::string> retval;
59
60 for(auto& i : m_rdn)
61 {
62 multimap_insert(retval, i.first.to_formatted_string(), i.second.value());
63 }
64 return retval;
65 }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition stl_util.h:76

References Botan::multimap_insert().

◆ decode_from()

void Botan::X509_DN::decode_from ( BER_Decoder from)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 272 of file x509_dn.cpp.

273 {
274 std::vector<uint8_t> bits;
275
276 source.start_cons(SEQUENCE)
277 .raw_bytes(bits)
278 .end_cons();
279
280 BER_Decoder sequence(bits);
281
282 while(sequence.more_items())
283 {
284 BER_Decoder rdn = sequence.start_cons(SET);
285
286 while(rdn.more_items())
287 {
288 OID oid;
289 ASN1_String str;
290
291 rdn.start_cons(SEQUENCE)
292 .decode(oid)
293 .decode(str) // TODO support Any
294 .end_cons();
295
296 add_attribute(oid, str);
297 }
298 }
299
300 m_dn_bits = bits;
301 }
@ SEQUENCE
Definition asn1_obj.h:42
@ SET
Definition asn1_obj.h:43

References add_attribute(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::BER_Decoder::more_items(), Botan::BER_Decoder::raw_bytes(), Botan::SEQUENCE, Botan::SET, and Botan::BER_Decoder::start_cons().

Referenced by Botan::Certificate_Store_In_SQL::all_subjects(), and Botan::GeneralName::decode_from().

◆ deref_info_field()

std::string Botan::X509_DN::deref_info_field ( const std::string &  key)
static

Definition at line 129 of file x509_dn.cpp.

130 {
131 if(info == "Name" || info == "CommonName" || info == "CN") return "X520.CommonName";
132 if(info == "SerialNumber" || info == "SN") return "X520.SerialNumber";
133 if(info == "Country" || info == "C") return "X520.Country";
134 if(info == "Organization" || info == "O") return "X520.Organization";
135 if(info == "Organizational Unit" || info == "OrgUnit" || info == "OU")
136 return "X520.OrganizationalUnit";
137 if(info == "Locality" || info == "L") return "X520.Locality";
138 if(info == "State" || info == "Province" || info == "ST") return "X520.State";
139 if(info == "Email") return "RFC822";
140 return info;
141 }

Referenced by get_attribute(), get_first_attribute(), has_field(), and Botan::operator>>().

◆ dn_info()

const std::vector< std::pair< OID, ASN1_String > > & Botan::X509_DN::dn_info ( ) const
inline

Definition at line 74 of file pkix_types.h.

74{ return m_rdn; }

Referenced by Botan::operator<<().

◆ empty()

bool Botan::X509_DN::empty ( ) const
inline

Definition at line 70 of file pkix_types.h.

70{ return m_rdn.empty(); }

Referenced by Botan::OCSP::Response::check_signature().

◆ encode_into()

void Botan::X509_DN::encode_into ( DER_Encoder to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 241 of file x509_dn.cpp.

242 {
243 der.start_cons(SEQUENCE);
244
245 if(!m_dn_bits.empty())
246 {
247 /*
248 If we decoded this from somewhere, encode it back exactly as
249 we received it
250 */
251 der.raw_bytes(m_dn_bits);
252 }
253 else
254 {
255 for(const auto& dn : m_rdn)
256 {
257 der.start_cons(SET)
258 .start_cons(SEQUENCE)
259 .encode(dn.first)
260 .encode(dn.second)
261 .end_cons()
262 .end_cons();
263 }
264 }
265
266 der.end_cons();
267 }

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::raw_bytes(), Botan::SEQUENCE, Botan::SET, and Botan::DER_Encoder::start_cons().

◆ get_attribute()

std::vector< std::string > Botan::X509_DN::get_attribute ( const std::string &  attr) const

Definition at line 109 of file x509_dn.cpp.

110 {
111 const OID oid = OID::from_string(deref_info_field(attr));
112
113 std::vector<std::string> values;
114
115 for(auto& i : m_rdn)
116 {
117 if(i.first == oid)
118 {
119 values.push_back(i.second.value());
120 }
121 }
122
123 return values;
124 }
static std::string deref_info_field(const std::string &key)
Definition x509_dn.cpp:129

References deref_info_field(), and Botan::OID::from_string().

Referenced by Botan::X509_Certificate::issuer_info(), Botan::GeneralName::matches(), and Botan::X509_Certificate::subject_info().

◆ get_attributes()

std::multimap< OID, std::string > Botan::X509_DN::get_attributes ( ) const

Definition at line 44 of file x509_dn.cpp.

45 {
46 std::multimap<OID, std::string> retval;
47
48 for(auto& i : m_rdn)
49 multimap_insert(retval, i.first, i.second.value());
50 return retval;
51 }

References Botan::multimap_insert().

Referenced by Botan::operator<(), and Botan::operator==().

◆ get_bits()

const std::vector< uint8_t > & Botan::X509_DN::get_bits ( ) const
inline

Definition at line 68 of file pkix_types.h.

68{ return m_dn_bits; }

◆ get_first_attribute() [1/2]

ASN1_String Botan::X509_DN::get_first_attribute ( const OID oid) const

Definition at line 93 of file x509_dn.cpp.

94 {
95 for(auto& i : m_rdn)
96 {
97 if(i.first == oid)
98 {
99 return i.second;
100 }
101 }
102
103 return ASN1_String();
104 }

Referenced by get_first_attribute().

◆ get_first_attribute() [2/2]

std::string Botan::X509_DN::get_first_attribute ( const std::string &  attr) const

Definition at line 87 of file x509_dn.cpp.

88 {
89 const OID oid = OID::from_string(deref_info_field(attr));
90 return get_first_attribute(oid).value();
91 }
const std::string & value() const
Definition asn1_obj.h:400
ASN1_String get_first_attribute(const OID &oid) const
Definition x509_dn.cpp:93

References deref_info_field(), Botan::OID::from_string(), get_first_attribute(), and Botan::ASN1_String::value().

◆ has_field() [1/2]

bool Botan::X509_DN::has_field ( const OID oid) const

Definition at line 76 of file x509_dn.cpp.

77 {
78 for(auto& i : m_rdn)
79 {
80 if(i.first == oid)
81 return true;
82 }
83
84 return false;
85 }

Referenced by has_field().

◆ has_field() [2/2]

bool Botan::X509_DN::has_field ( const std::string &  attr) const

Definition at line 67 of file x509_dn.cpp.

68 {
69 const OID o = OIDS::str2oid_or_empty(deref_info_field(attr));
70 if(o.has_value())
71 return has_field(o);
72 else
73 return false;
74 }
bool has_field(const OID &oid) const
Definition x509_dn.cpp:76
BOTAN_UNSTABLE_API OID str2oid_or_empty(const std::string &name)
Definition oids.cpp:116

References deref_info_field(), has_field(), Botan::OID::has_value(), and Botan::OIDS::str2oid_or_empty().

◆ lookup_ub()

size_t Botan::X509_DN::lookup_ub ( const OID oid)
static

Lookup upper bounds in characters for the length of distinguished name fields as given in RFC 5280, Appendix A.

Parameters
oidthe oid of the DN to lookup
Returns
the upper bound, or zero if no ub is known to Botan

Definition at line 47 of file x509_dn_ub.cpp.

48 {
49 auto ub_entry = DN_UB.find(oid);
50 if(ub_entry != DN_UB.end())
51 {
52 return ub_entry->second;
53 }
54 else
55 {
56 return 0;
57 }
58 }

◆ to_string()

std::string Botan::X509_DN::to_string ( ) const

Definition at line 326 of file x509_dn.cpp.

327 {
328 std::ostringstream out;
329 out << *this;
330 return out.str();
331 }

Referenced by Botan::GeneralName::matches().


The documentation for this class was generated from the following files: