Botan 3.6.1
Crypto and TLS for C&
crl_ent.cpp
Go to the documentation of this file.
1/*
2* CRL Entry
3* (C) 1999-2010 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/x509_crl.h>
9
10#include <botan/ber_dec.h>
11#include <botan/bigint.h>
12#include <botan/der_enc.h>
13#include <botan/x509_ext.h>
14#include <botan/x509cert.h>
15
16namespace Botan {
17
18struct CRL_Entry_Data {
19 std::vector<uint8_t> m_serial;
20 X509_Time m_time;
22 Extensions m_extensions;
23};
24
25/*
26* Create a CRL_Entry
27*/
29 m_data = std::make_shared<CRL_Entry_Data>();
30 m_data->m_serial = cert.serial_number();
31 m_data->m_time = X509_Time(std::chrono::system_clock::now());
32 m_data->m_reason = why;
33
34 if(why != CRL_Code::Unspecified) {
35 m_data->m_extensions.add(std::make_unique<Cert_Extension::CRL_ReasonCode>(why));
36 }
37}
38
39/*
40* Compare two CRL_Entrys for equality
41*/
42bool operator==(const CRL_Entry& a1, const CRL_Entry& a2) {
43 if(a1.serial_number() != a2.serial_number()) {
44 return false;
45 }
46 if(a1.expire_time() != a2.expire_time()) {
47 return false;
48 }
49 if(a1.reason_code() != a2.reason_code()) {
50 return false;
51 }
52 return true;
53}
54
55/*
56* Compare two CRL_Entrys for inequality
57*/
58bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2) {
59 return !(a1 == a2);
60}
61
62/*
63* DER encode a CRL_Entry
64*/
74
75/*
76* Decode a BER encoded CRL_Entry
77*/
79 BigInt serial_number_bn;
80
81 auto data = std::make_unique<CRL_Entry_Data>();
82
83 BER_Decoder entry = source.start_sequence();
84
85 entry.decode(serial_number_bn).decode(data->m_time);
86 data->m_serial = serial_number_bn.serialize();
87
88 if(entry.more_items()) {
89 entry.decode(data->m_extensions);
90 if(auto ext = data->m_extensions.get_extension_object_as<Cert_Extension::CRL_ReasonCode>()) {
91 data->m_reason = ext->get_reason();
92 } else {
93 data->m_reason = CRL_Code::Unspecified;
94 }
95 }
96
97 entry.end_cons();
98
99 m_data = std::move(data);
100}
101
102const CRL_Entry_Data& CRL_Entry::data() const {
103 if(!m_data) {
104 throw Invalid_State("CRL_Entry_Data uninitialized");
105 }
106
107 return *m_data;
108}
109
110const std::vector<uint8_t>& CRL_Entry::serial_number() const {
111 return data().m_serial;
112}
113
115 return data().m_time;
116}
117
119 return data().m_reason;
120}
121
123 return data().m_extensions;
124}
125
126} // namespace Botan
BER_Decoder & decode(bool &out)
Definition ber_dec.h:186
bool more_items() const
Definition ber_dec.cpp:201
BER_Decoder & end_cons()
Definition ber_dec.cpp:309
BER_Decoder start_sequence()
Definition ber_dec.h:123
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:95
T serialize(size_t len) const
Definition bigint.h:712
Definition x509_crl.h:28
CRL_Code reason_code() const
Definition crl_ent.cpp:118
const X509_Time & expire_time() const
Definition crl_ent.cpp:114
CRL_Entry()=default
const std::vector< uint8_t > & serial_number() const
Definition crl_ent.cpp:110
void decode_from(BER_Decoder &) override
Definition crl_ent.cpp:78
void encode_into(DER_Encoder &) const override
Definition crl_ent.cpp:65
const Extensions & extensions() const
Definition crl_ent.cpp:122
DER_Encoder & start_sequence()
Definition der_enc.h:64
DER_Encoder & end_cons()
Definition der_enc.cpp:171
DER_Encoder & encode(bool b)
Definition der_enc.cpp:250
const T * get_extension_object_as(const OID &oid=T::static_oid()) const
Definition pkix_types.h:477
const std::vector< uint8_t > & serial_number() const
Definition x509cert.cpp:383
ASN1_Time X509_Time
Definition asn1_obj.h:409
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:69
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:54