aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-21 08:09:05 -0400
committerJack Lloyd <[email protected]>2018-03-21 08:09:05 -0400
commit931d57093e7dd482ea5eccf609857f9ea090dbd2 (patch)
treef472c83f6861e5e5bd2fd216ce7de6a81f0e2b28 /src
parent9a35a05781688838b9bf951471c86363deba36cd (diff)
Store elements of a DN as a vector
This allows retreiving the original ordering which is required for DN string encoding as defined in RFC 4514 Fixes #336
Diffstat (limited to 'src')
-rw-r--r--src/lib/x509/x509_dn.cpp87
-rw-r--r--src/lib/x509/x509_dn.h31
2 files changed, 59 insertions, 59 deletions
diff --git a/src/lib/x509/x509_dn.cpp b/src/lib/x509/x509_dn.cpp
index 64c1c9a08..4220c289a 100644
--- a/src/lib/x509/x509_dn.cpp
+++ b/src/lib/x509/x509_dn.cpp
@@ -1,6 +1,6 @@
/*
* X509_DN
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -17,24 +17,6 @@
namespace Botan {
/*
-* Create an X509_DN
-*/
-X509_DN::X509_DN(const std::multimap<OID, std::string>& args)
- {
- for(auto i = args.begin(); i != args.end(); ++i)
- add_attribute(i->first, i->second);
- }
-
-/*
-* Create an X509_DN
-*/
-X509_DN::X509_DN(const std::multimap<std::string, std::string>& args)
- {
- for(auto i = args.begin(); i != args.end(); ++i)
- add_attribute(OIDS::lookup(i->first), i->second);
- }
-
-/*
* Add an attribute to a X509_DN
*/
void X509_DN::add_attribute(const std::string& type,
@@ -43,11 +25,6 @@ void X509_DN::add_attribute(const std::string& type,
add_attribute(OIDS::lookup(type), str);
}
-void X509_DN::add_attribute(const OID& oid, const std::string& str)
- {
- add_attribute(oid, ASN1_String(str));
- }
-
/*
* Add an attribute to a X509_DN
*/
@@ -56,14 +33,7 @@ void X509_DN::add_attribute(const OID& oid, const ASN1_String& str)
if(str.empty())
return;
- auto range = m_dn_info.equal_range(oid);
- for(auto i = range.first; i != range.second; ++i)
- {
- if(i->second == str)
- return;
- }
-
- multimap_insert(m_dn_info, oid, str);
+ m_rdn.push_back(std::make_pair(oid, str));
m_dn_bits.clear();
}
@@ -73,8 +43,9 @@ void X509_DN::add_attribute(const OID& oid, const ASN1_String& str)
std::multimap<OID, std::string> X509_DN::get_attributes() const
{
std::multimap<OID, std::string> retval;
- for(auto i = m_dn_info.begin(); i != m_dn_info.end(); ++i)
- multimap_insert(retval, i->first, i->second.value());
+
+ for(auto& i : m_rdn)
+ multimap_insert(retval, i.first, i.second.value());
return retval;
}
@@ -84,13 +55,14 @@ std::multimap<OID, std::string> X509_DN::get_attributes() const
std::multimap<std::string, std::string> X509_DN::contents() const
{
std::multimap<std::string, std::string> retval;
- for(auto i = m_dn_info.begin(); i != m_dn_info.end(); ++i)
+
+ for(auto& i : m_rdn)
{
- std::string str_value = OIDS::oid2str(i->first);
+ std::string str_value = OIDS::oid2str(i.first);
if(str_value.empty())
- str_value = i->first.as_string();
- multimap_insert(retval, str_value, i->second.value());
+ str_value = i.first.as_string();
+ multimap_insert(retval, str_value, i.second.value());
}
return retval;
}
@@ -102,8 +74,13 @@ bool X509_DN::has_field(const std::string& attr) const
bool X509_DN::has_field(const OID& oid) const
{
- auto range = m_dn_info.equal_range(oid);
- return (range.first != range.second);
+ for(auto& i : m_rdn)
+ {
+ if(i.first == oid)
+ return true;
+ }
+
+ return false;
}
std::string X509_DN::get_first_attribute(const std::string& attr) const
@@ -114,9 +91,13 @@ std::string X509_DN::get_first_attribute(const std::string& attr) const
ASN1_String X509_DN::get_first_attribute(const OID& oid) const
{
- auto i = m_dn_info.lower_bound(oid);
- if(i != m_dn_info.end() && i->first == oid)
- return i->second;
+ for(auto& i : m_rdn)
+ {
+ if(i.first == oid)
+ {
+ return i.second;
+ }
+ }
return ASN1_String();
}
@@ -128,11 +109,16 @@ std::vector<std::string> X509_DN::get_attribute(const std::string& attr) const
{
const OID oid = OIDS::lookup(deref_info_field(attr));
- auto range = m_dn_info.equal_range(oid);
-
std::vector<std::string> values;
- for(auto i = range.first; i != range.second; ++i)
- values.push_back(i->second.value());
+
+ for(auto& i : m_rdn)
+ {
+ if(i.first == oid)
+ {
+ values.push_back(i.second.value());
+ }
+ }
+
return values;
}
@@ -227,7 +213,7 @@ void X509_DN::encode_into(DER_Encoder& der) const
}
else
{
- for(const auto& dn : m_dn_info)
+ for(const auto& dn : m_rdn)
{
der.start_cons(SET)
.start_cons(SEQUENCE)
@@ -263,10 +249,7 @@ void X509_DN::decode_from(BER_Decoder& source)
OID oid;
ASN1_String str;
- rdn.start_cons(SEQUENCE)
- .decode(oid)
- .decode(str)
- .end_cons();
+ rdn.start_cons(SEQUENCE).decode(oid).decode(str).end_cons();
add_attribute(oid, str);
}
diff --git a/src/lib/x509/x509_dn.h b/src/lib/x509/x509_dn.h
index c08bf9e7e..e6302e961 100644
--- a/src/lib/x509/x509_dn.h
+++ b/src/lib/x509/x509_dn.h
@@ -12,6 +12,7 @@
#include <botan/asn1_obj.h>
#include <botan/asn1_oid.h>
#include <botan/asn1_str.h>
+#include <vector>
#include <map>
#include <iosfwd>
@@ -24,14 +25,22 @@ class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object
{
public:
X509_DN() = default;
- explicit X509_DN(const std::multimap<OID, std::string>& vals);
- explicit X509_DN(const std::multimap<std::string, std::string>& vals);
+
+ explicit X509_DN(const std::multimap<OID, std::string>& args)
+ {
+ for(auto i : args)
+ add_attribute(i.first, i.second);
+ }
+
+ explicit X509_DN(const std::multimap<std::string, std::string>& args)
+ {
+ for(auto i : args)
+ add_attribute(i.first, i.second);
+ }
void encode_into(class DER_Encoder&) const override;
void decode_from(class BER_Decoder&) override;
- const std::multimap<OID, ASN1_String>& dn_info() const { return m_dn_info; }
-
bool has_field(const OID& oid) const;
ASN1_String get_first_attribute(const OID& oid) const;
@@ -40,17 +49,25 @@ class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object
*/
const std::vector<uint8_t>& get_bits() const { return m_dn_bits; }
- bool empty() const { return m_dn_info.empty(); }
+ bool empty() const { return m_rdn.empty(); }
+
+ const std::vector<std::pair<OID,ASN1_String>>& dn_info() const { return m_rdn; }
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);
+
+ void add_attribute(const OID& oid, const std::string& val)
+ {
+ add_attribute(oid, ASN1_String(val));
+ }
+
void add_attribute(const OID& oid, const ASN1_String& val);
static std::string deref_info_field(const std::string& key);
@@ -65,7 +82,7 @@ class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object
static size_t lookup_ub(const OID& oid);
private:
- std::multimap<OID, ASN1_String> m_dn_info;
+ std::vector<std::pair<OID,ASN1_String>> m_rdn;
std::vector<uint8_t> m_dn_bits;
};