Botan 3.13.0
Crypto and TLS for C&
Botan::AlternativeName Class Referencefinal

#include <pkix_types.h>

Inheritance diagram for Botan::AlternativeName:
Botan::ASN1_Object

Classes

class  OtherNameValue
 An "OtherName" GeneralName entry: type-id OID and the inner ANY value as raw BER. More...

Public Member Functions

void add_attribute (std::string_view type, std::string_view value)
void add_dn (const X509_DN &dn)
 Add a directory name to this AlternativeName.
void add_dns (DNSName dns)
 Add a previously parsed DNS name to this AlternativeName.
void add_dns (std::string_view dns)
 Add a DNS name to this AlternativeName, parsing and validating the input.
void add_email (EmailAddress addr)
 Add a previously parsed email address to this AlternativeName.
void add_email (std::string_view addr)
 Add an email address to this AlternativeName, parsing and validating the input.
void add_ipv4_address (const IPv4Address &ipv4)
 Add an IP address to this alternative name.
void add_ipv4_address (uint32_t ipv4)
 Add an IP address to this alternative name.
void add_ipv6_address (const IPv6Address &ipv6)
 Add an IPv6 address to this alternative name.
void add_other_name (const OID &oid, const ASN1_String &value)
 Add an "OtherName" identified by object identifier to this AlternativeName.
void add_other_name_value (const OID &oid, std::span< const uint8_t > value)
void add_othername (const OID &oid, std::string_view value, ASN1_Type type)
void add_registered_id (const OID &oid)
 Add a registeredID (RFC 5280 [8]).
void add_uri (std::string_view uri)
 Add a URI to this AlternativeName, parsing and validating the input.
void add_uri (URI uri)
 Add a previously parsed URI to this AlternativeName.
 AlternativeName ()=default
 Create an empty name.
BOTAN_FUTURE_EXPLICIT 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
size_t count () const
void decode_from (BER_Decoder &from) override
const std::set< X509_DN > & directory_names () const
 Return the set of directory names included in this alternative name.
X509_DN dn () const
std::set< std::string > dns () const
const std::set< DNSName > & dns_names () const
 Return the set of DNS names included in this alternative name.
std::set< std::string > email () const
const std::set< EmailAddress > & email_addresses () const
 Return the set of email addresses included in this alternative name.
void encode_into (DER_Encoder &to) const override
std::vector< std::string > get_attribute (std::string_view attr) const
std::multimap< std::string, std::string, std::less<> > get_attributes () const
std::string get_first_attribute (std::string_view attr) const
std::multimap< OID, ASN1_Stringget_othernames () const
bool has_field (std::string_view attr) const
bool has_items () const
 Return true if this has any names set.
std::set< uint32_t > ipv4_address () const
 Return the set of IPv4 addresses included in this alternative name.
const std::set< IPv4Address > & ipv4_addresses () const
 Return the set of IPv4 addresses included in this alternative name.
const std::set< IPv6Address > & ipv6_address () const
 Return the set of IPv6 addresses included in this alternative name.
const std::set< IPv6Address > & ipv6_addresses () const
 Return the set of IPv6 addresses included in this alternative name.
bool is_empty () const
 Return true if this alternative name is empty (zero names).
const std::set< OtherNameValue > & other_name_values () const
 Return all "OtherName" entries with their inner ANY value as raw BER.
const std::set< std::pair< OID, ASN1_String > > & other_names () const
 Return the set of "other names" whose value was a recognized ASN1_String type.
const std::set< OID > & registered_ids () const
 Return the set of registeredID OIDs.
const std::set< SmtpUtf8Mailbox > & smtp_utf8_mailboxes () const
const std::set< URI > & uri_names () const
 Return the set of URIs included in this alternative name.
std::set< std::string > uris () const

Detailed Description

Alternative Name

Definition at line 306 of file pkix_types.h.

Constructor & Destructor Documentation

◆ AlternativeName() [1/2]

Botan::AlternativeName::AlternativeName ( )
default

◆ AlternativeName() [2/2]

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

Definition at line 21 of file asn1_alt_name.cpp.

