Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::AlternativeName Class Referencefinal

#include <pkix_types.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_Type 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 (BER_Decoder &) override
 
X509_DN dn () const
 
void encode_into (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 124 of file pkix_types.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 24 of file asn1_alt_name.cpp.

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

References add_attribute().

Member Function Documentation

◆ add_attribute()

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

Definition at line 38 of file asn1_alt_name.cpp.

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

References Botan::multimap_insert(), and type.

Referenced by AlternativeName(), and decode_from().

◆ add_othername()

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

Definition at line 55 of file asn1_alt_name.cpp.

57 {
58 if(value.empty())
59 return;
60 multimap_insert(m_othernames, oid, ASN1_String(value, type));
61 }

References Botan::multimap_insert(), and type.

Referenced by decode_from().

◆ 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.

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

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

◆ contents()

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

Definition at line 66 of file asn1_alt_name.cpp.

67 {
68 std::multimap<std::string, std::string> names;
69
70 for(const auto& name : m_alt_info)
71 {
72 multimap_insert(names, name.first, name.second);
73 }
74
75 for(const auto& othername : m_othernames)
76 {
77 multimap_insert(names,
78 othername.first.to_formatted_string(),
79 othername.second.value());
80 }
81
82 return names;
83 }
std::string name

References Botan::multimap_insert(), and name.

◆ decode_from()

void Botan::AlternativeName::decode_from ( 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 197 of file asn1_alt_name.cpp.

198 {
199 BER_Decoder names = source.start_sequence();
200
201 // FIXME this is largely a duplication of GeneralName::decode_from
202
203 while(names.more_items())
204 {
205 BER_Object obj = names.get_next_object();
206
207 if(obj.is_a(0, ASN1_Class::ContextSpecific))
208 {
209 BER_Decoder othername(obj);
210
211 OID oid;
212 othername.decode(oid);
213 if(othername.more_items())
214 {
215 BER_Object othername_value_outer = othername.get_next_object();
216 othername.verify_end();
217
218 if(othername_value_outer.is_a(0, ASN1_Class::ExplicitContextSpecific) == false)
219 throw Decoding_Error("Invalid tags on otherName value");
220
221 BER_Decoder othername_value_inner(othername_value_outer);
222
223 BER_Object value = othername_value_inner.get_next_object();
224 othername_value_inner.verify_end();
225
226 if(ASN1_String::is_string_type(value.type()) && value.get_class() == ASN1_Class::Universal)
227 {
228 add_othername(oid, ASN1::to_string(value), value.type());
229 }
230 }
231 }
232 if(obj.is_a(1, ASN1_Class::ContextSpecific))
233 {
234 add_attribute("RFC822", ASN1::to_string(obj));
235 }
236 else if(obj.is_a(2, ASN1_Class::ContextSpecific))
237 {
238 add_attribute("DNS", ASN1::to_string(obj));
239 }
240 else if(obj.is_a(6, ASN1_Class::ContextSpecific))
241 {
242 add_attribute("URI", ASN1::to_string(obj));
243 }
245 {
246 BER_Decoder dec(obj);
247 X509_DN dn;
248 std::stringstream ss;
249
250 dec.decode(dn);
251 ss << dn;
252
253 add_attribute("DN", ss.str());
254 }
255 else if(obj.is_a(7, ASN1_Class::ContextSpecific))
256 {
257 if(obj.length() == 4)
258 {
259 const uint32_t ip = load_be<uint32_t>(obj.bits(), 0);
260 add_attribute("IP", ipv4_to_string(ip));
261 }
262 }
263
264 }
265 }
static bool is_string_type(ASN1_Type tag)
Definition: asn1_str.cpp:68
void add_othername(const OID &oid, const std::string &value, ASN1_Type type)
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:209
constexpr uint32_t load_be< uint32_t >(const uint8_t in[], size_t off)
Definition: loadstor.h:190
std::string ipv4_to_string(uint32_t ip)
Definition: parsing.cpp:181

References add_attribute(), add_othername(), Botan::BER_Object::bits(), Botan::Constructed, Botan::ContextSpecific, Botan::BER_Decoder::decode(), dn(), Botan::ExplicitContextSpecific, 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::BER_Decoder::start_sequence(), Botan::ASN1::to_string(), Botan::BER_Object::type(), Botan::Universal, and Botan::BER_Decoder::verify_end().

◆ dn()

X509_DN Botan::AlternativeName::dn ( ) const

Definition at line 109 of file asn1_alt_name.cpp.

110 {
111 X509_DN dn;
112 auto range = m_alt_info.equal_range("DN");
113
114 for(auto i = range.first; i != range.second; ++i)
115 {
116 std::istringstream strm(i->second);
117 strm >> dn;
118 }
119
120 return dn;
121 }

References dn().

Referenced by decode_from(), dn(), and Botan::GeneralName::matches().

◆ encode_into()

void Botan::AlternativeName::encode_into ( 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 171 of file asn1_alt_name.cpp.

172 {
173 der.start_sequence();
174
175 encode_entries(der, m_alt_info, "RFC822", ASN1_Type(1));
176 encode_entries(der, m_alt_info, "DNS", ASN1_Type(2));
177 encode_entries(der, m_alt_info, "DN", ASN1_Type(4));
178 encode_entries(der, m_alt_info, "URI", ASN1_Type(6));
179 encode_entries(der, m_alt_info, "IP", ASN1_Type(7));
180
181 for(const auto& othername : m_othernames)
182 {
183 der.start_explicit(0)
184 .encode(othername.first)
185 .start_explicit(0)
186 .encode(othername.second)
187 .end_explicit()
188 .end_explicit();
189 }
190
191 der.end_cons();
192 }
ASN1_Type
Definition: asn1_obj.h:39

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

◆ get_attribute()

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

Definition at line 100 of file asn1_alt_name.cpp.

101 {
102 std::vector<std::string> results;
103 auto range = m_alt_info.equal_range(attr);
104 for(auto i = range.first; i != range.second; ++i)
105 results.push_back(i->second);
106 return results;
107 }

Referenced by Botan::X509_Certificate::issuer_info(), Botan::GeneralName::matches(), and Botan::X509_Certificate::subject_info().

◆ get_attributes()

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

Definition at line 140 of file pkix_types.h.

141 {
142 return m_alt_info;
143 }

◆ get_first_attribute()

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

Definition at line 91 of file asn1_alt_name.cpp.

92 {
93 auto i = m_alt_info.lower_bound(attr);
94 if(i != m_alt_info.end() && i->first == attr)
95 return i->second;
96
97 return "";
98 }

◆ get_othernames()

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

Definition at line 145 of file pkix_types.h.

146 {
147 return m_othernames;
148 }

◆ has_field()

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

Definition at line 85 of file asn1_alt_name.cpp.

86 {
87 auto range = m_alt_info.equal_range(attr);
88 return (range.first != range.second);
89 }

◆ has_items()

bool Botan::AlternativeName::has_items ( ) const

Definition at line 126 of file asn1_alt_name.cpp.

127 {
128 return (!m_alt_info.empty() || !m_othernames.empty());
129 }

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