Botan: Botan::X509_DN Class Reference

Botan 1.10.16

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

`#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 &)
void | encode_into (class DER_Encoder &) const
std::vector< std::string > | get_attribute (const std::string &) const
std::multimap< OID, std::string > | get_attributes () const
MemoryVector< byte > | 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 21 of file x509_dn.h.

## Constructor & Destructor Documentation

## ◆ X509_DN() [1/3]

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

Definition at line 20 of file x509_dn.cpp.

21 {
22 }

## ◆ X509_DN() [2/3]

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

Definition at line 27 of file x509_dn.cpp.

References add_attribute().

28 {
29 std::multimap<OID, std::string>::const_iterator j;
30 for(j = args.begin(); j != args.end(); ++j)
31 add_attribute(j->first, j->second);
32 }
Botan::X509_DN::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47

## ◆ X509_DN() [3/3]

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

Definition at line 37 of file x509_dn.cpp.

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

38 {
39 std::multimap<std::string, std::string>::const_iterator j;
40 for(j = args.begin(); j != args.end(); ++j)
41 add_attribute(OIDS::lookup(j->first), j->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:31

## Member Function Documentation

## ◆ add_attribute() [1/2]

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(), and oid.

Referenced by Botan::create_dn(), decode_from(), 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
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
oid
OID oid
Definition: x509_ext.cpp:446

## ◆ add_attribute() [2/2]

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

Definition at line 57 of file x509_dn.cpp.

References Botan::MemoryRegion< T >::clear(), and Botan::multimap_insert().

58 {
59 if(str == "")
60 return;
61
62 typedef std::multimap<OID, ASN1_String>::iterator rdn_iter;
63
64 std::pair<rdn_iter, rdn_iter> range = dn_info.equal_range(oid);
65 for(rdn_iter j = range.first; j != range.second; ++j)
66 if(j->second.value() == str)
67 return;
68
69 multimap_insert(dn_info, oid, ASN1_String(str));
70 dn_bits.clear();
71 }
Botan::MemoryRegion::clear
void clear()
Definition: secmem.h:152
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76
oid
OID oid
Definition: x509_ext.cpp:446

## ◆ contents()

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

Definition at line 89 of file x509_dn.cpp.

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

Referenced by Botan::PKCS10_Request::PKCS10_Request(), Botan::X509_Certificate::X509_Certificate(), and Botan::X509_CRL::X509_CRL().

90 {
91 typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
92
93 std::multimap<std::string, std::string> retval;
94 for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j)
95 multimap_insert(retval, OIDS::lookup(j->first), j->second.value());
96 return retval;
97 }
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

## ◆ decode_from()

void Botan::X509_DN::decode_from | ( | class BER_Decoder & | from | ) |
| 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 264 of file x509_dn.cpp.

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

265 {
266 MemoryVector<byte> bits;
267
268 source.start_cons(SEQUENCE)
269 .raw_bytes(bits)
270 .end_cons();
271
272 BER_Decoder sequence(bits);
273
274 while(sequence.more_items())
275 {
276 BER_Decoder rdn = sequence.start_cons(SET);
277
278 while(rdn.more_items())
279 {
280 OID oid;
281 ASN1_String str;
282
283 rdn.start_cons(SEQUENCE)
284 .decode(oid)
285 .decode(str)
286 .verify_end()
287 .end_cons();
288
289 add_attribute(oid, str.value());
290 }
291 }
292
293 dn_bits = bits;
294 }
Botan::X509_DN::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::SET
Definition: asn1_int.h:36
oid
OID oid
Definition: x509_ext.cpp:446

## ◆ deref_info_field()

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

Definition at line 126 of file x509_dn.cpp.

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

127 {
128 if(info == "Name" || info == "CommonName") return "X520.CommonName";
129 if(info == "SerialNumber") return "X520.SerialNumber";
130 if(info == "Country") return "X520.Country";
131 if(info == "Organization") return "X520.Organization";
132 if(info == "Organizational Unit" || info == "OrgUnit")
133 return "X520.OrganizationalUnit";
134 if(info == "Locality") return "X520.Locality";
135 if(info == "State" || info == "Province") return "X520.State";
136 if(info == "Email") return "RFC822";
137 return info;
138 }

## ◆ encode_into()

void Botan::X509_DN::encode_into | ( | class DER_Encoder & | to | ) | const
| 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 239 of file x509_dn.cpp.

References Botan::DIRECTORY_STRING, Botan::MemoryRegion< T >::empty(), Botan::DER_Encoder::end_cons(), get_attributes(), Botan::PRINTABLE_STRING, Botan::DER_Encoder::raw_bytes(), Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

240 {
241 std::multimap<OID, std::string> dn_info = get_attributes();
242
243 der.start_cons(SEQUENCE);
244
245 if(!dn_bits.empty())
246 der.raw_bytes(dn_bits);
247 else
248 {
249 do_ava(der, dn_info, PRINTABLE_STRING, "X520.Country");
250 do_ava(der, dn_info, DIRECTORY_STRING, "X520.State");
251 do_ava(der, dn_info, DIRECTORY_STRING, "X520.Locality");
252 do_ava(der, dn_info, DIRECTORY_STRING, "X520.Organization");
253 do_ava(der, dn_info, DIRECTORY_STRING, "X520.OrganizationalUnit");
254 do_ava(der, dn_info, DIRECTORY_STRING, "X520.CommonName");
255 do_ava(der, dn_info, PRINTABLE_STRING, "X520.SerialNumber");
256 }
257
258 der.end_cons();
259 }
Botan::PRINTABLE_STRING
Definition: asn1_int.h:40
Botan::MemoryRegion::empty
bool empty() const
Definition: secmem.h:35
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::DIRECTORY_STRING
Definition: asn1_int.h:50
Botan::X509_DN::get_attributes
std::multimap< OID, std::string > get_attributes() const
Definition: x509_dn.cpp:76

## ◆ get_attribute()

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

Definition at line 102 of file x509_dn.cpp.

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

103 {
104 typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
105
106 const OID oid = OIDS::lookup(deref_info_field(attr));
107 std::pair<rdn_iter, rdn_iter> range = dn_info.equal_range(oid);
108
109 std::vector<std::string> values;
110 for(rdn_iter j = range.first; j != range.second; ++j)
111 values.push_back(j->second.value());
112 return values;
113 }
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::X509_DN::deref_info_field
static std::string deref_info_field(const std::string &)
Definition: x509_dn.cpp:126
oid
OID oid
Definition: x509_ext.cpp:446

## ◆ get_attributes()

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

Definition at line 76 of file x509_dn.cpp.

References Botan::multimap_insert().

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

77 {
78 typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
79
80 std::multimap<OID, std::string> retval;
81 for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j)
82 multimap_insert(retval, j->first, j->second.value());
83 return retval;
84 }
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

## ◆ get_bits()

MemoryVector< byte > Botan::X509_DN::get_bits | ( |  | ) | const

Definition at line 118 of file x509_dn.cpp.

119 {
120 return dn_bits;
121 }

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

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