diff options
author | Jack Lloyd <[email protected]> | 2018-03-21 08:30:50 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-21 08:30:50 -0400 |
commit | e2a0236d3c00b2a80ad22b8239e9752fb08f777e (patch) | |
tree | 235b1724022468403846c3686a24ceb0572fe26a /src/lib | |
parent | 931d57093e7dd482ea5eccf609857f9ea090dbd2 (diff) |
Avoid creating a map from a DN when not required
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/asn1/asn1_str.h | 2 | ||||
-rw-r--r-- | src/lib/x509/name_constraint.cpp | 4 | ||||
-rw-r--r-- | src/lib/x509/x509_dn.cpp | 18 | ||||
-rw-r--r-- | src/lib/x509/x509_dn.h | 7 | ||||
-rw-r--r-- | src/lib/x509/x509path.cpp | 3 |
5 files changed, 20 insertions, 14 deletions
diff --git a/src/lib/asn1/asn1_str.h b/src/lib/asn1/asn1_str.h index 9a571561c..41dbd005c 100644 --- a/src/lib/asn1/asn1_str.h +++ b/src/lib/asn1/asn1_str.h @@ -26,6 +26,8 @@ class BOTAN_PUBLIC_API(2,0) ASN1_String final : public ASN1_Object const std::string& value() const { return m_utf8_str; } + size_t size() const { return value().size(); } + bool empty() const { return m_utf8_str.empty(); } std::string BOTAN_DEPRECATED("Use value() to get UTF-8 string instead") diff --git a/src/lib/x509/name_constraint.cpp b/src/lib/x509/name_constraint.cpp index 888291557..b64e04d29 100644 --- a/src/lib/x509/name_constraint.cpp +++ b/src/lib/x509/name_constraint.cpp @@ -190,14 +190,14 @@ bool GeneralName::matches_dn(const std::string& nam) const bool ret = true; size_t trys = 0; - for(const std::pair<OID,std::string>& c: my_dn.get_attributes()) + for(const auto& c: my_dn.dn_info()) { auto i = attr.equal_range(c.first); if(i.first != i.second) { trys += 1; - ret = ret && (i.first->second == c.second); + ret = ret && (i.first->second == c.second.value()); } } diff --git a/src/lib/x509/x509_dn.cpp b/src/lib/x509/x509_dn.cpp index 4220c289a..9eb509dab 100644 --- a/src/lib/x509/x509_dn.cpp +++ b/src/lib/x509/x509_dn.cpp @@ -260,8 +260,13 @@ void X509_DN::decode_from(BER_Decoder& source) namespace { -std::string to_short_form(const std::string& long_id) +std::string to_short_form(const OID& oid) { + const std::string long_id = OIDS::oid2str(oid); + + if(long_id.empty()) + return oid.to_string(); + if(long_id == "X520.CommonName") return "CN"; @@ -281,13 +286,12 @@ std::string to_short_form(const std::string& long_id) std::ostream& operator<<(std::ostream& out, const X509_DN& dn) { - std::multimap<std::string, std::string> contents = dn.contents(); + auto info = dn.dn_info(); - for(std::multimap<std::string, std::string>::const_iterator i = contents.begin(); - i != contents.end(); ++i) + for(size_t i = 0; i != info.size(); ++i) { - out << to_short_form(i->first) << "=\""; - for(char c: i->second) + out << to_short_form(info[i].first) << "=\""; + for(char c : info[i].second.value()) { if(c == '\\' || c == '\"') { @@ -297,7 +301,7 @@ std::ostream& operator<<(std::ostream& out, const X509_DN& dn) } out << "\""; - if(std::next(i) != contents.end()) + if(i + 1 < info.size()) { out << ","; } diff --git a/src/lib/x509/x509_dn.h b/src/lib/x509/x509_dn.h index e6302e961..9d8beb0bf 100644 --- a/src/lib/x509/x509_dn.h +++ b/src/lib/x509/x509_dn.h @@ -53,14 +53,13 @@ class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object const std::vector<std::pair<OID,ASN1_String>>& dn_info() const { return m_rdn; } + std::multimap<OID, std::string> get_attributes() const; + std::multimap<std::string, std::string> contents() const; + bool has_field(const std::string& attr) const; std::vector<std::string> get_attribute(const std::string& attr) const; std::string get_first_attribute(const std::string& attr) const; - std::multimap<OID, std::string> get_attributes() const; - - std::multimap<std::string, std::string> contents() const; - void add_attribute(const std::string& key, const std::string& val); void add_attribute(const OID& oid, const std::string& val) diff --git a/src/lib/x509/x509path.cpp b/src/lib/x509/x509path.cpp index f703bf028..e73fe12b6 100644 --- a/src/lib/x509/x509path.cpp +++ b/src/lib/x509/x509path.cpp @@ -92,7 +92,8 @@ PKIX::check_chain(const std::vector<std::shared_ptr<const X509_Certificate>>& ce } // Check the subject's DN components' length - for(const auto& dn_pair : subject->subject_dn().get_attributes()) + + for(const auto& dn_pair : subject->subject_dn().dn_info()) { const size_t dn_ub = X509_DN::lookup_ub(dn_pair.first); // dn_pair = <OID,str> |