Botan::X509_DN Class Reference

#include <asn1_obj.h>

Inheritance diagram for Botan::X509_DN:

Botan::ASN1_Object

List of all members.

Public Member Functions

void add_attribute (const OID &, const std::string &)
void add_attribute (const std::string &, const std::string &)
std::multimap< std::string,
std::string > 
contents () const
void decode_from (class BER_Decoder &)
void do_decode (const MemoryRegion< byte > &)
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< byteget_bits () const
 X509_DN (const std::multimap< std::string, std::string > &)
 X509_DN (const std::multimap< OID, std::string > &)
 X509_DN ()

Static Public Member Functions

static std::string deref_info_field (const std::string &)


Detailed Description

Distinguished Name

Definition at line 88 of file asn1_obj.h.


Constructor & Destructor Documentation

Botan::X509_DN::X509_DN (  ) 

Definition at line 20 of file asn1_dn.cpp.

00021    {
00022    }

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

Definition at line 27 of file asn1_dn.cpp.

References add_attribute().

00028    {
00029    std::multimap<OID, std::string>::const_iterator j;
00030    for(j = args.begin(); j != args.end(); ++j)
00031       add_attribute(j->first, j->second);
00032    }

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

Definition at line 37 of file asn1_dn.cpp.

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

00038    {
00039    std::multimap<std::string, std::string>::const_iterator j;
00040    for(j = args.begin(); j != args.end(); ++j)
00041       add_attribute(OIDS::lookup(j->first), j->second);
00042    }


Member Function Documentation

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

Definition at line 57 of file asn1_dn.cpp.

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

00058    {
00059    if(str == "")
00060       return;
00061 
00062    typedef std::multimap<OID, ASN1_String>::iterator rdn_iter;
00063 
00064    std::pair<rdn_iter, rdn_iter> range = dn_info.equal_range(oid);
00065    for(rdn_iter j = range.first; j != range.second; ++j)
00066       if(j->second.value() == str)
00067          return;
00068 
00069    multimap_insert(dn_info, oid, ASN1_String(str));
00070    dn_bits.destroy();
00071    }

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

Definition at line 47 of file asn1_dn.cpp.

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

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

00049    {
00050    OID oid = OIDS::lookup(type);
00051    add_attribute(oid, str);
00052    }

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

Definition at line 89 of file asn1_dn.cpp.

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

00090    {
00091    typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
00092 
00093    std::multimap<std::string, std::string> retval;
00094    for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j)
00095       multimap_insert(retval, OIDS::lookup(j->first), j->second.value());
00096    return retval;
00097    }

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 293 of file asn1_dn.cpp.

References do_decode(), Botan::BER_Decoder::end_cons(), Botan::BER_Decoder::raw_bytes(), Botan::SEQUENCE, and Botan::BER_Decoder::start_cons().

00294    {
00295    dn_info.clear();
00296 
00297    source.start_cons(SEQUENCE)
00298       .raw_bytes(dn_bits)
00299    .end_cons();
00300 
00301    do_decode(dn_bits);
00302    }

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

Definition at line 155 of file asn1_dn.cpp.

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

00156    {
00157    if(info == "Name" || info == "CommonName") return "X520.CommonName";
00158    if(info == "SerialNumber")                 return "X520.SerialNumber";
00159    if(info == "Country")                      return "X520.Country";
00160    if(info == "Organization")                 return "X520.Organization";
00161    if(info == "Organizational Unit" || info == "OrgUnit")
00162       return "X520.OrganizationalUnit";
00163    if(info == "Locality")                     return "X520.Locality";
00164    if(info == "State" || info == "Province")  return "X520.State";
00165    if(info == "Email")                        return "RFC822";
00166    return info;
00167    }

void Botan::X509_DN::do_decode ( const MemoryRegion< byte > &  bits  ) 

Definition at line 118 of file asn1_dn.cpp.

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

Referenced by decode_from().

00119    {
00120    BER_Decoder sequence(bits);
00121 
00122    while(sequence.more_items())
00123       {
00124       BER_Decoder rdn = sequence.start_cons(SET);
00125 
00126       while(rdn.more_items())
00127          {
00128          OID oid;
00129          ASN1_String str;
00130 
00131          rdn.start_cons(SEQUENCE)
00132             .decode(oid)
00133             .decode(str)
00134             .verify_end()
00135         .end_cons();
00136 
00137          add_attribute(oid, str.value());
00138          }
00139       }
00140 
00141    dn_bits = bits;
00142    }

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 268 of file asn1_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().

00269    {
00270    std::multimap<OID, std::string> dn_info = get_attributes();
00271 
00272    der.start_cons(SEQUENCE);
00273 
00274    if(!dn_bits.empty())
00275       der.raw_bytes(dn_bits);
00276    else
00277       {
00278       do_ava(der, dn_info, PRINTABLE_STRING, "X520.Country", true);
00279       do_ava(der, dn_info, DIRECTORY_STRING, "X520.State");
00280       do_ava(der, dn_info, DIRECTORY_STRING, "X520.Locality");
00281       do_ava(der, dn_info, DIRECTORY_STRING, "X520.Organization");
00282       do_ava(der, dn_info, DIRECTORY_STRING, "X520.OrganizationalUnit");
00283       do_ava(der, dn_info, DIRECTORY_STRING, "X520.CommonName", true);
00284       do_ava(der, dn_info, PRINTABLE_STRING, "X520.SerialNumber");
00285       }
00286 
00287    der.end_cons();
00288    }

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

Definition at line 102 of file asn1_dn.cpp.

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

00103    {
00104    typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
00105 
00106    const OID oid = OIDS::lookup(deref_info_field(attr));
00107    std::pair<rdn_iter, rdn_iter> range = dn_info.equal_range(oid);
00108 
00109    std::vector<std::string> values;
00110    for(rdn_iter j = range.first; j != range.second; ++j)
00111       values.push_back(j->second.value());
00112    return values;
00113    }

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

Definition at line 76 of file asn1_dn.cpp.

References Botan::multimap_insert().

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

00077    {
00078    typedef std::multimap<OID, ASN1_String>::const_iterator rdn_iter;
00079 
00080    std::multimap<OID, std::string> retval;
00081    for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j)
00082       multimap_insert(retval, j->first, j->second.value());
00083    return retval;
00084    }

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

Definition at line 147 of file asn1_dn.cpp.

00148    {
00149    return dn_bits;
00150    }


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

Generated on Fri Aug 13 16:21:01 2010 for Botan by  doxygen 1.5.8