Botan 3.0.0
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 (std::string_view type, std::string_view value)
 
void add_othername (const OID &oid, std::string_view value, ASN1_Type type)
 
 AlternativeName (std::string_view email_addr="", std::string_view uri="", std::string_view dns="", std::string_view 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 (std::string_view attr) const
 
const std::multimap< std::string, std::string, std::less<> > & get_attributes () const
 
std::string get_first_attribute (std::string_view attr) const
 
const std::multimap< OID, ASN1_String > & get_othernames () const
 
bool has_field (std::string_view attr) const
 
bool has_items () const
 

Detailed Description

Alternative Name

Definition at line 120 of file pkix_types.h.

Constructor & Destructor Documentation

◆ AlternativeName()

Botan::AlternativeName::AlternativeName ( std::string_view  email_addr = "",
std::string_view  uri = "",
std::string_view  dns = "",
std::string_view  ip_address = "" 
)

Definition at line 23 of file asn1_alt_name.cpp.

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

References add_attribute().

Member Function Documentation

◆ add_attribute()

void Botan::AlternativeName::add_attribute ( std::string_view  type,
std::string_view  value 
)

Definition at line 37 of file asn1_alt_name.cpp.

39 {
40 if(type.empty() || value.empty())
41 return;
42
43 auto range = m_alt_info.equal_range(type);
44 for(auto j = range.first; j != range.second; ++j)
45 if(j->second == value)
46 return;
47
48 m_alt_info.emplace(type, value);
49 }

Referenced by AlternativeName(), and decode_from().

◆ add_othername()

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

Definition at line 54 of file asn1_alt_name.cpp.

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

References Botan::multimap_insert().

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

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

References Botan::ASN1_Object::encode_into().

Referenced by Botan::PSS_Params::decode_from(), 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 65 of file asn1_alt_name.cpp.

66 {
67 std::multimap<std::string, std::string> names;
68
69 for(const auto& name : m_alt_info)
70 {
71 names.emplace(name.first, name.second);
72 }
73
74 for(const auto& othername : m_othernames)
75 {
76 multimap_insert(names,
77 othername.first.to_formatted_string(),
78 othername.second.value());
79 }
80
81 return names;
82 }
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 196 of file asn1_alt_name.cpp.

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

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 108 of file asn1_alt_name.cpp.

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

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 170 of file asn1_alt_name.cpp.

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

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 ( std::string_view  attr) const

Definition at line 99 of file asn1_alt_name.cpp.

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

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, std::less<> > & Botan::AlternativeName::get_attributes ( ) const
inline

Definition at line 136 of file pkix_types.h.

137 {
138 return m_alt_info;
139 }

◆ get_first_attribute()

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

Definition at line 90 of file asn1_alt_name.cpp.

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

◆ get_othernames()

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

Definition at line 141 of file pkix_types.h.

142 {
143 return m_othernames;
144 }

◆ has_field()

bool Botan::AlternativeName::has_field ( std::string_view  attr) const

Definition at line 84 of file asn1_alt_name.cpp.

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

◆ has_items()

bool Botan::AlternativeName::has_items ( ) const

Definition at line 125 of file asn1_alt_name.cpp.

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

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