Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::AlternativeName Class Referencefinal

#include <asn1_alt_name.h>

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

Public Member Functions

void add_attribute (const std::string &type, const std::string &value)
 
void add_othername (const OID &oid, const std::string &value, ASN1_Tag type)
 
 AlternativeName (const std::string &email_addr="", const std::string &uri="", const std::string &dns="", const std::string &ip_address="")
 
std::multimap< std::string, std::string > contents () const
 
void decode_from (class BER_Decoder &) override
 
void encode_into (class DER_Encoder &) const override
 
std::vector< std::string > get_attribute (const std::string &attr) const
 
const std::multimap< std::string, std::string > & get_attributes () const
 
std::string get_first_attribute (const std::string &attr) const
 
const std::multimap< OID, ASN1_String > & get_othernames () const
 
bool has_field (const std::string &attr) const
 
bool has_items () const
 

Detailed Description

Alternative Name

Definition at line 21 of file asn1_alt_name.h.

Constructor & Destructor Documentation

◆ AlternativeName()

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

Definition at line 25 of file asn1_alt_name.cpp.

References add_attribute().

29  {
30  add_attribute("RFC822", email_addr);
31  add_attribute("DNS", dns);
32  add_attribute("URI", uri);
33  add_attribute("IP", ip);
34  }
void add_attribute(const std::string &type, const std::string &value)

Member Function Documentation

◆ add_attribute()

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

Definition at line 39 of file asn1_alt_name.cpp.

References Botan::multimap_insert().

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

41  {
42  if(type.empty() || value.empty())
43  return;
44 
45  auto range = m_alt_info.equal_range(type);
46  for(auto j = range.first; j != range.second; ++j)
47  if(j->second == value)
48  return;
49 
50  multimap_insert(m_alt_info, type, value);
51  }
MechanismType type
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

◆ add_othername()

void Botan::AlternativeName::add_othername ( const OID oid,
const std::string &  value,
ASN1_Tag  type 
)

Definition at line 56 of file asn1_alt_name.cpp.

References Botan::multimap_insert().

Referenced by decode_from().

58  {
59  if(value.empty())
60  return;
61  multimap_insert(m_othernames, oid, ASN1_String(value, type));
62  }
MechanismType type
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

◆ contents()

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

Definition at line 67 of file asn1_alt_name.cpp.

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

68  {
69  std::multimap<std::string, std::string> names;
70 
71  for(auto i = m_alt_info.begin(); i != m_alt_info.end(); ++i)
72  multimap_insert(names, i->first, i->second);
73 
74  for(auto i = m_othernames.begin(); i != m_othernames.end(); ++i)
75  multimap_insert(names, OIDS::lookup(i->first), i->second.value());
76 
77  return names;
78  }
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ decode_from()

void Botan::AlternativeName::decode_from ( class BER_Decoder from)
overridevirtual

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::ASN1_String::is_string_type(), Botan::load_be< uint32_t >(), Botan::BER_Decoder::more_items(), Botan::SEQUENCE, Botan::BER_Decoder::start_cons(), Botan::ASN1::to_string(), 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(ASN1_String::is_string_type(value_type) && value.class_tag == UNIVERSAL)
216  {
217  add_othername(oid, ASN1::to_string(value), value_type);
218  }
219  }
220  }
221  else if(tag == 1 || tag == 2 || tag == 6)
222  {
223  if(tag == 1) add_attribute("RFC822", ASN1::to_string(obj));
224  if(tag == 2) add_attribute("DNS", ASN1::to_string(obj));
225  if(tag == 6) add_attribute("URI", ASN1::to_string(obj));
226  }
227  else if(tag == 4)
228  {
229  BER_Decoder dec(obj.value);
230  X509_DN dn;
231  std::stringstream ss;
232 
233  dec.decode(dn);
234  ss << dn;
235 
236  add_attribute("DN", ss.str());
237  }
238  else if(tag == 7)
239  {
240  if(obj.value.size() == 4)
241  {
242  const uint32_t ip = load_be<uint32_t>(&obj.value[0], 0);
243  add_attribute("IP", ipv4_to_string(ip));
244  }
245  }
246 
247  }
248  }
static bool is_string_type(ASN1_Tag tag)
Definition: asn1_str.cpp:68
void add_othername(const OID &oid, const std::string &value, ASN1_Tag type)
void add_attribute(const std::string &type, const std::string &value)
uint32_t load_be< uint32_t >(const uint8_t in[], size_t off)
Definition: loadstor.h:177
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
ASN1_Tag
Definition: asn1_obj.h:22
std::string ipv4_to_string(uint32_t ip)
Definition: parsing.cpp:292

◆ encode_into()

void Botan::AlternativeName::encode_into ( class DER_Encoder to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

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

153  {
154  der.start_cons(SEQUENCE);
155 
156  encode_entries(der, m_alt_info, "RFC822", ASN1_Tag(1));
157  encode_entries(der, m_alt_info, "DNS", ASN1_Tag(2));
158  encode_entries(der, m_alt_info, "DN", ASN1_Tag(4));
159  encode_entries(der, m_alt_info, "URI", ASN1_Tag(6));
160  encode_entries(der, m_alt_info, "IP", ASN1_Tag(7));
161 
162  for(auto i = m_othernames.begin(); i != m_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:22

◆ get_attribute()

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

Definition at line 95 of file asn1_alt_name.cpp.

Referenced by Botan::GeneralName::matches().

96  {
97  std::vector<std::string> results;
98  auto range = m_alt_info.equal_range(attr);
99  for(auto i = range.first; i != range.second; ++i)
100  results.push_back(i->second);
101  return results;
102  }

◆ get_attributes()

const std::multimap<std::string, std::string>& Botan::AlternativeName::get_attributes ( ) const
inline

Definition at line 37 of file asn1_alt_name.h.

38  {
39  return m_alt_info;
40  }

◆ get_first_attribute()

std::string Botan::AlternativeName::get_first_attribute ( const std::string &  attr) const

Definition at line 86 of file asn1_alt_name.cpp.

87  {
88  auto i = m_alt_info.lower_bound(attr);
89  if(i != m_alt_info.end() && i->first == attr)
90  return i->second;
91 
92  return "";
93  }

◆ get_othernames()

const std::multimap<OID, ASN1_String>& Botan::AlternativeName::get_othernames ( ) const
inline

Definition at line 42 of file asn1_alt_name.h.

43  {
44  return m_othernames;
45  }

◆ has_field()

bool Botan::AlternativeName::has_field ( const std::string &  attr) const

Definition at line 80 of file asn1_alt_name.cpp.

81  {
82  auto range = m_alt_info.equal_range(attr);
83  return (range.first != range.second);
84  }

◆ has_items()

bool Botan::AlternativeName::has_items ( ) const

Definition at line 107 of file asn1_alt_name.cpp.

References Botan::DER_Encoder::add_object(), Botan::CONTEXT_SPECIFIC, Botan::DER_Encoder::encode(), Botan::IA5_STRING, Botan::store_be(), Botan::string_to_ipv4(), type, and Botan::ASN1_String::value().

108  {
109  return (m_alt_info.size() > 0 || m_othernames.size() > 0);
110  }

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