Botan  1.11.15
Public Member Functions
Botan::AlternativeName Class Reference

#include <asn1_alt_name.h>

Inheritance diagram for Botan::AlternativeName:
Botan::ASN1_Object

List of all members.

Public Member Functions

void add_attribute (const std::string &, const std::string &)
void add_othername (const OID &, const std::string &, ASN1_Tag)
 AlternativeName (const std::string &="", const std::string &="", const std::string &="", 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::multimap< std::string,
std::string > 
get_attributes () const
std::multimap< OID, ASN1_Stringget_othernames () const
bool has_items () const

Detailed Description

Alternative Name

Definition at line 22 of file asn1_alt_name.h.


Constructor & Destructor Documentation

Botan::AlternativeName::AlternativeName ( const std::string &  email_addr = "",
const std::string &  uri = "",
const std::string &  dns = "",
const std::string &  ip = "" 
)

Definition at line 41 of file asn1_alt_name.cpp.

References add_attribute().

   {
   add_attribute("RFC822", email_addr);
   add_attribute("DNS", dns);
   add_attribute("URI", uri);
   add_attribute("IP", ip);
   }

Member Function Documentation

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

Definition at line 55 of file asn1_alt_name.cpp.

References Botan::multimap_insert().

Referenced by AlternativeName(), Botan::create_alt_name(), and decode_from().

   {
   if(type == "" || str == "")
      return;

   auto range = alt_info.equal_range(type);
   for(auto j = range.first; j != range.second; ++j)
      if(j->second == str)
         return;

   multimap_insert(alt_info, type, str);
   }
void Botan::AlternativeName::add_othername ( const OID oid,
const std::string &  value,
ASN1_Tag  type 
)

Definition at line 72 of file asn1_alt_name.cpp.

References Botan::multimap_insert().

Referenced by decode_from().

   {
   if(value == "")
      return;
   multimap_insert(othernames, oid, ASN1_String(value, type));
   }
std::multimap< std::string, std::string > Botan::AlternativeName::contents ( ) const

Definition at line 99 of file asn1_alt_name.cpp.

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

   {
   std::multimap<std::string, std::string> names;

   for(auto i = alt_info.begin(); i != alt_info.end(); ++i)
      multimap_insert(names, i->first, i->second);

   for(auto i = othernames.begin(); i != othernames.end(); ++i)
      multimap_insert(names, OIDS::lookup(i->first), i->second.value());

   return names;
   }
void Botan::AlternativeName::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 178 of file asn1_alt_name.cpp.

References add_attribute(), add_othername(), Botan::BER_Object::class_tag, Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::BER_Decoder::decode(), Botan::BER_Decoder::get_next_object(), Botan::ipv4_to_string(), Botan::LATIN1_CHARSET, Botan::load_be< u32bit >(), Botan::LOCAL_CHARSET, Botan::BER_Decoder::more_items(), Botan::SEQUENCE, Botan::BER_Decoder::start_cons(), Botan::ASN1::to_string(), Botan::Charset::transcode(), Botan::BER_Object::type_tag, Botan::UNIVERSAL, Botan::BER_Object::value, and Botan::BER_Decoder::verify_end().

   {
   BER_Decoder names = source.start_cons(SEQUENCE);

   while(names.more_items())
      {
      BER_Object obj = names.get_next_object();
      if((obj.class_tag != CONTEXT_SPECIFIC) &&
         (obj.class_tag != (CONTEXT_SPECIFIC | CONSTRUCTED)))
         continue;

      const ASN1_Tag tag = obj.type_tag;

      if(tag == 0)
         {
         BER_Decoder othername(obj.value);

         OID oid;
         othername.decode(oid);
         if(othername.more_items())
            {
            BER_Object othername_value_outer = othername.get_next_object();
            othername.verify_end();

            if(othername_value_outer.type_tag != ASN1_Tag(0) ||
               othername_value_outer.class_tag !=
                   (CONTEXT_SPECIFIC | CONSTRUCTED)
               )
               throw Decoding_Error("Invalid tags on otherName value");

            BER_Decoder othername_value_inner(othername_value_outer.value);

            BER_Object value = othername_value_inner.get_next_object();
            othername_value_inner.verify_end();

            const ASN1_Tag value_type = value.type_tag;

            if(is_string_type(value_type) && value.class_tag == UNIVERSAL)
               add_othername(oid, ASN1::to_string(value), value_type);
            }
         }
      else if(tag == 1 || tag == 2 || tag == 6)
         {
         const std::string value = Charset::transcode(ASN1::to_string(obj),
                                                      LATIN1_CHARSET,
                                                      LOCAL_CHARSET);

         if(tag == 1) add_attribute("RFC822", value);
         if(tag == 2) add_attribute("DNS", value);
         if(tag == 6) add_attribute("URI", value);
         }
      else if(tag == 7)
         {
         if(obj.value.size() == 4)
            {
            const u32bit ip = load_be<u32bit>(&obj.value[0], 0);
            add_attribute("IP", ipv4_to_string(ip));
            }
         }

      }
   }
void Botan::AlternativeName::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 153 of file asn1_alt_name.cpp.

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::end_explicit(), Botan::SEQUENCE, Botan::DER_Encoder::start_cons(), and Botan::DER_Encoder::start_explicit().

   {
   der.start_cons(SEQUENCE);

   encode_entries(der, alt_info, "RFC822", ASN1_Tag(1));
   encode_entries(der, alt_info, "DNS", ASN1_Tag(2));
   encode_entries(der, alt_info, "URI", ASN1_Tag(6));
   encode_entries(der, alt_info, "IP", ASN1_Tag(7));

   for(auto i = othernames.begin(); i != othernames.end(); ++i)
      {
      der.start_explicit(0)
         .encode(i->first)
         .start_explicit(0)
            .encode(i->second)
         .end_explicit()
      .end_explicit();
      }

   der.end_cons();
   }
std::multimap< std::string, std::string > Botan::AlternativeName::get_attributes ( ) const

Definition at line 83 of file asn1_alt_name.cpp.

   {
   return alt_info;
   }

Definition at line 91 of file asn1_alt_name.cpp.

   {
   return othernames;
   }

Definition at line 115 of file asn1_alt_name.cpp.

   {
   return (alt_info.size() > 0 || othernames.size() > 0);
   }

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