aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/cert/x509/x509_ext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/cert/x509/x509_ext.cpp')
-rw-r--r--src/lib/cert/x509/x509_ext.cpp68
1 files changed, 32 insertions, 36 deletions
diff --git a/src/lib/cert/x509/x509_ext.cpp b/src/lib/cert/x509/x509_ext.cpp
index 765ad1786..47fd909eb 100644
--- a/src/lib/cert/x509/x509_ext.cpp
+++ b/src/lib/cert/x509/x509_ext.cpp
@@ -55,14 +55,12 @@ Extensions::Extensions(const Extensions& extensions) : ASN1_Object()
* Extensions Assignment Operator
*/
Extensions& Extensions::operator=(const Extensions& other)
- {
- for(size_t i = 0; i != m_extensions.size(); ++i)
- delete m_extensions[i].first;
+ {
m_extensions.clear();
for(size_t i = 0; i != other.m_extensions.size(); ++i)
m_extensions.push_back(
- std::make_pair(other.m_extensions[i].first->copy(),
+ std::make_pair(std::unique_ptr<Certificate_Extension>(other.m_extensions[i].first->copy()),
other.m_extensions[i].second));
m_throw_on_unknown_critical = other.m_throw_on_unknown_critical;
@@ -80,7 +78,14 @@ OID Certificate_Extension::oid_of() const
void Extensions::add(Certificate_Extension* extn, bool critical)
{
- m_extensions.push_back(std::make_pair(extn, critical));
+ m_extensions.push_back(std::make_pair(std::unique_ptr<Certificate_Extension>(extn), critical));
+ m_extensions_raw.emplace(extn->oid_of(), std::make_pair(extn->encode_inner(), critical));
+ }
+
+
+std::map<OID, std::pair<std::vector<byte>, bool>> Extensions::extensions_raw() const
+ {
+ return m_extensions_raw;
}
/*
@@ -90,7 +95,7 @@ void Extensions::encode_into(DER_Encoder& to_object) const
{
for(size_t i = 0; i != m_extensions.size(); ++i)
{
- const Certificate_Extension* ext = m_extensions[i].first;
+ const Certificate_Extension* ext = m_extensions[i].first.get();
const bool is_critical = m_extensions[i].second;
const bool should_encode = ext->should_encode();
@@ -111,9 +116,8 @@ void Extensions::encode_into(DER_Encoder& to_object) const
*/
void Extensions::decode_from(BER_Decoder& from_source)
{
- for(size_t i = 0; i != m_extensions.size(); ++i)
- delete m_extensions[i].first;
m_extensions.clear();
+ m_extensions_raw.clear();
BER_Decoder sequence = from_source.start_cons(SEQUENCE);
@@ -130,7 +134,9 @@ void Extensions::decode_from(BER_Decoder& from_source)
.verify_end()
.end_cons();
- Certificate_Extension* ext = get_extension(oid);
+ m_extensions_raw.emplace(oid, std::make_pair(value, critical));
+
+ std::unique_ptr<Certificate_Extension> ext(get_extension(oid));
if(!ext && critical && m_throw_on_unknown_critical)
throw Decoding_Error("Encountered unknown X.509 extension marked "
@@ -148,7 +154,7 @@ void Extensions::decode_from(BER_Decoder& from_source)
oid.as_string() + ": " + e.what());
}
- m_extensions.push_back(std::make_pair(ext, critical));
+ m_extensions.push_back(std::make_pair(std::move(ext), critical));
}
}
@@ -168,14 +174,6 @@ void Extensions::contents_to(Data_Store& subject_info,
}
}
-/*
-* Delete an Extensions list
-*/
-Extensions::~Extensions()
- {
- for(size_t i = 0; i != m_extensions.size(); ++i)
- delete m_extensions[i].first;
- }
namespace Cert_Extension {
@@ -314,11 +312,8 @@ void Subject_Key_ID::contents_to(Data_Store& subject, Data_Store&) const
/*
* Subject_Key_ID Constructor
*/
-Subject_Key_ID::Subject_Key_ID(const std::vector<byte>& pub_key)
- {
- SHA_160 hash;
- m_key_id = unlock(hash.process(pub_key));
- }
+Subject_Key_ID::Subject_Key_ID(const std::vector<byte>& pub_key) : m_key_id(unlock(SHA_160().process(pub_key)))
+ {}
/*
* Encode the extension
@@ -389,11 +384,10 @@ void Alternative_Name::contents_to(Data_Store& subject_info,
* Alternative_Name Constructor
*/
Alternative_Name::Alternative_Name(const AlternativeName& alt_name,
- const std::string& oid_name_str)
- {
- this->m_alt_name = alt_name;
- this->m_oid_name_str = oid_name_str;
- }
+ const std::string& oid_name_str) :
+ m_oid_name_str(oid_name_str),
+ m_alt_name(alt_name)
+ {}
/*
* Subject_Alternative_Name Constructor
@@ -514,26 +508,28 @@ namespace {
class Policy_Information : public ASN1_Object
{
public:
- // public member variable:
- OID oid;
-
Policy_Information() {}
- Policy_Information(const OID& oid_) : oid(oid_) {}
+ explicit Policy_Information(const OID& oid) : m_oid(oid) {}
+
+ const OID& oid() const { return m_oid; }
void encode_into(DER_Encoder& codec) const override
{
codec.start_cons(SEQUENCE)
- .encode(oid)
+ .encode(m_oid)
.end_cons();
}
void decode_from(BER_Decoder& codec) override
{
codec.start_cons(SEQUENCE)
- .decode(oid)
+ .decode(m_oid)
.discard_remaining()
.end_cons();
}
+
+ private:
+ OID m_oid;
};
}
@@ -546,7 +542,7 @@ std::vector<byte> Certificate_Policies::encode_inner() const
std::vector<Policy_Information> policies;
for(size_t i = 0; i != m_oids.size(); ++i)
- policies.push_back(m_oids[i]);
+ policies.push_back(Policy_Information(m_oids[i]));
return DER_Encoder()
.start_cons(SEQUENCE)
@@ -566,7 +562,7 @@ void Certificate_Policies::decode_inner(const std::vector<byte>& in)
m_oids.clear();
for(size_t i = 0; i != policies.size(); ++i)
- m_oids.push_back(policies[i].oid);
+ m_oids.push_back(policies[i].oid());
}
/*