From c07f37f0af64156b5bc0369aa79936751cf55dfc Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Tue, 7 May 2024 06:40:05 -0400 Subject: [PATCH] Address some review comments --- src/lib/x509/asn1_alt_name.cpp | 10 ++-------- src/lib/x509/pkix_types.h | 22 +++++++++++++++------- src/lib/x509/x509cert.cpp | 6 ++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/lib/x509/asn1_alt_name.cpp b/src/lib/x509/asn1_alt_name.cpp index 1a810cdbb2..54fa4f6d5e 100644 --- a/src/lib/x509/asn1_alt_name.cpp +++ b/src/lib/x509/asn1_alt_name.cpp @@ -92,10 +92,6 @@ std::multimap AlternativeName::contents() const { names.emplace("IP", nm); } - for(const auto& nm : this->ip_address()) { - names.emplace("IP", nm); - } - for(const auto& nm : this->directory_names()) { names.emplace("DN", nm.to_string()); } @@ -132,10 +128,8 @@ std::string AlternativeName::get_first_attribute(std::string_view type) const { } std::vector AlternativeName::get_attribute(std::string_view attr) const { - auto set_to_vector = [](const std::set& s) { - std::vector v(s.size()); - std::copy(s.begin(), s.end(), v.begin()); - return v; + auto set_to_vector = [](const std::set& s) -> std::vector { + return {s.begin(), s.end()}; }; if(attr == "DNS") { diff --git a/src/lib/x509/pkix_types.h b/src/lib/x509/pkix_types.h index 18fbbe2de4..e2d1444f97 100644 --- a/src/lib/x509/pkix_types.h +++ b/src/lib/x509/pkix_types.h @@ -118,37 +118,45 @@ class BOTAN_PUBLIC_API(2, 0) AlternativeName final : public ASN1_Object { void encode_into(DER_Encoder&) const override; void decode_from(BER_Decoder&) override; - // Create an empty name + /// Create an empty name AlternativeName() {} - // Add a URI to this AlternativeName + /// Add a URI to this AlternativeName void add_uri(std::string_view uri); - // Add a URI to this AlternativeName + /// Add a URI to this AlternativeName void add_email(std::string_view addr); + /// Add a DNS name to this AlternativeName void add_dns(std::string_view dns); - // Add an "OtherName" identified by object identifier + /// Add an "OtherName" identified by object identifier to this AlternativeName void add_other_name(const OID& oid, const ASN1_String& value); + /// Add a directory name to this AlternativeName void add_dn(const X509_DN& dn); + /// Add an IP address to this alternative name + /// + /// Note: currently only IPv4 is accepted void add_ip_address(std::string_view ip_str); - // Read the set of URIs included in this alternative name + /// Return the set of URIs included in this alternative name const std::set& uris() const { return m_uri; } - // Read the set of email addresses included in this alternative name + /// Return the set of email addresses included in this alternative name const std::set& email() const { return m_email; } - // Read the set of DNS names included in this alternative name + /// Return the set of DNS names included in this alternative name const std::set& dns() const { return m_dns; } + /// Return the set of IPv4 addresses included in this alternative name const std::set& ip_address() const { return m_ip_addr; } + /// Return the set of "other names" included in this alternative name const std::set>& other_names() const { return m_othernames; } + /// Return the set of directory names included in this alternative name const std::set& directory_names() const { return m_dn_names; } // Return true if this has any names set diff --git a/src/lib/x509/x509cert.cpp b/src/lib/x509/x509cert.cpp index 2c976a9248..a057190541 100644 --- a/src/lib/x509/x509cert.cpp +++ b/src/lib/x509/x509cert.cpp @@ -513,10 +513,8 @@ const AlternativeName& X509_Certificate::issuer_alt_name() const { namespace { std::vector get_cert_user_info(std::string_view req, const X509_DN& dn, const AlternativeName& alt_name) { - auto set_to_vector = [](const std::set& s) { - std::vector v(s.size()); - std::copy(s.begin(), s.end(), v.begin()); - return v; + auto set_to_vector = [](const std::set& s) -> std::vector { + return {s.begin(), s.end()}; }; if(dn.has_field(req)) {