aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/x509
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-11-14 09:20:51 -0500
committerJack Lloyd <[email protected]>2017-11-14 16:19:44 -0500
commitc2239949daf06c1e3b47ac9652750aca8e344796 (patch)
treedf1584753ee09935446a0650b42c36ff50bc5f04 /src/lib/x509
parentbc552d5ced2a3727c93070c82a87a4338f95e0db (diff)
Store CRL_Entry data in shared_ptr
Diffstat (limited to 'src/lib/x509')
-rw-r--r--src/lib/x509/crl_ent.cpp94
-rw-r--r--src/lib/x509/crl_ent.h28
2 files changed, 81 insertions, 41 deletions
diff --git a/src/lib/x509/crl_ent.cpp b/src/lib/x509/crl_ent.cpp
index fabd88326..61fd5d31f 100644
--- a/src/lib/x509/crl_ent.cpp
+++ b/src/lib/x509/crl_ent.cpp
@@ -14,24 +14,28 @@
namespace Botan {
-/*
-* Create a CRL_Entry
-*/
-CRL_Entry::CRL_Entry(bool t_on_unknown_crit) :
- m_throw_on_unknown_critical(t_on_unknown_crit)
+struct CRL_Entry_Data
{
- m_reason = UNSPECIFIED;
- }
+ std::vector<uint8_t> m_serial;
+ X509_Time m_time;
+ CRL_Code m_reason;
+ Extensions m_extensions;
+ };
/*
* Create a CRL_Entry
*/
-CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why) :
- m_throw_on_unknown_critical(false)
+CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why)
{
- m_serial = cert.serial_number();
- m_time = X509_Time(std::chrono::system_clock::now());
- m_reason = why;
+ m_data.reset(new CRL_Entry_Data);
+ m_data->m_serial = cert.serial_number();
+ m_data->m_time = X509_Time(std::chrono::system_clock::now());
+ m_data->m_reason = why;
+
+ if(why != UNSPECIFIED)
+ {
+ m_data->m_extensions.add(new Cert_Extension::CRL_ReasonCode(why));
+ }
}
/*
@@ -61,17 +65,13 @@ bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2)
*/
void CRL_Entry::encode_into(DER_Encoder& der) const
{
- Extensions extensions;
-
- extensions.add(new Cert_Extension::CRL_ReasonCode(m_reason));
-
der.start_cons(SEQUENCE)
- .encode(BigInt::decode(m_serial))
- .encode(m_time)
- .start_cons(SEQUENCE)
- .encode(extensions)
- .end_cons()
- .end_cons();
+ .encode(BigInt::decode(serial_number()))
+ .encode(expire_time())
+ .start_cons(SEQUENCE)
+ .encode(extensions())
+ .end_cons()
+ .end_cons();
}
/*
@@ -80,24 +80,58 @@ void CRL_Entry::encode_into(DER_Encoder& der) const
void CRL_Entry::decode_from(BER_Decoder& source)
{
BigInt serial_number_bn;
- m_reason = UNSPECIFIED;
+
+ std::unique_ptr<CRL_Entry_Data> data(new CRL_Entry_Data);
BER_Decoder entry = source.start_cons(SEQUENCE);
- entry.decode(serial_number_bn).decode(m_time);
+ entry.decode(serial_number_bn).decode(data->m_time);
+ data->m_serial = BigInt::encode(serial_number_bn);
if(entry.more_items())
{
- Extensions extensions(m_throw_on_unknown_critical);
- entry.decode(extensions);
- Data_Store info;
- extensions.contents_to(info, info);
- m_reason = CRL_Code(info.get1_uint32("X509v3.CRLReasonCode"));
+ entry.decode(data->m_extensions);
+ if(auto ext = data->m_extensions.get_extension_object_as<Cert_Extension::CRL_ReasonCode>())
+ {
+ data->m_reason = ext->get_reason();
+ }
+ else
+ {
+ data->m_reason = UNSPECIFIED;
+ }
}
entry.end_cons();
- m_serial = BigInt::encode(serial_number_bn);
+ m_data.reset(data.release());
+ }
+
+const CRL_Entry_Data& CRL_Entry::data() const
+ {
+ if(!m_data)
+ throw Decoding_Error("Uninitialized CRL_Entry");
+ return *m_data.get();
+ }
+
+const std::vector<uint8_t>& CRL_Entry::serial_number() const
+ {
+ return data().m_serial;
}
+const X509_Time& CRL_Entry::expire_time() const
+ {
+ return data().m_time;
+ }
+
+CRL_Code CRL_Entry::reason_code() const
+ {
+ return data().m_reason;
+ }
+
+const Extensions& CRL_Entry::extensions() const
+ {
+ return data().m_extensions;
+ }
+
+
}
diff --git a/src/lib/x509/crl_ent.h b/src/lib/x509/crl_ent.h
index cf509d3c1..967dc92d2 100644
--- a/src/lib/x509/crl_ent.h
+++ b/src/lib/x509/crl_ent.h
@@ -12,7 +12,9 @@
namespace Botan {
+class Extensions;
class X509_Certificate;
+struct CRL_Entry_Data;
/**
* X.509v2 CRL Reason Code.
@@ -47,26 +49,29 @@ class BOTAN_PUBLIC_API(2,0) CRL_Entry final : public ASN1_Object
* Get the serial number of the certificate associated with this entry.
* @return certificate's serial number
*/
- std::vector<uint8_t> serial_number() const { return m_serial; }
+ const std::vector<uint8_t>& serial_number() const;
/**
* Get the revocation date of the certificate associated with this entry
* @return certificate's revocation date
*/
- X509_Time expire_time() const { return m_time; }
+ const X509_Time& expire_time() const;
/**
* Get the entries reason code
* @return reason code
*/
- CRL_Code reason_code() const { return m_reason; }
+ CRL_Code reason_code() const;
/**
- * Construct an empty CRL entry.
- * @param throw_on_unknown_critical_extension should we throw an exception
- * if an unknown CRL extension marked as critical is encountered
+ * Get the extensions on this CRL entry
*/
- explicit CRL_Entry(bool throw_on_unknown_critical_extension = false);
+ const Extensions& extensions() const;
+
+ /**
+ * Create uninitialized CRL_Entry object
+ */
+ CRL_Entry() {}
/**
* Construct an CRL entry.
@@ -77,10 +82,11 @@ class BOTAN_PUBLIC_API(2,0) CRL_Entry final : public ASN1_Object
CRL_Code reason = UNSPECIFIED);
private:
- bool m_throw_on_unknown_critical;
- std::vector<uint8_t> m_serial;
- X509_Time m_time;
- CRL_Code m_reason;
+ friend class X509_CRL;
+
+ const CRL_Entry_Data& data() const;
+
+ std::shared_ptr<CRL_Entry_Data> m_data;
};
/**