Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
Botan::X509_DN Class Referencefinal

`#include <x509_dn.h>`

Inheritance diagram for Botan::X509_DN:

## Public Member Functions
void | add_attribute (const std::string &, const std::string &)
void | add_attribute (const OID &, const std::string &)
std::multimap< std::string, std::string > | contents () const
void | decode_from (class BER_Decoder &) override
bool | empty () const
void | encode_into (class DER_Encoder &) const override
std::vector< std::string > | get_attribute (const std::string &) const
std::multimap< OID, std::string > | get_attributes () const
std::vector< uint8_t > | get_bits () const
| X509_DN ()
| X509_DN (const std::multimap< OID, std::string > &)
| X509_DN (const std::multimap< std::string, std::string > &)

## Static Public Member Functions
static std::string | deref_info_field (const std::string &)

## Detailed Description

Distinguished Name

Definition at line 22 of file x509_dn.h.

## Constructor & Destructor Documentation

Botan::X509_DN::X509_DN | ( |  | ) |

Definition at line 22 of file x509_dn.cpp.

23 {
24 }

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

Definition at line 29 of file x509_dn.cpp.

References add_attribute().

30 {
31 for(auto i = args.begin(); i != args.end(); ++i)
32 add_attribute(i->first, i->second);
33 }
Botan::X509_DN::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47

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

Definition at line 38 of file x509_dn.cpp.

References add_attribute(), and Botan::OIDS::lookup().

39 {
40 for(auto i = args.begin(); i != args.end(); ++i)
41 add_attribute(OIDS::lookup(i->first), i->second);
42 }
Botan::X509_DN::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18

## Member Function Documentation

void Botan::X509_DN::add_attribute | ( | const std::string & | type,
|  | const std::string & | str
| ) |  |

Definition at line 47 of file x509_dn.cpp.

References Botan::OIDS::lookup().

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

49 {
50 OID oid = OIDS::lookup(type);
51 add_attribute(oid, str);
52 }
Botan::X509_DN::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47
type
MechanismType type
Definition: p11_mechanism.cpp:43
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18

void Botan::X509_DN::add_attribute | ( | const OID & | oid,
|  | const std::string & | str
| ) |  |

Definition at line 57 of file x509_dn.cpp.

References Botan::multimap_insert().

58 {
59 if(str.empty())
60 return;
61
62 auto range = m_dn_info.equal_range(oid);
63 for(auto i = range.first; i != range.second; ++i)
64 if(i->second.value() == str)
65 return;
66
67 multimap_insert(m_dn_info, oid, ASN1_String(str));
68 m_dn_bits.clear();
69 }
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

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

Definition at line 85 of file x509_dn.cpp.

References Botan::OIDS::lookup(), and Botan::multimap_insert().

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

86 {
87 std::multimap<std::string, std::string> retval;
88 for(auto i = m_dn_info.begin(); i != m_dn_info.end(); ++i)
89 multimap_insert(retval, OIDS::lookup(i->first), i->second.value());
90 return retval;
91 }
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

void Botan::X509_DN::decode_from | ( | class BER_Decoder & | from | ) |
| override virtual

Decode whatever this object is from from

Parameters

  from | the BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 250 of file x509_dn.cpp.

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, Botan::BER_Decoder::start_cons(), and Botan::ASN1_String::value().

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

251 {
252 std::vector<uint8_t> bits;
253
254 source.start_cons(SEQUENCE)
255 .raw_bytes(bits)
256 .end_cons();
257
258 BER_Decoder sequence(bits);
259
260 while(sequence.more_items())
261 {
262 BER_Decoder rdn = sequence.start_cons(SET);
263
264 while(rdn.more_items())
265 {
266 OID oid;
267 ASN1_String str;
268
269 rdn.start_cons(SEQUENCE)
270 .decode(oid)
271 .decode(str)
272 .end_cons();
273
274 add_attribute(oid, str.value());
275 }
276 }
277
278 m_dn_bits = bits;
279 }
Botan::X509_DN::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan::SET
Definition: asn1_obj.h:40

