Botan  2.7.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::vector< uint8_t > BER_encode () const
 
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(), and type.

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(), and type.

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

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 16 of file asn1_obj.cpp.

References Botan::ASN1_Object::encode_into().

Referenced by Botan::PSSR::config_for_x509(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::Certificate_Store_In_SQL::revoke_cert().

17  {
18  std::vector<uint8_t> output;
19  DER_Encoder der(output);
20  this->encode_into(der);
21  return output;
22  }
virtual void encode_into(DER_Encoder &to) const =0

◆ 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:113

◆ 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::bits(), Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::BER_Decoder::decode(), Botan::BER_Object::get_class(), Botan::BER_Decoder::get_next_object(), Botan::ipv4_to_string(), Botan::BER_Object::is_a(), Botan::ASN1_String::is_string_type(), Botan::BER_Object::length(), 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(), Botan::UNIVERSAL, and Botan::BER_Decoder::verify_end().

179  {
180  BER_Decoder names = source.start_cons(SEQUENCE);
181 
182  // FIXME this is largely a duplication of GeneralName::decode_from
183 
184  while(names.more_items())
185  {
186  BER_Object obj = names.get_next_object();
187 
188  if(obj.is_a(0, CONTEXT_SPECIFIC))
189  {
190  BER_Decoder othername(obj);
191 
192  OID oid;
193  othername.decode(oid);
194  if(othername.more_items())
195  {
196  BER_Object othername_value_outer = othername.get_next_object();
197  othername.verify_end();
198 
199  if(othername_value_outer.is_a(0, ASN1_Tag(CONTEXT_SPECIFIC | CONSTRUCTED)) == false)
200  throw Decoding_Error("Invalid tags on otherName value");
201 
202  BER_Decoder othername_value_inner(othername_value_outer);
203 
204  BER_Object value = othername_value_inner.get_next_object();
205  othername_value_inner.verify_end();
206 
207  if(ASN1_String::is_string_type(value.type()) && value.get_class() == UNIVERSAL)
208  {
209  add_othername(oid, ASN1::to_string(value), value.type());
210  }
211  }
212  }
213  if(obj.is_a(1, CONTEXT_SPECIFIC))
214  {
215  add_attribute("RFC822", ASN1::to_string(obj));
216  }
217  else if(obj.is_a(2, CONTEXT_SPECIFIC))
218  {
219  add_attribute("DNS", ASN1::to_string(obj));
220  }
221  else if(obj.is_a(6, CONTEXT_SPECIFIC))
222  {
223  add_attribute("URI", ASN1::to_string(obj));
224  }
225  else if(obj.is_a(4, ASN1_Tag(CONTEXT_SPECIFIC | CONSTRUCTED)))
226  {
227  BER_Decoder dec(obj);
228  X509_DN dn;
229  std::stringstream ss;
230 
231  dec.decode(dn);
232  ss << dn;
233 
234  add_attribute("DN", ss.str());
235  }
236  else if(obj.is_a(7, CONTEXT_SPECIFIC))
237  {
238  if(obj.length() == 4)
239  {
240  const uint32_t ip = load_be<uint32_t>(obj.bits(), 0);
241  add_attribute("IP", ipv4_to_string(ip));
242  }
243  }
244 
245  }
246  }
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:210
ASN1_Tag
Definition: asn1_obj.h:22
std::string ipv4_to_string(uint32_t ip)
Definition: parsing.cpp:294

◆ 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::X509_Certificate::issuer_info(), Botan::GeneralName::matches(), and Botan::X509_Certificate::subject_info().

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.

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

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