24 {
25 if(!email_addr.empty()) {
26 add_email(email_addr);
27 }
28 if(!dns.empty()) {
29 add_dns(dns);
30 }
31 if(!uri.empty()) {
32 add_uri(uri);
33 }
34 if(!ip.empty()) {
35 if(auto ipv4 = IPv4Address::from_string(ip)) {
36 add_ipv4_address(*ipv4);
37 } else {
38 throw Invalid_Argument(fmt("Invalid IPv4 address '{}'", ip));
39 }
40 }
41}
void add_dns(std::string_view dns)
Add a DNS name to this AlternativeName, parsing and validating the input.
Definition alt_name.cpp:63
std::set< std::string > dns() const
Definition alt_name.cpp:78
void add_ipv4_address(uint32_t ipv4)
Add an IP address to this alternative name.
Definition pkix_types.h:374
void add_email(std::string_view addr)
Add an email address to this AlternativeName, parsing and validating the input.
Definition alt_name.cpp:40
void add_uri(std::string_view uri)
Add a URI to this AlternativeName, parsing and validating the input.
Definition alt_name.cpp:17
static std::optional< IPv4Address > from_string(std::string_view str)
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References add_dns(), add_email(), add_ipv4_address(), add_uri(), dns(), Botan::fmt(), and Botan::IPv4Address::from_string().

Member Function Documentation

◆ add_attribute()

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

Definition at line 46 of file asn1_alt_name.cpp.

46 {
47 if(type.empty() || value.empty()) {
48 return;
49 }
50
51 if(type == "DNS") {
52 this->add_dns(value);
53 } else if(type == "RFC822") {
54 this->add_email(value);
55 } else if(type == "URI") {
56 this->add_uri(value);
57 } else if(type == "DN") {
58 if(auto dn = X509_DN::parse(value)) {
59 this->add_dn(*dn);
60 } else {
61 throw Invalid_Argument(fmt("Invalid X.509 DN '{}'", value));
62 }
63 } else if(type == "IP") {
64 if(auto ipv4 = IPv4Address::from_string(value)) {
65 add_ipv4_address(*ipv4);
66 } else {
67 throw Invalid_Argument(fmt("Invalid IPv4 address '{}'", value));
68 }
69 } else {
70 throw Not_Implemented(fmt("Unknown AlternativeName name type {}", type));
71 }
72}
void add_dn(const X509_DN &dn)
Add a directory name to this AlternativeName.
Definition alt_name.cpp:101
static std::optional< X509_DN > parse(std::string_view str)
Definition x509_dn.cpp:554

References add_dn(), add_dns(), add_email(), add_ipv4_address(), add_uri(), dn(), Botan::fmt(), Botan::IPv4Address::from_string(), and Botan::X509_DN::parse().

◆ add_dn()

void Botan::AlternativeName::add_dn ( const X509_DN & dn)

Add a directory name to this AlternativeName.

Definition at line 101 of file alt_name.cpp.

101 {
102 m_dn_names.insert(dn);
103}

References dn().

Referenced by add_attribute(), AlternativeName(), and decode_from().

◆ add_dns() [1/2]

void Botan::AlternativeName::add_dns ( DNSName dns)

Add a previously parsed DNS name to this AlternativeName.

Definition at line 74 of file alt_name.cpp.

74 {
75 m_dns.insert(std::move(dns));
76}

References dns().

◆ add_dns() [2/2]

void Botan::AlternativeName::add_dns ( std::string_view dns)

Add a DNS name to this AlternativeName, parsing and validating the input.

Definition at line 63 of file alt_name.cpp.

63 {
64 if(dns.empty()) {
65 return;
66 }
67 if(auto parsed = DNSName::from_san_string(dns)) {
68 add_dns(std::move(*parsed));
69 } else {
70 throw Decoding_Error("Invalid DNS name in SubjectAlternativeName");
71 }
72}
static std::optional< DNSName > from_san_string(std::string_view name)
Definition dns_name.cpp:149

References add_dns(), dns(), and Botan::DNSName::from_san_string().

Referenced by add_attribute(), add_dns(), AlternativeName(), AlternativeName(), and decode_from().

◆ add_email() [1/2]

void Botan::AlternativeName::add_email ( EmailAddress addr)

Add a previously parsed email address to this AlternativeName.

Definition at line 51 of file alt_name.cpp.

51 {
52 m_email.insert(std::move(addr));
53}

