aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/cert/x509/x509_ext.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-03-06 05:55:23 -0500
committerJack Lloyd <[email protected]>2016-03-06 05:55:23 -0500
commitb73ecdcb0ad7199e95b4a06eb029edb49eef6a47 (patch)
treeb18b0580cc64d19f64853fb96013349c57866c73 /src/lib/cert/x509/x509_ext.cpp
parent27c9aeb85849b0b2808e95f50656d0a3c0aa6371 (diff)
parent6ab73e03710a93dbef18d65a84fbe1d702b7d795 (diff)
Merge GH #437 add X509_Certificate::v3_extensions
Makes it possible for an application to interpret some extension not supported by the library.
Diffstat (limited to 'src/lib/cert/x509/x509_ext.cpp')
-rw-r--r--src/lib/cert/x509/x509_ext.cpp34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/lib/cert/x509/x509_ext.cpp b/src/lib/cert/x509/x509_ext.cpp
index 7dd4a3190..f8f9adb2b 100644
--- a/src/lib/cert/x509/x509_ext.cpp
+++ b/src/lib/cert/x509/x509_ext.cpp
@@ -53,14 +53,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;
@@ -78,7 +76,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;
}
/*
@@ -88,7 +93,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();
@@ -109,9 +114,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);
@@ -128,7 +132,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 "
@@ -146,7 +152,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));
}
}
@@ -163,14 +169,6 @@ void Extensions::contents_to(Data_Store& subject_info,
m_extensions[i].first->contents_to(subject_info, issuer_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 {