Botan  2.4.0
Crypto and TLS for C++11
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 &key, const std::string &val)
 
void add_attribute (const OID &oid, const std::string &val)
 
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 &attr) const
 
std::multimap< OID, std::string > get_attributes () const
 
const std::vector< uint8_t > & get_bits () const
 
std::string get_first_attribute (const std::string &attr) const
 
bool has_field (const std::string &attr) const
 
 X509_DN ()=default
 
 X509_DN (const std::multimap< OID, std::string > &vals)
 
 X509_DN (const std::multimap< std::string, std::string > &vals)
 

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 23 of file x509_dn.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 > &  vals)
explicit

Definition at line 22 of file x509_dn.cpp.

References add_attribute().

23  {
24  for(auto i = args.begin(); i != args.end(); ++i)
25  add_attribute(i->first, i->second);
26  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:40

◆ X509_DN() [3/3]

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

Definition at line 31 of file x509_dn.cpp.

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

32  {
33  for(auto i = args.begin(); i != args.end(); ++i)
34  add_attribute(OIDS::lookup(i->first), i->second);
35  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:40
std::string lookup(const OID &oid)
Definition: oids.cpp:18

Member Function Documentation

◆ add_attribute() [1/2]

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

Definition at line 40 of file x509_dn.cpp.

References Botan::OIDS::lookup().

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

42  {
43  OID oid = OIDS::lookup(type);
44  add_attribute(oid, str);
45  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:40
MechanismType type
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ add_attribute() [2/2]

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

Definition at line 50 of file x509_dn.cpp.

References Botan::multimap_insert().

51  {
52  if(str.empty())
53  return;
54 
55  auto range = m_dn_info.equal_range(oid);
56  for(auto i = range.first; i != range.second; ++i)
57  if(i->second.value() == str)
58  return;
59 
60  multimap_insert(m_dn_info, oid, ASN1_String(str));
61  m_dn_bits.clear();
62  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

◆ contents()

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

Definition at line 78 of file x509_dn.cpp.

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

Referenced by Botan::operator<<().

79  {
80  std::multimap<std::string, std::string> retval;
81  for(auto i = m_dn_info.begin(); i != m_dn_info.end(); ++i)
82  {
83  std::string str_value = OIDS::oid2str(i->first);
84 
85  if(str_value.empty())
86  str_value = i->first.as_string();
87  multimap_insert(retval, str_value, i->second.value());
88  }
89  return retval;
90  }
std::string oid2str(const OID &oid)
Definition: oids.h:32
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)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe 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(), 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().

265  {
266  std::vector<uint8_t> 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  .end_cons();
287 
288  add_attribute(oid, str.value());
289  }
290  }
291 
292  m_dn_bits = bits;
293  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:40

◆ deref_info_field()

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

Definition at line 133 of file x509_dn.cpp.

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

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

◆ empty()

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

Definition at line 56 of file x509_dn.h.

References BOTAN_PUBLIC_API, Botan::operator!=(), Botan::operator<(), Botan::operator<<(), Botan::operator==(), and Botan::operator>>().

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

56 { return m_dn_info.empty(); }

◆ encode_into()

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 239 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_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), and Botan::Certificate_Store_In_SQL::insert_cert().

240  {
241  auto dn_info = get_attributes();
242 
243  der.start_cons(SEQUENCE);
244 
245  if(!m_dn_bits.empty())
246  der.raw_bytes(m_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  }
std::multimap< OID, std::string > get_attributes() const
Definition: x509_dn.cpp:67

◆ get_attribute()

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

Definition at line 113 of file x509_dn.cpp.

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

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

114  {
115  const OID oid = OIDS::lookup(deref_info_field(attr));
116 
117  auto range = m_dn_info.equal_range(oid);
118 
119  std::vector<std::string> values;
120  for(auto i = range.first; i != range.second; ++i)
121  values.push_back(i->second.value());
122  return values;
123  }
static std::string deref_info_field(const std::string &key)
Definition: x509_dn.cpp:133
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ get_attributes()

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

Definition at line 67 of file x509_dn.cpp.

References Botan::multimap_insert().

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

68  {
69  std::multimap<OID, std::string> retval;
70  for(auto i = m_dn_info.begin(); i != m_dn_info.end(); ++i)
71  multimap_insert(retval, i->first, i->second.value());
72  return retval;
73  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

◆ get_bits()

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

Definition at line 125 of file x509_dn.cpp.

126  {
127  return m_dn_bits;
128  }

◆ get_first_attribute()

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

Definition at line 99 of file x509_dn.cpp.

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

100  {
101  const OID oid = OIDS::lookup(deref_info_field(attr));
102 
103  auto i = m_dn_info.lower_bound(oid);
104  if(i != m_dn_info.end() && i->first == oid)
105  return i->second.value();
106 
107  return "";
108  }
static std::string deref_info_field(const std::string &key)
Definition: x509_dn.cpp:133
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ has_field()

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

Definition at line 92 of file x509_dn.cpp.

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

93  {
94  const OID oid = OIDS::lookup(deref_info_field(attr));
95  auto range = m_dn_info.equal_range(oid);
96  return (range.first != range.second);
97  }
static std::string deref_info_field(const std::string &key)
Definition: x509_dn.cpp:133
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ 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 45 of file x509_dn_ub.cpp.

Referenced by Botan::PKIX::check_chain().

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

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