◆ add_email() [2/2]

void Botan::AlternativeName::add_email ( std::string_view addr)

Add an email address to this AlternativeName, parsing and validating the input.

Definition at line 40 of file alt_name.cpp.

40 {
41 if(addr.empty()) {
42 return;
43 }
44 if(auto parsed = EmailAddress::from_string(addr)) {
45 add_email(std::move(*parsed));
46 } else {
47 throw Decoding_Error("Invalid email address in SubjectAlternativeName");
48 }
49}
static std::optional< EmailAddress > from_string(std::string_view addr)
Definition email.cpp:78

References add_email(), and Botan::EmailAddress::from_string().

Referenced by add_attribute(), add_email(), AlternativeName(), AlternativeName(), and decode_from().

◆ add_ipv4_address() [1/2]

void Botan::AlternativeName::add_ipv4_address ( const IPv4Address & ipv4)

Add an IP address to this alternative name.

Definition at line 105 of file alt_name.cpp.

105 {
106 m_ipv4_addrs.insert(ip);
107}

◆ add_ipv4_address() [2/2]

void Botan::AlternativeName::add_ipv4_address ( uint32_t ipv4)
inline

Add an IP address to this alternative name.

Definition at line 374 of file pkix_types.h.

374 {
375 this->add_ipv4_address(IPv4Address(ipv4));
376 }

References add_ipv4_address().

Referenced by add_attribute(), add_ipv4_address(), AlternativeName(), and decode_from().

◆ add_ipv6_address()

void Botan::AlternativeName::add_ipv6_address ( const IPv6Address & ipv6)

Add an IPv6 address to this alternative name.

Definition at line 109 of file alt_name.cpp.

109 {
110 m_ipv6_addrs.insert(ip);
111}

Referenced by decode_from().

◆ add_other_name()

void Botan::AlternativeName::add_other_name ( const OID & oid,
const ASN1_String & value )

Add an "OtherName" identified by object identifier to this AlternativeName.

Definition at line 86 of file alt_name.cpp.

86 {
87 m_othernames.insert(std::make_pair(oid, value));
88 std::vector<uint8_t> raw;
89 DER_Encoder(raw).encode(value);
90 m_other_name_values.insert(OtherNameValue(oid, std::move(raw)));
91}
An "OtherName" GeneralName entry: type-id OID and the inner ANY value as raw BER.
Definition pkix_types.h:309

References Botan::DER_Encoder::encode().

Referenced by add_othername(), and AlternativeName().

◆ add_other_name_value()

void Botan::AlternativeName::add_other_name_value ( const OID & oid,
std::span< const uint8_t > value )

Add an "OtherName" with arbitrary inner value, given as raw BER bytes

value must be a complete BER-encoded object (tag + length + content) representing the inner ANY value of the OtherName.

Definition at line 93 of file alt_name.cpp.

93 {
94 m_other_name_values.insert(OtherNameValue(oid, value));
95}

Referenced by AlternativeName().

◆ add_othername()

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

Definition at line 77 of file asn1_alt_name.cpp.

77 {
78 if(value.empty()) {
79 return;
80 }
81 this->add_other_name(oid, ASN1_String(value, type));
82}
void add_other_name(const OID &oid, const ASN1_String &value)
Add an "OtherName" identified by object identifier to this AlternativeName.
Definition alt_name.cpp:86

References add_other_name().

◆ add_registered_id()

void Botan::AlternativeName::add_registered_id ( const OID & oid)

Add a registeredID (RFC 5280 [8]).

Definition at line 97 of file alt_name.cpp.

97 {
98 m_registered_ids.insert(oid);
99}

Referenced by AlternativeName(), and decode_from().

◆ add_uri() [1/2]

void Botan::AlternativeName::add_uri ( std::string_view uri)

Add a URI to this AlternativeName, parsing and validating the input.

Definition at line 17 of file alt_name.cpp.

17 {
18 if(uri.empty()) {
19 return;
20 }
21 if(auto parsed = URI::from_string(uri)) {
22 add_uri(std::move(*parsed));
23 } else {
24 throw Decoding_Error("Invalid URI in SubjectAlternativeName");
25 }
26}
static std::optional< URI > from_string(std::string_view raw)
Definition uri.cpp:164

