Botan  1.10.9
Public Member Functions | List of all members
Botan::AlternativeName Class Reference

#include <asn1_obj.h>

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

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 68 of file asn1_obj.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.cpp.

References add_attribute().

45  {
46  add_attribute("RFC822", email_addr);
47  add_attribute("DNS", dns);
48  add_attribute("URI", uri);
49  add_attribute("IP", ip);
50  }
void add_attribute(const std::string &, const std::string &)
Definition: asn1_alt.cpp:55

Member Function Documentation

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

Definition at line 55 of file asn1_alt.cpp.

References Botan::multimap_insert().

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

57  {
58  if(type == "" || str == "")
59  return;
60 
61  typedef std::multimap<std::string, std::string>::iterator iter;
62  std::pair<iter, iter> range = alt_info.equal_range(type);
63  for(iter j = range.first; j != range.second; ++j)
64  if(j->second == str)
65  return;
66 
67  multimap_insert(alt_info, type, str);
68  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76
void Botan::AlternativeName::add_othername ( const OID oid,
const std::string &  value,
ASN1_Tag  type 
)

Definition at line 73 of file asn1_alt.cpp.

References Botan::multimap_insert().

Referenced by decode_from().

75  {
76  if(value == "")
77  return;
78  multimap_insert(othernames, oid, ASN1_String(value, type));
79  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76
OID oid
Definition: x509_ext.cpp:446
std::multimap< std::string, std::string > Botan::AlternativeName::contents ( ) const

Definition at line 100 of file asn1_alt.cpp.

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

101  {
102  std::multimap<std::string, std::string> names;
103 
104  typedef std::multimap<std::string, std::string>::const_iterator rdn_iter;
105  for(rdn_iter j = alt_info.begin(); j != alt_info.end(); ++j)
106  multimap_insert(names, j->first, j->second);
107 
108  typedef std::multimap<OID, ASN1_String>::const_iterator on_iter;
109  for(on_iter j = othernames.begin(); j != othernames.end(); ++j)
110  multimap_insert(names, OIDS::lookup(j->first), j->second.value());
111 
112  return names;
113  }
std::string lookup(const OID &oid)
Definition: oids.cpp:31
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76
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 183 of file asn1_alt.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(), oid, Botan::SEQUENCE, Botan::MemoryRegion< T >::size(), 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().

184  {
185  BER_Decoder names = source.start_cons(SEQUENCE);
186 
187  while(names.more_items())
188  {
189  BER_Object obj = names.get_next_object();
190  if((obj.class_tag != CONTEXT_SPECIFIC) &&
191  (obj.class_tag != (CONTEXT_SPECIFIC | CONSTRUCTED)))
192  continue;
193 
194  const ASN1_Tag tag = obj.type_tag;
195 
196  if(tag == 0)
197  {
198  BER_Decoder othername(obj.value);
199 
200  OID oid;
201  othername.decode(oid);
202  if(othername.more_items())
203  {
204  BER_Object othername_value_outer = othername.get_next_object();
205  othername.verify_end();
206 
207  if(othername_value_outer.type_tag != ASN1_Tag(0) ||
208  othername_value_outer.class_tag !=
210  )
211  throw Decoding_Error("Invalid tags on otherName value");
212 
213  BER_Decoder othername_value_inner(othername_value_outer.value);
214 
215  BER_Object value = othername_value_inner.get_next_object();
216  othername_value_inner.verify_end();
217 
218  const ASN1_Tag value_type = value.type_tag;
219 
220  if(is_string_type(value_type) && value.class_tag == UNIVERSAL)
221  add_othername(oid, ASN1::to_string(value), value_type);
222  }
223  }
224  else if(tag == 1 || tag == 2 || tag == 6)
225  {
226  const std::string value = Charset::transcode(ASN1::to_string(obj),
228  LOCAL_CHARSET);
229 
230  if(tag == 1) add_attribute("RFC822", value);
231  if(tag == 2) add_attribute("DNS", value);
232  if(tag == 6) add_attribute("URI", value);
233  }
234  else if(tag == 7)
235  {
236  if(obj.value.size() == 4)
237  {
238  const u32bit ip = load_be<u32bit>(&obj.value[0], 0);
239  add_attribute("IP", ipv4_to_string(ip));
240  }
241  }
242 
243  }
244  }
void add_attribute(const std::string &, const std::string &)
Definition: asn1_alt.cpp:55
std::string ipv4_to_string(u32bit ip)
Definition: parsing.cpp:277
std::string to_string(const BER_Object &obj)
Definition: asn1_int.cpp:46
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
ASN1_Tag
Definition: asn1_int.h:19
u32bit load_be< u32bit >(const byte in[], size_t off)
Definition: loadstor.h:166
void add_othername(const OID &, const std::string &, ASN1_Tag)
Definition: asn1_alt.cpp:73
unsigned int u32bit
Definition: types.h:32
OID oid
Definition: x509_ext.cpp:446
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 157 of file asn1_alt.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().

158  {
159  der.start_cons(SEQUENCE);
160 
161  encode_entries(der, alt_info, "RFC822", ASN1_Tag(1));
162  encode_entries(der, alt_info, "DNS", ASN1_Tag(2));
163  encode_entries(der, alt_info, "URI", ASN1_Tag(6));
164  encode_entries(der, alt_info, "IP", ASN1_Tag(7));
165 
166  std::multimap<OID, ASN1_String>::const_iterator i;
167  for(i = othernames.begin(); i != othernames.end(); ++i)
168  {
169  der.start_explicit(0)
170  .encode(i->first)
171  .start_explicit(0)
172  .encode(i->second)
173  .end_explicit()
174  .end_explicit();
175  }
176 
177  der.end_cons();
178  }
ASN1_Tag
Definition: asn1_int.h:19
std::multimap< std::string, std::string > Botan::AlternativeName::get_attributes ( ) const

Definition at line 84 of file asn1_alt.cpp.

85  {
86  return alt_info;
87  }
std::multimap< OID, ASN1_String > Botan::AlternativeName::get_othernames ( ) const

Definition at line 92 of file asn1_alt.cpp.

93  {
94  return othernames;
95  }
bool Botan::AlternativeName::has_items ( ) const

Definition at line 118 of file asn1_alt.cpp.

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

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