Botan 2.19.1
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_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 (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 123 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:76
MechanismType type

References Botan::multimap_insert(), and type.

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

◆ add_othername()

void Botan::AlternativeName::add_othername ( const OID oid,
const std::string &  value,
ASN1_Tag  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(auto i = m_alt_info.begin(); i != m_alt_info.end(); ++i)
71 {
72 multimap_insert(names, i->first, i->second);
73 }
74
75 for(auto i = m_othernames.begin(); i != m_othernames.end(); ++i)
76 {
77 multimap_insert(names, i->first.to_formatted_string(), i->second.value());
78 }
79
80 return names;
81 }

References Botan::multimap_insert().

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

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

References add_attribute(), add_othername(), Botan::BER_Object::bits(), Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::BER_Decoder::decode(), dn(), 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().

◆ dn()

X509_DN Botan::AlternativeName::dn ( ) const

Definition at line 107 of file asn1_alt_name.cpp.

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

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

170 {
171 der.start_cons(SEQUENCE);
172
173 encode_entries(der, m_alt_info, "RFC822", ASN1_Tag(1));
174 encode_entries(der, m_alt_info, "DNS", ASN1_Tag(2));
175 encode_entries(der, m_alt_info, "DN", ASN1_Tag(4));
176 encode_entries(der, m_alt_info, "URI", ASN1_Tag(6));
177 encode_entries(der, m_alt_info, "IP", ASN1_Tag(7));
178
179 for(auto i = m_othernames.begin(); i != m_othernames.end(); ++i)
180 {
181 der.start_explicit(0)
182 .encode(i->first)
183 .start_explicit(0)
184 .encode(i->second)
185 .end_explicit()
186 .end_explicit();
187 }
188
189 der.end_cons();
190 }

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

◆ get_attribute()

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

Definition at line 98 of file asn1_alt_name.cpp.

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

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 139 of file pkix_types.h.

140 {
141 return m_alt_info;
142 }

◆ get_first_attribute()

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

Definition at line 89 of file asn1_alt_name.cpp.

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

◆ get_othernames()

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

Definition at line 144 of file pkix_types.h.

145 {
146 return m_othernames;
147 }

◆ has_field()

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

Definition at line 83 of file asn1_alt_name.cpp.

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

◆ has_items()

bool Botan::AlternativeName::has_items ( ) const

Definition at line 124 of file asn1_alt_name.cpp.

125 {
126 return (m_alt_info.size() > 0 || m_othernames.size() > 0);
127 }

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