References add_uri(), and Botan::URI::from_string().

Referenced by add_attribute(), add_uri(), AlternativeName(), AlternativeName(), and decode_from().

◆ add_uri() [2/2]

void Botan::AlternativeName::add_uri ( URI uri)

Add a previously parsed URI to this AlternativeName.

Definition at line 28 of file alt_name.cpp.

28 {
29 m_uri.insert(std::move(uri));
30}

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

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

References encode_into().

Referenced by decode_from(), Botan::PKCS12::export_to(), 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::PSS_Params::PSS_Params().

◆ contents()

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

Definition at line 87 of file asn1_alt_name.cpp.

87 {
88 std::multimap<std::string, std::string> names;
89
90 for(const auto& nm : this->dns()) {
91 names.emplace("DNS", nm);
92 }
93
94 for(const auto& nm : this->email()) {
95 names.emplace("RFC822", nm);
96 }
97
98 for(const auto& nm : this->uris()) {
99 names.emplace("URI", nm);
100 }
101
102 for(const auto& ipv4 : this->ipv4_addresses()) {
103 names.emplace("IP", ipv4.to_string());
104 }
105
106 for(const auto& ipv6 : this->ipv6_addresses()) {
107 names.emplace("IPv6", ipv6.to_string());
108 }
109
110 for(const auto& nm : this->directory_names()) {
111 names.emplace("DN", nm.to_string());
112 }
113
114 for(const auto& othername : this->other_names()) {
115 names.emplace(othername.first.to_formatted_string(), othername.second.value());
116 }
117
118 return names;
119}
const std::set< IPv6Address > & ipv6_addresses() const
Return the set of IPv6 addresses included in this alternative name.
Definition pkix_types.h:423
const std::set< X509_DN > & directory_names() const
Return the set of directory names included in this alternative name.
Definition pkix_types.h:443
const std::set< std::pair< OID, ASN1_String > > & other_names() const
Return the set of "other names" whose value was a recognized ASN1_String type.
Definition pkix_types.h:427
std::set< std::string > uris() const
Definition alt_name.cpp:32
std::set< std::string > email() const
Definition alt_name.cpp:55
const std::set< IPv4Address > & ipv4_addresses() const
Return the set of IPv4 addresses included in this alternative name.
Definition pkix_types.h:420

References directory_names(), dns(), email(), ipv4_addresses(), ipv6_addresses(), other_names(), and uris().

Referenced by get_attributes().

◆ count()

size_t Botan::AlternativeName::count ( ) const

Return the total number of names in this AlternativeName

This only counts names which were parsed, ignoring names which were of some unknown type

Definition at line 113 of file alt_name.cpp.

113 {
114 const auto sum = checked_add(m_dns.size(),
115 m_uri.size(),
116 m_email.size(),
117 m_ipv4_addrs.size(),
118 m_ipv6_addrs.size(),
119 m_dn_names.size(),
120 m_other_name_values.size(),
121 m_registered_ids.size());
122
123 BOTAN_ASSERT_NOMSG(sum.has_value());
124 return sum.value();
125}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
constexpr std::optional< T > checked_add(T a, T b)
Definition int_utils.h:19

References BOTAN_ASSERT_NOMSG, and Botan::checked_add().

Referenced by has_items(), and is_empty().

◆ 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 198 of file alt_name.cpp.

