Botan  2.7.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)
 
void add_attribute (const OID &oid, const ASN1_String &val)
 
std::vector< uint8_t > BER_encode () const
 
std::multimap< std::string, std::string > contents () const
 
void decode_from (class BER_Decoder &) override
 
const std::vector< std::pair< OID, ASN1_String > > & dn_info () const
 
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
 
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
 
 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 24 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 > &  args)
inlineexplicit

Definition at line 29 of file x509_dn.h.

30  {
31  for(auto i : args)
32  add_attribute(i.first, i.second);
33  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:22

◆ X509_DN() [3/3]

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

Definition at line 35 of file x509_dn.h.

36  {
37  for(auto i : args)
38  add_attribute(i.first, i.second);
39  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:22

Member Function Documentation

◆ add_attribute() [1/3]

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

Definition at line 22 of file x509_dn.cpp.

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

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

24  {
26  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:22
MechanismType type
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ add_attribute() [2/3]

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

Definition at line 65 of file x509_dn.h.

66  {
67  add_attribute(oid, ASN1_String(val));
68  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:22

◆ add_attribute() [3/3]

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

Definition at line 31 of file x509_dn.cpp.

References Botan::ASN1_String::empty().

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

◆ 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.

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().

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

◆ contents()

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

Definition at line 55 of file x509_dn.cpp.

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

56  {
57  std::multimap<std::string, std::string> retval;
58 
59  for(auto& i : m_rdn)
60  {
61  std::string str_value = OIDS::oid2str(i.first);
62 
63  if(str_value.empty())
64  str_value = i.first.as_string();
65  multimap_insert(retval, str_value, i.second.value());
66  }
67  return retval;
68  }
std::string oid2str(const OID &oid)
Definition: oids.h:48
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 233 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, and Botan::BER_Decoder::start_cons().

Referenced by Botan::Certificate_Store_In_SQL::all_subjects().

234  {
235  std::vector<uint8_t> bits;
236 
237  source.start_cons(SEQUENCE)
238  .raw_bytes(bits)
239  .end_cons();
240 
241  BER_Decoder sequence(bits);
242 
243  while(sequence.more_items())
244  {
245  BER_Decoder rdn = sequence.start_cons(SET);
246 
247  while(rdn.more_items())
248  {
249  OID oid;
250  ASN1_String str;
251 
252  rdn.start_cons(SEQUENCE).decode(oid).decode(str).end_cons();
253 
254  add_attribute(oid, str);
255  }
256  }
257 
258  m_dn_bits = bits;
259  }
void add_attribute(const std::string &key, const std::string &val)
Definition: x509_dn.cpp:22

◆ deref_info_field()

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

Definition at line 128 of file x509_dn.cpp.

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

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

◆ dn_info()

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

Definition at line 54 of file x509_dn.h.

Referenced by Botan::operator<<().

54 { return m_rdn; }

◆ empty()

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

Definition at line 52 of file x509_dn.h.

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

52 { return m_rdn.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 202 of file x509_dn.cpp.

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().

203  {
204  der.start_cons(SEQUENCE);
205 
206  if(!m_dn_bits.empty())
207  {
208  /*
209  If we decoded this from somewhere, encode it back exactly as
210  we received it
211  */
212  der.raw_bytes(m_dn_bits);
213  }
214  else
215  {
216  for(const auto& dn : m_rdn)
217  {
218  der.start_cons(SET)
219  .start_cons(SEQUENCE)
220  .encode(dn.first)
221  .encode(dn.second)
222  .end_cons()
223  .end_cons();
224  }
225  }
226 
227  der.end_cons();
228  }

◆ get_attribute()

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

Definition at line 108 of file x509_dn.cpp.

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

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

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

◆ get_attributes()

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

Definition at line 43 of file x509_dn.cpp.

References Botan::multimap_insert().

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

44  {
45  std::multimap<OID, std::string> retval;
46 
47  for(auto& i : m_rdn)
48  multimap_insert(retval, i.first, i.second.value());
49  return retval;
50  }
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
inline

Definition at line 50 of file x509_dn.h.

50 { return m_dn_bits; }

◆ get_first_attribute() [1/2]

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

Definition at line 92 of file x509_dn.cpp.

Referenced by get_first_attribute().

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

◆ get_first_attribute() [2/2]

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

Definition at line 86 of file x509_dn.cpp.

References deref_info_field(), get_first_attribute(), Botan::OIDS::lookup(), and Botan::ASN1_String::value().

87  {
88  const OID oid = OIDS::lookup(deref_info_field(attr));
89  return get_first_attribute(oid).value();
90  }
ASN1_String get_first_attribute(const OID &oid) const
Definition: x509_dn.cpp:92
static std::string deref_info_field(const std::string &key)
Definition: x509_dn.cpp:128
const std::string & value() const
Definition: asn1_str.h:27
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ has_field() [1/2]

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

Definition at line 75 of file x509_dn.cpp.

Referenced by has_field().

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

◆ has_field() [2/2]

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

Definition at line 70 of file x509_dn.cpp.

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

71  {
73  }
static std::string deref_info_field(const std::string &key)
Definition: x509_dn.cpp:128
bool has_field(const OID &oid) const
Definition: x509_dn.cpp:75
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ 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: