Botan 3.3.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 116 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 24 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.

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

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

55 {
56 if(value.empty()) {
57 return;
58 }
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:109

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

19 {
20 std::vector<uint8_t> output;
21 DER_Encoder der(output);
22 this->encode_into(der);
23 return output;
24}
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.

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

179 {
180 BER_Decoder names = source.start_sequence();
181
182 // FIXME this is largely a duplication of GeneralName::decode_from
183
184 while(names.more_items()) {
185 BER_Object obj = names.get_next_object();
186
187 if(obj.is_a(0, ASN1_Class::ContextSpecific)) {
188 BER_Decoder othername(obj);
189
190 OID oid;
191 othername.decode(oid);
192 if(othername.more_items()) {
193 BER_Object othername_value_outer = othername.get_next_object();
194 othername.verify_end();
195
196 if(othername_value_outer.is_a(0, ASN1_Class::ExplicitContextSpecific) == false) {
197 throw Decoding_Error("Invalid tags on otherName value");
198 }
199
200 BER_Decoder othername_value_inner(othername_value_outer);
201
202 BER_Object value = othername_value_inner.get_next_object();
203 othername_value_inner.verify_end();
204
205 if(ASN1_String::is_string_type(value.type()) && value.get_class() == ASN1_Class::Universal) {
206 add_othername(oid, ASN1::to_string(value), value.type());
207 }
208 }
209 }
210 if(obj.is_a(1, ASN1_Class::ContextSpecific)) {
211 add_attribute("RFC822", ASN1::to_string(obj));
212 } else if(obj.is_a(2, ASN1_Class::ContextSpecific)) {
213 add_attribute("DNS", ASN1::to_string(obj));
214 } else if(obj.is_a(6, ASN1_Class::ContextSpecific)) {
215 add_attribute("URI", ASN1::to_string(obj));
216 } else if(obj.is_a(4, ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
217 BER_Decoder dec(obj);
218 X509_DN dn;
219 std::stringstream ss;
220
221 dec.decode(dn);
222 ss << dn;
223
224 add_attribute("DN", ss.str());
225 } else if(obj.is_a(7, ASN1_Class::ContextSpecific)) {
226 if(obj.length() == 4) {
227 const uint32_t ip = load_be<uint32_t>(obj.bits(), 0);
228 add_attribute("IP", ipv4_to_string(ip));
229 }
230 }
231 }
232}
static bool is_string_type(ASN1_Type tag)
Definition asn1_str.cpp:60
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:185
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::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 102 of file asn1_alt_name.cpp.

102 {
103 X509_DN dn;
104 auto range = m_alt_info.equal_range("DN");
105
106 for(auto i = range.first; i != range.second; ++i) {
107 std::istringstream strm(i->second);
108 strm >> dn;
109 }
110
111 return dn;
112}

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

155 {
156 der.start_sequence();
157
158 encode_entries(der, m_alt_info, "RFC822", ASN1_Type(1));
159 encode_entries(der, m_alt_info, "DNS", ASN1_Type(2));
160 encode_entries(der, m_alt_info, "DN", ASN1_Type(4));
161 encode_entries(der, m_alt_info, "URI", ASN1_Type(6));
162 encode_entries(der, m_alt_info, "IP", ASN1_Type(7));
163
164 for(const auto& othername : m_othernames) {
165 der.start_explicit(0)
166 .encode(othername.first)
167 .start_explicit(0)
168 .encode(othername.second)
169 .end_explicit()
170 .end_explicit();
171 }
172
173 der.end_cons();
174}
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 93 of file asn1_alt_name.cpp.

93 {
94 std::vector<std::string> results;
95 auto range = m_alt_info.equal_range(attr);
96 for(auto i = range.first; i != range.second; ++i) {
97 results.push_back(i->second);
98 }
99 return results;
100}

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

131{ return m_alt_info; }

Referenced by Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point::encode_into().

◆ get_first_attribute()

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

Definition at line 84 of file asn1_alt_name.cpp.

84 {
85 auto i = m_alt_info.lower_bound(attr);
86 if(i != m_alt_info.end() && i->first == attr) {
87 return i->second;
88 }
89
90 return "";
91}

◆ get_othernames()

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

Definition at line 133 of file pkix_types.h.

133{ return m_othernames; }

◆ has_field()

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

Definition at line 79 of file asn1_alt_name.cpp.

79 {
80 auto range = m_alt_info.equal_range(attr);
81 return (range.first != range.second);
82}

◆ has_items()

bool Botan::AlternativeName::has_items ( ) const

Definition at line 117 of file asn1_alt_name.cpp.

117 {
118 return (!m_alt_info.empty() || !m_othernames.empty());
119}

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