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

#include <asn1_alt_name.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 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().

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 &)

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

57  {
58  if(type == "" || str == "")
59  return;
60 
61  auto range = alt_info.equal_range(type);
62  for(auto j = range.first; j != range.second; ++j)
63  if(j->second == str)
64  return;
65 
66  multimap_insert(alt_info, type, str);
67  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:55
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().

74  {
75  if(value == "")
76  return;
77  multimap_insert(othernames, oid, ASN1_String(value, type));
78  }
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::AlternativeName::contents ( ) const

Definition at line 99 of file asn1_alt_name.cpp.

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

100  {
101  std::multimap<std::string, std::string> names;
102 
103  for(auto i = alt_info.begin(); i != alt_info.end(); ++i)
104  multimap_insert(names, i->first, i->second);
105 
106  for(auto i = othernames.begin(); i != othernames.end(); ++i)
107  multimap_insert(names, OIDS::lookup(i->first), i->second.value());
108 
109  return names;
110  }
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::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(), oid, 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().

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

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

Definition at line 83 of file asn1_alt_name.cpp.

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

Definition at line 91 of file asn1_alt_name.cpp.

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

Definition at line 115 of file asn1_alt_name.cpp.

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

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