Botan  1.11.11
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:
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 &)
 
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
 
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 21 of file x509_dn.cpp.

22  {
23  }
Botan::X509_DN::X509_DN ( const std::multimap< OID, std::string > &  args)

Definition at line 28 of file x509_dn.cpp.

References add_attribute().

29  {
30  for(auto i = args.begin(); i != args.end(); ++i)
31  add_attribute(i->first, i->second);
32  }
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:46
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  for(auto i = args.begin(); i != args.end(); ++i)
40  add_attribute(OIDS::lookup(i->first), i->second);
41  }
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:46
std::string lookup(const OID &oid)
Definition: oids.cpp:111

Member Function Documentation

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

Definition at line 46 of file x509_dn.cpp.

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

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

48  {
49  OID oid = OIDS::lookup(type);
50  add_attribute(oid, str);
51  }
void add_attribute(const std::string &, const std::string &)
Definition: x509_dn.cpp:46
std::string lookup(const OID &oid)
Definition: oids.cpp:111
OID oid
Definition: x509_ext.cpp:447
void Botan::X509_DN::add_attribute ( const OID oid,
const std::string &  str 
)

Definition at line 56 of file x509_dn.cpp.

References Botan::multimap_insert().

57  {
58  if(str == "")
59  return;
60 
61  auto range = dn_info.equal_range(oid);
62  for(auto i = range.first; i != range.second; ++i)
63  if(i->second.value() == str)
64  return;
65 
66  multimap_insert(dn_info, oid, ASN1_String(str));
67  dn_bits.clear();
68  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:55
OID oid
Definition: x509_ext.cpp:447
std::multimap< std::string, std::string > Botan::X509_DN::contents ( ) const

Definition at line 84 of file x509_dn.cpp.

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

Referenced by Botan::operator<<().

85  {
86  std::multimap<std::string, std::string> retval;
87  for(auto i = dn_info.begin(); i != dn_info.end(); ++i)
88  multimap_insert(retval, OIDS::lookup(i->first), i->second.value());
89  return retval;
90  }
std::string lookup(const OID &oid)
Definition: oids.cpp:111
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:55
void Botan::X509_DN::decode_from ( class BER_Decoder from)
virtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 249 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().

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

Definition at line 118 of file x509_dn.cpp.

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

119  {
120  if(info == "Name" || info == "CommonName") return "X520.CommonName";
121  if(info == "SerialNumber") return "X520.SerialNumber";
122  if(info == "Country") return "X520.Country";
123  if(info == "Organization") return "X520.Organization";
124  if(info == "Organizational Unit" || info == "OrgUnit")
125  return "X520.OrganizationalUnit";
126  if(info == "Locality") return "X520.Locality";
127  if(info == "State" || info == "Province") return "X520.State";
128  if(info == "Email") return "RFC822";
129  return info;
130  }
void Botan::X509_DN::encode_into ( class DER_Encoder to) const
virtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 224 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().

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

Definition at line 95 of file x509_dn.cpp.

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

96  {
97  const OID oid = OIDS::lookup(deref_info_field(attr));
98 
99  auto range = dn_info.equal_range(oid);
100 
101  std::vector<std::string> values;
102  for(auto i = range.first; i != range.second; ++i)
103  values.push_back(i->second.value());
104  return values;
105  }
std::string lookup(const OID &oid)
Definition: oids.cpp:111
static std::string deref_info_field(const std::string &)
Definition: x509_dn.cpp:118
OID oid
Definition: x509_ext.cpp:447
std::multimap< OID, std::string > Botan::X509_DN::get_attributes ( ) const

Definition at line 73 of file x509_dn.cpp.

References Botan::multimap_insert().

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

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

Definition at line 110 of file x509_dn.cpp.

111  {
112  return dn_bits;
113  }

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