Botan 2.1.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 &, const std::string &)
void | add_othername (const OID &, const std::string &, ASN1_Tag)
| AlternativeName (const std::string &="", const std::string &="", const std::string &="", const std::string &="")
std::multimap< std::string, std::string > | contents () const
void | decode_from (class BER_Decoder &) override
void | encode_into (class DER_Encoder &) const override
std::multimap< std::string, std::string > | get_attributes () const
std::multimap< OID, ASN1_String > | get_othernames () const
bool | has_items () const

## Detailed Description

Alternative Name

Definition at line 22 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 = `""`
| ) |  |

Definition at line 41 of file asn1_alt_name.cpp.

References add_attribute().

45 {
46 add_attribute("RFC822", email_addr);
47 add_attribute("DNS", dns);
48 add_attribute("URI", uri);
49 add_attribute("IP", ip);
50 }
Botan::AlternativeName::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: asn1_alt_name.cpp:55

## Member Function Documentation

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

Definition at line 55 of file asn1_alt_name.cpp.

References Botan::multimap_insert().

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

57 {
58 if(type.empty() || str.empty())
59 return;
60
61 auto range = m_alt_info.equal_range(type);
62 for(auto j = range.first; j != range.second; ++j)
63 if(j->second == str)
64 return;
65
66 multimap_insert(m_alt_info, type, str);
67 }
type
MechanismType type
Definition: p11_mechanism.cpp:43
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 72 of file asn1_alt_name.cpp.

References Botan::multimap_insert().

Referenced by decode_from().

74 {
75 if(value.empty())
76 return;
77 multimap_insert(m_othernames, oid, ASN1_String(value, type));
78 }
type
MechanismType type
Definition: p11_mechanism.cpp:43
Botan::multimap_insert
void multimap_insert(std::multimap< K, V > &multimap, const K &key, const V &value)
Definition: stl_util.h:76

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

Definition at line 99 of file asn1_alt_name.cpp.

References Botan::OIDS::lookup(), and Botan::multimap_insert().

100 {
101 std::multimap<std::string, std::string> names;
102
103 for(auto i = m_alt_info.begin(); i != m_alt_info.end(); ++i)
104 multimap_insert(names, i->first, i->second);
105
106 for(auto i = m_othernames.begin(); i != m_othernames.end(); ++i)
107 multimap_insert(names, OIDS::lookup(i->first), i->second.value());
108
109 return names;
110 }
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18
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 178 of file asn1_alt_name.cpp.

References add_attribute(), add_othername(), Botan::BER_Object::class_tag, Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::BER_Decoder::decode(), Botan::BER_Decoder::get_next_object(), Botan::ipv4_to_string(), Botan::LATIN1_CHARSET, Botan::load_be< uint32_t >(), Botan::LOCAL_CHARSET, Botan::BER_Decoder::more_items(), Botan::SEQUENCE, Botan::BER_Decoder::start_cons(), Botan::ASN1::to_string(), Botan::Charset::transcode(), Botan::BER_Object::type_tag, Botan::UNIVERSAL, Botan::BER_Object::value, and Botan::BER_Decoder::verify_end().

179 {
180 BER_Decoder names = source.start_cons(SEQUENCE);
181
182 while(names.more_items())
183 {
184 BER_Object obj = names.get_next_object();
185 if((obj.class_tag != CONTEXT_SPECIFIC) &&
186 (obj.class_tag != (CONTEXT_SPECIFIC | CONSTRUCTED)))
187 continue;
188
189 const ASN1_Tag tag = obj.type_tag;
190
191 if(tag == 0)
192 {
193 BER_Decoder othername(obj.value);
194
195 OID oid;
196 othername.decode(oid);
197 if(othername.more_items())
198 {
199 BER_Object othername_value_outer = othername.get_next_object();
200 othername.verify_end();
201
202 if(othername_value_outer.type_tag != ASN1_Tag(0) ||
203 othername_value_outer.class_tag !=
204 (CONTEXT_SPECIFIC | CONSTRUCTED)
205 )
206 throw Decoding_Error("Invalid tags on otherName value");
207
208 BER_Decoder othername_value_inner(othername_value_outer.value);
209
210 BER_Object value = othername_value_inner.get_next_object();
211 othername_value_inner.verify_end();
212
213 const ASN1_Tag value_type = value.type_tag;
214
215 if(is_string_type(value_type) && value.class_tag == UNIVERSAL)
216 add_othername(oid, ASN1::to_string(value), value_type);
217 }
218 }
219 else if(tag == 1 || tag == 2 || tag == 6)
220 {
221 const std::string value = Charset::transcode(ASN1::to_string(obj),
222 LATIN1_CHARSET,
223 LOCAL_CHARSET);
224
225 if(tag == 1) add_attribute("RFC822", value);
226 if(tag == 2) add_attribute("DNS", value);
227 if(tag == 6) add_attribute("URI", value);
228 }
229 else if(tag == 7)
230 {
231 if(obj.value.size() == 4)
232 {
233 const uint32_t ip = load_be<uint32_t>(&obj.value[0], 0);
234 add_attribute("IP", ipv4_to_string(ip));
235 }
236 }
237
238 }
239 }
Botan::AlternativeName::add_attribute
void add_attribute(const std::string &, const std::string &)
Definition: asn1_alt_name.cpp:55
Botan::CONTEXT_SPECIFIC
Definition: asn1_obj.h:25
Botan::load_be< uint32_t >
uint32_t load_be< uint32_t >(const uint8_t in[], size_t off)
Definition: loadstor.h:185
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
Botan::ipv4_to_string
std::string ipv4_to_string(uint32_t ip)
Definition: parsing.cpp:288
Botan::UNIVERSAL
Definition: asn1_obj.h:23
Botan::CONSTRUCTED
Definition: asn1_obj.h:27
Botan::Charset::transcode
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:22
Botan::LATIN1_CHARSET
Definition: charset.h:23
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan::AlternativeName::add_othername
void add_othername(const OID &, const std::string &, ASN1_Tag)
Definition: asn1_alt_name.cpp:72
Botan::LOCAL_CHARSET
Definition: charset.h:20

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

154 {
155 der.start_cons(SEQUENCE);
156
157 encode_entries(der, m_alt_info, "RFC822", ASN1_Tag(1));
158 encode_entries(der, m_alt_info, "DNS", ASN1_Tag(2));
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 }
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:22
Botan::SEQUENCE
Definition: asn1_obj.h:39

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

Definition at line 83 of file asn1_alt_name.cpp.

84 {
85 return m_alt_info;
86 }

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

Definition at line 91 of file asn1_alt_name.cpp.

92 {
93 return m_othernames;
94 }

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

Definition at line 115 of file asn1_alt_name.cpp.

116 {
117 return (m_alt_info.size() > 0 || m_othernames.size() > 0);
118 }

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

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