9#include <botan/pkix_types.h>
11#include <botan/internal/fmt.h>
12#include <botan/internal/parsing.h>
23 std::string_view ip) {
24 if(!email_addr.empty()) {
46 if(type.empty() || value.empty()) {
52 }
else if(type ==
"RFC822") {
54 }
else if(type ==
"URI") {
56 }
else if(type ==
"DN") {
58 std::istringstream ss{std::string(value)};
61 }
else if(type ==
"IP") {
86 std::multimap<std::string, std::string> names;
88 for(
const auto& nm : this->
dns()) {
89 names.emplace(
"DNS", nm);
92 for(
const auto& nm : this->
email()) {
93 names.emplace(
"RFC822", nm);
96 for(
const auto& nm : this->
uris()) {
97 names.emplace(
"URI", nm);
105 names.emplace(
"DN", nm.to_string());
109 names.emplace(othername.first.to_formatted_string(), othername.second.value());
116 std::multimap<std::string, std::string, std::less<>> r;
118 for(
const auto& c : this->
contents()) {
119 r.emplace(c.first, c.second);
140 auto set_to_vector = [](
const std::set<std::string>& s) -> std::vector<std::string> {
return {s.begin(), s.end()}; };
143 return set_to_vector(this->
dns());
144 }
else if(attr ==
"RFC822") {
145 return set_to_vector(this->
email());
146 }
else if(attr ==
"URI") {
147 return set_to_vector(this->
uris());
148 }
else if(attr ==
"DN") {
149 std::vector<std::string> ret;
152 ret.push_back(nm.to_string());
156 }
else if(attr ==
"IP") {
157 std::vector<std::string> ip_str;
174 std::ostringstream oss;
177 std::istringstream iss(oss.str());
const std::set< X509_DN > & directory_names() const
Return the set of directory names included in this alternative name.
std::string get_first_attribute(std::string_view attr) const
void add_dns(std::string_view dns)
Add a DNS name to this AlternativeName.
void add_ipv4_address(uint32_t ipv4)
Add an IP address to this alternative name.
void add_email(std::string_view addr)
Add a URI to this AlternativeName.
std::multimap< std::string, std::string > contents() const
std::vector< std::string > get_attribute(std::string_view attr) const
const std::set< uint32_t > & ipv4_address() const
Return the set of IPv4 addresses included in this alternative name.
const std::set< std::pair< OID, ASN1_String > > & other_names() const
Return the set of "other names" included in this alternative name.
const std::set< std::string > & uris() const
Return the set of URIs included in this alternative name.
void add_uri(std::string_view uri)
Add a URI to this AlternativeName.
void add_attribute(std::string_view type, std::string_view value)
const std::set< std::string > & dns() const
Return the set of DNS names included in this alternative name.
std::multimap< std::string, std::string, std::less<> > get_attributes() const
void add_other_name(const OID &oid, const ASN1_String &value)
Add an "OtherName" identified by object identifier to this AlternativeName.
void add_othername(const OID &oid, std::string_view value, ASN1_Type type)
AlternativeName()
Create an empty name.
const std::set< std::string > & email() const
Return the set of email addresses included in this alternative name.
void add_dn(const X509_DN &dn)
Add a directory name to this AlternativeName.
bool has_field(std::string_view attr) const
std::string fmt(std::string_view format, const T &... args)
std::optional< uint32_t > string_to_ipv4(std::string_view str)
std::string ipv4_to_string(uint32_t ip)