std::string Botan::X509_DN::deref_info_field | ( | const std::string & | info | ) |
| static

Definition at line 119 of file x509_dn.cpp.

Referenced by get_attribute(), Botan::X509_Certificate::issuer_info(), Botan::operator>>(), and Botan::X509_Certificate::subject_info().

120 {
121 if(info == "Name" || info == "CommonName" || info == "CN") return "X520.CommonName";
122 if(info == "SerialNumber" || info == "SN") return "X520.SerialNumber";
123 if(info == "Country" || info == "C") return "X520.Country";
124 if(info == "Organization" || info == "O") return "X520.Organization";
125 if(info == "Organizational Unit" || info == "OrgUnit" || info == "OU")
126 return "X520.OrganizationalUnit";
127 if(info == "Locality" || info == "L") return "X520.Locality";
128 if(info == "State" || info == "Province" || info == "ST") return "X520.State";
129 if(info == "Email") return "RFC822";
130 return info;
131 }

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

Definition at line 40 of file x509_dn.h.

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

40 { return m_dn_info.empty(); }

void Botan::X509_DN::encode_into | ( | class DER_Encoder & | to | ) | const
| override virtual

Encode whatever this object is into to

Parameters

  to | the DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 225 of file x509_dn.cpp.

References Botan::DIRECTORY_STRING, Botan::DER_Encoder::end_cons(), get_attributes(), Botan::PRINTABLE_STRING, Botan::DER_Encoder::raw_bytes(), Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

Referenced by Botan::Certificate_Store_In_SQL::find_cert(), and Botan::Certificate_Store_In_SQL::insert_cert().

226 {
227 auto dn_info = get_attributes();
228
229 der.start_cons(SEQUENCE);
230
231 if(!m_dn_bits.empty())
232 der.raw_bytes(m_dn_bits);
233 else
234 {
235 do_ava(der, dn_info, PRINTABLE_STRING, "X520.Country");
236 do_ava(der, dn_info, DIRECTORY_STRING, "X520.State");
237 do_ava(der, dn_info, DIRECTORY_STRING, "X520.Locality");
238 do_ava(der, dn_info, DIRECTORY_STRING, "X520.Organization");
239 do_ava(der, dn_info, DIRECTORY_STRING, "X520.OrganizationalUnit");
240 do_ava(der, dn_info, DIRECTORY_STRING, "X520.CommonName");
241 do_ava(der, dn_info, PRINTABLE_STRING, "X520.SerialNumber");
242 }
243
244 der.end_cons();
245 }
Botan::PRINTABLE_STRING
Definition: asn1_obj.h:44
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan::DIRECTORY_STRING
Definition: asn1_obj.h:55
Botan::X509_DN::get_attributes
std::multimap< OID, std::string > get_attributes() const
Definition: x509_dn.cpp:74

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

Definition at line 96 of file x509_dn.cpp.

References deref_info_field(), and Botan::OIDS::lookup().

97 {
98 const OID oid = OIDS::lookup(deref_info_field(attr));
99
100 auto range = m_dn_info.equal_range(oid);
101
102 std::vector<std::string> values;
103 for(auto i = range.first; i != range.second; ++i)
104 values.push_back(i->second.value());
105 return values;
106 }
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18
Botan::X509_DN::deref_info_field
static std::string deref_info_field(const std::string &)
Definition: x509_dn.cpp:119

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

Definition at line 74 of file x509_dn.cpp.

References Botan::multimap_insert().

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

75 {
76 std::multimap<OID, std::string> retval;
77 for(auto i = m_dn_info.begin(); i != m_dn_info.end(); ++i)
78 multimap_insert(retval, i->first, i->second.value());
79 return retval;
80 }
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

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

Definition at line 111 of file x509_dn.cpp.

112 {
113 return m_dn_bits;
114 }

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

- src/lib/asn1/x509_dn.h
- src/lib/asn1/x509_dn.cpp