Skip to content

Commit

Permalink
Add AlternativeName::count
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed May 11, 2024
1 parent 252ec96 commit a6ad2c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
33 changes: 14 additions & 19 deletions src/lib/x509/alt_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#include <botan/ber_dec.h>
#include <botan/der_enc.h>
#include <botan/internal/int_utils.h>
#include <botan/internal/loadstor.h>
#include <botan/internal/parsing.h>
#include <botan/internal/stl_util.h>

namespace Botan {

Expand Down Expand Up @@ -43,26 +45,19 @@ void AlternativeName::add_ipv4_address(uint32_t ip) {
m_ipv4_addr.insert(ip);
}

size_t AlternativeName::count() const {
const auto sum = checked_add(m_dns.size(),
m_uri.size(),
m_email.size(),
m_ipv4_addr.size(),
m_dn_names.size(),
m_othernames.size());

return BOTAN_ASSERT_IS_SOME(sum);
}

bool AlternativeName::has_items() const {
if(!this->dns().empty()) {
return true;
}
if(!this->uris().empty()) {
return true;
}
if(!this->email().empty()) {
return true;
}
if(!this->ipv4_address().empty()) {
return true;
}
if(!this->directory_names().empty()) {
return true;
}
if(!this->other_names().empty()) {
return true;
}
return false;
return this->count() > 0;
}

void AlternativeName::encode_into(DER_Encoder& der) const {
Expand Down
8 changes: 7 additions & 1 deletion src/lib/x509/pkix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ class BOTAN_PUBLIC_API(2, 0) AlternativeName final : public ASN1_Object {
/// 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
/// Return the total number of names in this AlternativeName
///
/// This only counts names which were parsed, ignoring names which
/// were of some unknown type
size_t count() const;

/// Return true if this has any names set
bool has_items() const;

// Old, now deprecated interface follows:
Expand Down

0 comments on commit a6ad2c2

Please sign in to comment.