Skip to content

Commit

Permalink
Address some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed May 7, 2024
1 parent ab85979 commit c07f37f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
10 changes: 2 additions & 8 deletions src/lib/x509/asn1_alt_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ std::multimap<std::string, std::string> 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());
}
Expand Down Expand Up @@ -132,10 +128,8 @@ std::string AlternativeName::get_first_attribute(std::string_view type) const {
}

std::vector<std::string> AlternativeName::get_attribute(std::string_view attr) const {
auto set_to_vector = [](const std::set<std::string>& s) {
std::vector<std::string> v(s.size());
std::copy(s.begin(), s.end(), v.begin());
return v;
auto set_to_vector = [](const std::set<std::string>& s) -> std::vector<std::string> {
return {s.begin(), s.end()};
};

if(attr == "DNS") {
Expand Down
22 changes: 15 additions & 7 deletions src/lib/x509/pkix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& 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<std::string>& 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<std::string>& dns() const { return m_dns; }

/// Return the set of IPv4 addresses included in this alternative name
const std::set<std::string>& ip_address() const { return m_ip_addr; }

/// Return the set of "other names" included in this alternative name
const std::set<std::pair<OID, ASN1_String>>& other_names() const { return m_othernames; }

/// Return the set of directory names included in this alternative name
const std::set<X509_DN>& directory_names() const { return m_dn_names; }

// Return true if this has any names set
Expand Down
6 changes: 2 additions & 4 deletions src/lib/x509/x509cert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,8 @@ const AlternativeName& X509_Certificate::issuer_alt_name() const {
namespace {

std::vector<std::string> get_cert_user_info(std::string_view req, const X509_DN& dn, const AlternativeName& alt_name) {
auto set_to_vector = [](const std::set<std::string>& s) {
std::vector<std::string> v(s.size());
std::copy(s.begin(), s.end(), v.begin());
return v;
auto set_to_vector = [](const std::set<std::string>& s) -> std::vector<std::string> {
return {s.begin(), s.end()};
};

if(dn.has_field(req)) {
Expand Down

0 comments on commit c07f37f

Please sign in to comment.