Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::AlternativeName Class Referencefinal

`#include <asn1_alt_name.h>`

Inheritance diagram for Botan::AlternativeName:

## 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

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 }
Botan::AlternativeName::add_attribute
void add_attribute(const std::string &type, const std::string &value)
Definition: asn1_alt_name.cpp:39

## Member Function Documentation

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 }
type
MechanismType type
Definition: p11_mechanism.cpp:44
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

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 }
type
MechanismType type
Definition: p11_mechanism.cpp:44
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

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 }
Botan::ASN1_Object::encode_into
virtual void encode_into(DER_Encoder &to) const =0

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

Definition at line 67 of file asn1_alt_name.cpp.

References 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 {
73 multimap_insert(names, i->first, i->second);
74 }
75
76 for(auto i = m_othernames.begin(); i != m_othernames.end(); ++i)
77 {
78 multimap_insert(names, i->first.to_formatted_string(), i->second.value());
79 }
80
81 return names;
82 }
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

void Botan::AlternativeName::decode_from | ( | class BER_Decoder & | from | ) |
| override virtual

Decode whatever this object is from from

Parameters

  from | the BER_Decoder that will be read from

Implements Botan::ASN1_Object.

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

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

void Botan::AlternativeName::encode_into | ( | class DER_Encoder & | to | ) | const
| override virtual

Encode whatever this object is into to

Parameters

  to | the DER_Encoder that will be written to

Implements Botan::ASN1_Object.

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

157 {
158 der.start_cons(SEQUENCE);
159
160 encode_entries(der, m_alt_info, "RFC822", ASN1_Tag(1));
161 encode_entries(der, m_alt_info, "DNS", ASN1_Tag(2));
162 encode_entries(der, m_alt_info, "DN", ASN1_Tag(4));
163 encode_entries(der, m_alt_info, "URI", ASN1_Tag(6));
164 encode_entries(der, m_alt_info, "IP", ASN1_Tag(7));
165
166 for(auto i = m_othernames.begin(); i != m_othernames.end(); ++i)
167 {
168 der.start_explicit(0)
169 .encode(i->first)
170 .start_explicit(0)
171 .encode(i->second)
172 .end_explicit()
173 .end_explicit();
174 }
175
176 der.end_cons();
177 }
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:23
Botan::SEQUENCE
Definition: asn1_obj.h:40

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

Definition at line 99 of file asn1_alt_name.cpp.

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

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 }

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 }

std::string Botan::AlternativeName::get_first_attribute | ( | const std::string & | 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 }

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 }

bool Botan::AlternativeName::has_field | ( | const std::string & | 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 }

bool Botan::AlternativeName::has_items | ( |  | ) | const

Definition at line 111 of file asn1_alt_name.cpp.

112 {
113 return (m_alt_info.size() > 0 || m_othernames.size() > 0);
114 }

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

- src/lib/x509/asn1_alt_name.h
- src/lib/x509/asn1_alt_name.cpp