Botan  1.11.26
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:
Botan::ASN1_Object

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
 
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< byteget_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  }
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  }
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47
std::string lookup(const OID &oid)
Definition: oids.cpp:155

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  }
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47
std::string lookup(const OID &oid)
Definition: oids.cpp:155
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  }
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::X509_CRL::is_revoked(), Botan::operator<<(), Botan::PKCS10_Request::PKCS10_Request(), and Botan::X509_Certificate::X509_Certificate().

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  }
std::string lookup(const OID &oid)
Definition: oids.cpp:155
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)
overridevirtual

Decode whatever this object is from from

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

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

251  {
252  std::vector<byte> 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  .verify_end()
273  .end_cons();
274 
275  add_attribute(oid, str.value());
276  }
277  }
278 
279  m_dn_bits = bits;
280  }
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:47
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  }
void Botan::X509_DN::encode_into ( class 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 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().

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  }
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  }
std::string lookup(const OID &oid)
Definition: oids.cpp:155
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::GeneralName::matches(), 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  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76
std::vector< byte > Botan::X509_DN::get_bits ( ) const

Definition at line 111 of file x509_dn.cpp.

Referenced by Botan::X509_Certificate::X509_Certificate().

112  {
113  return m_dn_bits;
114  }

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