198 {
199 BER_Decoder names = source.start_sequence();
200
201 while(names.more_items()) {
202 const BER_Object obj = names.get_next_object();
203
204 if(obj.is_a(0, ASN1_Class::ExplicitContextSpecific)) {
205 BER_Decoder othername(obj, names.limits());
206
207 OID oid;
208 othername.decode(oid);
209 const BER_Object othername_value_outer = othername.get_next_object();
210 othername.verify_end();
211
212 if(!othername_value_outer.is_a(0, ASN1_Class::ExplicitContextSpecific)) {
213 throw Decoding_Error("Invalid tags on otherName value");
214 }
215
216 BER_Decoder othername_value_inner(othername_value_outer, names.limits());
217
218 const BER_Object value = othername_value_inner.get_next_object();
219 othername_value_inner.verify_end();
220
221 // Capture the inner ANY value verbatim so applications can retrieve
222 // it regardless of its ASN.1 form.
223 std::vector<uint8_t> raw_value;
224 DER_Encoder(raw_value).add_object(value.type_tag(), value.class_tag(), value.data());
225 m_other_name_values.insert(OtherNameValue{oid, std::move(raw_value)});
226
227 // Populate old string view for compatibility
228 if(ASN1_String::is_string_type(value.type()) && value.get_class() == ASN1_Class::Universal) {
229 try {
230 m_othernames.insert(std::make_pair(oid, ASN1_String(ASN1::to_string(value), value.type())));
231 } catch(const Invalid_Argument&) { // NOLINT(*-empty-catch)
232 }
233 }
234
235 if(oid == OID::from_string("PKIX.SmtpUTF8Mailbox")) {
237 throw Decoding_Error("SmtpUTF8Mailbox otherName must contain a UTF8String");
238 }
239 auto parsed_mailbox = SmtpUtf8Mailbox::from_string(ASN1::to_string(value));
240 if(!parsed_mailbox.has_value()) {
241 throw Decoding_Error("Invalid SmtpUTF8Mailbox encoding");
242 }
243 m_smtp_utf8_mailboxes.insert(std::move(*parsed_mailbox));
244 }
245 } else if(obj.is_a(1, ASN1_Class::ContextSpecific)) {
247 } else if(obj.is_a(2, ASN1_Class::ContextSpecific)) {
249 } else if(obj.is_a(3, ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
250 // x400Address not supported but it is a SEQUENCE so we know it cannot be empty
251 if(obj.length() == 0) {
252 throw Decoding_Error("Invalid x400Address field");
253 }
254 } else if(obj.is_a(4, ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
255 BER_Decoder dec(obj, names.limits());
256 X509_DN dn;
257 dec.decode(dn).verify_end();
258 this->add_dn(dn);
259 } else if(obj.is_a(5, ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
260 // ediPartyName not supported but it is a SEQUENCE so we know it cannot be empty
261 if(obj.length() == 0) {
262 throw Decoding_Error("Invalid ediPartyName field");
263 }
264 } else if(obj.is_a(6, ASN1_Class::ContextSpecific)) {
265 this->add_uri(ASN1::to_string(obj));
266 } else if(obj.is_a(7, ASN1_Class::ContextSpecific)) {
267 if(obj.length() == 4) {
268 const uint32_t ip = load_be<uint32_t>(obj.bits(), 0);
269 this->add_ipv4_address(ip);
270 } else if(obj.length() == 16) {
271 const IPv6Address ip(std::span<const uint8_t, 16>{obj.bits(), 16});
272 this->add_ipv6_address(ip);
273 } else {
274 throw Decoding_Error("Invalid IP constraint neither IPv4 or IPv6");
275 }
276 } else if(obj.is_a(8, ASN1_Class::ContextSpecific)) {
277 // [8] registeredID is IMPLICIT OBJECT IDENTIFIER.
278 OID oid;
279 names.decode_implicit(obj, oid, ASN1_Type::ObjectId, ASN1_Class::Universal);
280 this->add_registered_id(oid);
281 } else {
282 throw Decoding_Error(fmt("Unknown GeneralName tag {}/class {}",
283 static_cast<uint32_t>(obj.type_tag()),
284 static_cast<uint32_t>(obj.class_tag())));
285 }
286 }
287}
static bool is_string_type(ASN1_Type tag)
Definition asn1_str.cpp:131
void add_registered_id(const OID &oid)
Add a registeredID (RFC 5280 [8]).
Definition alt_name.cpp:97
void add_ipv6_address(const IPv6Address &ipv6)
Add an IPv6 address to this alternative name.
Definition alt_name.cpp:109
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
static std::optional< SmtpUtf8Mailbox > from_string(std::string_view addr)
Definition email.cpp:99
std::string to_string(const BER_Object &obj)
Definition asn1_obj.cpp:224
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504

References add_dn(), add_dns(), add_email(), add_ipv4_address(), add_ipv6_address(), Botan::DER_Encoder::add_object(), add_registered_id(), add_uri(), Botan::BER_Object::bits(), Botan::BER_Object::class_tag(), Botan::Constructed, Botan::ContextSpecific, Botan::BER_Object::data(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_implicit(), dn(), Botan::ExplicitContextSpecific, Botan::fmt(), Botan::OID::from_string(), Botan::SmtpUtf8Mailbox::from_string(), Botan::BER_Object::get_class(), Botan::BER_Decoder::get_next_object(), Botan::BER_Object::is_a(), Botan::ASN1_String::is_string_type(), Botan::BER_Object::length(), Botan::BER_Decoder::limits(), Botan::load_be(), Botan::BER_Decoder::more_items(), Botan::ObjectId, Botan::BER_Decoder::start_sequence(), Botan::ASN1::to_string(), Botan::BER_Object::type(), Botan::BER_Object::type_tag(), Botan::Universal, Botan::Utf8String, and Botan::BER_Decoder::verify_end().

◆ directory_names()

const std::set< X509_DN > & Botan::AlternativeName::directory_names ( ) const
inline

Return the set of directory names included in this alternative name.

Definition at line 443 of file pkix_types.h.

443{ return m_dn_names; }

Referenced by contents(), dn(), get_attribute(), and Botan::GeneralName::matches().

◆ dn()

X509_DN Botan::AlternativeName::dn ( ) const

This returns all of the alternative name DNs combined into a single DN

This result is not a valid DN. The logic is retained for compatibility, but this function should not be used. It will be removed in Botan4.

Definition at line 173 of file asn1_alt_name.cpp.

173 {
174 // This logic really does not make any sense, but it is
175 // how this function was historically implemented.
176
177 X509_DN combined_dn;
178
179 for(const auto& dn : this->directory_names()) {
180 for(const auto& rdn : dn.rdns()) {
181 combined_dn.add_rdn(rdn);
182 }
183 }
184
185 return combined_dn;
186}

References Botan::X509_DN::add_rdn(), directory_names(), and dn().

Referenced by add_attribute(), add_dn(), AlternativeName(), decode_from(), dn(), and get_othernames().

◆ dns()

std::set< std::string > Botan::AlternativeName::dns ( ) const

Return the set of DNS names included in this alternative name

Deprecated: use dns_names() instead, which exposes the parsed DNSName values. This accessor constructs a copy.

Definition at line 78 of file alt_name.cpp.

78 {
79 std::set<std::string> out;
80 for(const auto& name : m_dns) {
81 out.insert(name.to_string());
82 }
83 return out;
84}

Referenced by add_dns(), add_dns(), AlternativeName(), AlternativeName(), contents(), get_attribute(), and get_othernames().

◆ dns_names()

const std::set< DNSName > & Botan::AlternativeName::dns_names ( ) const
inline

Return the set of DNS names included in this alternative name.

Definition at line 409 of file pkix_types.h.

409{ return m_dns; }

References dns_names().

Referenced by dns_names(), Botan::GeneralName::matches(), and Botan::X509_Certificate::matches_dns_name().

◆ email()

std::set< std::string > Botan::AlternativeName::email ( ) const

Return the set of email addresses included in this alternative name

Deprecated: use email_addresses() instead, which exposes the parsed EmailAddress values. This accessor constructs a copy.

Definition at line 55 of file alt_name.cpp.

55 {
56 std::set<std::string> out;
57 for(const auto& addr : m_email) {
58 out.insert(addr.to_string());
59 }
60 return out;
61}

Referenced by contents(), and get_attribute().

◆ email_addresses()

const std::set< EmailAddress > & Botan::AlternativeName::email_addresses ( ) const
inline

Return the set of email addresses included in this alternative name.

Definition at line 400 of file pkix_types.h.

400{ return m_email; }

References email_addresses().

Referenced by email_addresses(), Botan::GeneralName::matches(), and Botan::X509_Certificate::subject_email_addresses().

◆ 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 135 of file alt_name.cpp.

135 {
136 der.start_sequence();
137
138 /*
139 GeneralName ::= CHOICE {
140 otherName [0] OtherName,
141 rfc822Name [1] IA5String,
142 dNSName [2] IA5String,
143 x400Address [3] ORAddress,
144 directoryName [4] Name,
145 ediPartyName [5] EDIPartyName,
146 uniformResourceIdentifier [6] IA5String,
147 iPAddress [7] OCTET STRING,
148 registeredID [8] OBJECT IDENTIFIER }
149 */
150
151 for(const auto& othername : m_other_name_values) {
152 der.start_explicit(0)
153 .encode(othername.oid())
154 .start_explicit(0)
155 .raw_bytes(othername.value())
156 .end_explicit()
157 .end_explicit();
158 }
159
160 for(const auto& addr : m_email) {
161 const ASN1_String str(addr.to_string(), ASN1_Type::Ia5String);
162 der.add_object(ASN1_Type(1), ASN1_Class::ContextSpecific, str.value());
163 }
164
165 for(const auto& name : m_dns) {
166 const ASN1_String str(name.to_string(), ASN1_Type::Ia5String);
167 der.add_object(ASN1_Type(2), ASN1_Class::ContextSpecific, str.value());
168 }
169
170 for(const auto& name : m_dn_names) {
171 der.add_object(ASN1_Type(4), ASN1_Class::ExplicitContextSpecific, name.DER_encode());
172 }
173
174 for(const auto& name : m_uri) {
175 const ASN1_String str(name.original_input(), ASN1_Type::Ia5String);
176 der.add_object(ASN1_Type(6), ASN1_Class::ContextSpecific, str.value());
177 }
178
179 for(const auto& ip : m_ipv4_addrs) {
180 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
181 der.add_object(ASN1_Type(7), ASN1_Class::ContextSpecific, ip.to_bytes());
182 }
183
184 for(const auto& ip : m_ipv6_addrs) {
185 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
186 der.add_object(ASN1_Type(7), ASN1_Class::ContextSpecific, ip.address().data(), ip.address().size());
187 }
188
189 for(const auto& reg_id : m_registered_ids) {
190 // [8] registeredID is IMPLICIT OBJECT IDENTIFIER.
191 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
192 der.encode_implicit(reg_id, ASN1_Type(8), ASN1_Class::ContextSpecific);
193 }
194
195 der.end_cons();
196}
ASN1_Type
Definition asn1_obj.h:47

References Botan::DER_Encoder::add_object(), Botan::ContextSpecific, Botan::DER_Encoder::encode(), Botan::DER_Encoder::encode_implicit(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::end_explicit(), Botan::ExplicitContextSpecific, Botan::Ia5String, Botan::DER_Encoder::raw_bytes(), Botan::DER_Encoder::start_explicit(), Botan::DER_Encoder::start_sequence(), and Botan::ASN1_String::value().

◆ get_attribute()

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

Definition at line 145 of file asn1_alt_name.cpp.

145 {
146 auto set_to_vector = [](const std::set<std::string>& s) -> std::vector<std::string> { return {s.begin(), s.end()}; };
147
148 if(attr == "DNS") {
149 return set_to_vector(this->dns());
150 } else if(attr == "RFC822") {
151 return set_to_vector(this->email());
152 } else if(attr == "URI") {
153 return set_to_vector(this->uris());
154 } else if(attr == "DN") {
155 std::vector<std::string> ret;
156
157 for(const auto& nm : this->directory_names()) {
158 ret.push_back(nm.to_string());
159 }
160
161 return ret;
162 } else if(attr == "IP") {
163 std::vector<std::string> ip_str;
164 for(const auto& ipv4 : this->ipv4_addresses()) {
165 ip_str.push_back(ipv4.to_string());
166 }
167 return ip_str;
168 } else {
169 return {};
170 }
171}

References directory_names(), dns(), email(), ipv4_addresses(), and uris().

Referenced by get_first_attribute(), and has_field().

◆ get_attributes()

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

Definition at line 121 of file asn1_alt_name.cpp.

121 {
122 std::multimap<std::string, std::string, std::less<>> r;
123
124 for(const auto& c : this->contents()) {
125 r.emplace(c.first, c.second);
126 }
127
128 return r;
129}
std::multimap< std::string, std::string > contents() const

References contents().

◆ get_first_attribute()

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

Definition at line 135 of file asn1_alt_name.cpp.

135 {
136 auto attr = this->get_attribute(type);
137
138 if(!attr.empty()) {
139 return attr[0];
140 }
141
142 return "";
143}
std::vector< std::string > get_attribute(std::string_view attr) const

References get_attribute().

◆ get_othernames()

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

◆ has_field()

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

Definition at line 131 of file asn1_alt_name.cpp.

131 {
132 return !this->get_attribute(attr).empty();
133}

References get_attribute().

◆ has_items()

bool Botan::AlternativeName::has_items ( ) const

Return true if this has any names set.

Definition at line 127 of file alt_name.cpp.

127 {
128 return this->count() > 0;
129}
size_t count() const
Definition alt_name.cpp:113

References count().

◆ ipv4_address()

std::set< uint32_t > Botan::AlternativeName::ipv4_address ( ) const

Return the set of IPv4 addresses included in this alternative name.

Definition at line 188 of file asn1_alt_name.cpp.

188 {
189 std::set<uint32_t> out;
190 for(const auto& a : m_ipv4_addrs) {
191 out.insert(a.address());
192 }
193 return out;
194}

◆ ipv4_addresses()

const std::set< IPv4Address > & Botan::AlternativeName::ipv4_addresses ( ) const
inline

Return the set of IPv4 addresses included in this alternative name.

Definition at line 420 of file pkix_types.h.

420{ return m_ipv4_addrs; }

Referenced by contents(), get_attribute(), Botan::GeneralName::matches(), and Botan::X509_Certificate::matches_ip().

◆ ipv6_address()

const std::set< IPv6Address > & Botan::AlternativeName::ipv6_address ( ) const
inline

Return the set of IPv6 addresses included in this alternative name.

Definition at line 415 of file pkix_types.h.

415 {
416 return ipv6_addresses();
417 }

References BOTAN_DEPRECATED, ipv6_address(), and ipv6_addresses().

Referenced by ipv6_address().

◆ ipv6_addresses()

const std::set< IPv6Address > & Botan::AlternativeName::ipv6_addresses ( ) const
inline

Return the set of IPv6 addresses included in this alternative name.

Definition at line 423 of file pkix_types.h.

423{ return m_ipv6_addrs; }

Referenced by contents(), ipv6_address(), Botan::GeneralName::matches(), and Botan::X509_Certificate::matches_ip().

◆ is_empty()

bool Botan::AlternativeName::is_empty ( ) const

Return true if this alternative name is empty (zero names).

Definition at line 131 of file alt_name.cpp.

131 {
132 return this->count() == 0;
133}

References count().

Referenced by Botan::GeneralName::matches().

◆ other_name_values()

const std::set< OtherNameValue > & Botan::AlternativeName::other_name_values ( ) const
inline

Return all "OtherName" entries with their inner ANY value as raw BER.

Definition at line 432 of file pkix_types.h.

432{ return m_other_name_values; }

◆ other_names()

const std::set< std::pair< OID, ASN1_String > > & Botan::AlternativeName::other_names ( ) const
inline

Return the set of "other names" whose value was a recognized ASN1_String type.

Definition at line 427 of file pkix_types.h.

427 {
428 return m_othernames;
429 }

References other_names().

Referenced by contents(), and other_names().

◆ registered_ids()

const std::set< OID > & Botan::AlternativeName::registered_ids ( ) const
inline

Return the set of registeredID OIDs.

Definition at line 440 of file pkix_types.h.

440{ return m_registered_ids; }

◆ smtp_utf8_mailboxes()

const std::set< SmtpUtf8Mailbox > & Botan::AlternativeName::smtp_utf8_mailboxes ( ) const
inline

Return the set of SmtpUTF8Mailbox SAN entries (RFC 9598).

Any such values are also included with their raw encoding in other_name_values

Definition at line 437 of file pkix_types.h.

437{ return m_smtp_utf8_mailboxes; }

◆ uri_names()

const std::set< URI > & Botan::AlternativeName::uri_names ( ) const
inline

Return the set of URIs included in this alternative name.

Definition at line 391 of file pkix_types.h.

391{ return m_uri; }

References uri_names().

Referenced by Botan::GeneralName::matches(), and uri_names().

◆ uris()

std::set< std::string > Botan::AlternativeName::uris ( ) const

Return the set of URIs included in this alternative name

Deprecated: use uri_names() instead, which exposes the parsed URI values. This accessor constructs a copy.

Definition at line 32 of file alt_name.cpp.

32 {
33 std::set<std::string> out;
34 for(const auto& uri : m_uri) {
35 out.insert(uri.original_input());
36 }
37 return out;
38}

Referenced by contents(), and get_attribute().


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