Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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/crl_ent.h>
9 #include <botan/x509cert.h>
10 #include <botan/x509_ext.h>
11 #include <botan/der_enc.h>
12 #include <botan/ber_dec.h>
13 #include <botan/bigint.h>
14
15 namespace Botan {
16
17 struct CRL_Entry_Data
18 {
19 std::vector<uint8_t> m_serial;
20 X509_Time m_time;
21 CRL_Code m_reason = UNSPECIFIED;
22 Extensions m_extensions;
23 };
24
25 /*
26 * Create a CRL_Entry
27 */
28 CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why)
29 {
30 m_data.reset(new CRL_Entry_Data);
31 m_data->m_serial = cert.serial_number();
32 m_data->m_time = X509_Time(std::chrono::system_clock::now());
33 m_data->m_reason = why;
34
35 if(why != UNSPECIFIED)
36 {
37 m_data->m_extensions.add(new Cert_Extension::CRL_ReasonCode(why));
38 }
39 }
40
41 /*
42 * Compare two CRL_Entrys for equality
43 */
44 bool operator==(const CRL_Entry& a1, const CRL_Entry& a2)
45 {
46 if(a1.serial_number() != a2.serial_number())
47 return false;
48 if(a1.expire_time() != a2.expire_time())
49 return false;
50 if(a1.reason_code() != a2.reason_code())
51 return false;
52 return true;
53 }
54
55 /*
56 * Compare two CRL_Entrys for inequality
57 */
58 bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2)
59 {
60 return !(a1 == a2);
61 }
62
63 /*
64 * DER encode a CRL_Entry
65 */
66 void CRL_Entry::encode_into(DER_Encoder& der) const
67 {
68 der.start_cons(SEQUENCE)
69 .encode(BigInt::decode(serial_number()))
70 .encode(expire_time())
71 .start_cons(SEQUENCE)
72 .encode(extensions())
73 .end_cons()
74 .end_cons();
75 }
76
77 /*
78 * Decode a BER encoded CRL_Entry
79 */
80 void CRL_Entry::decode_from(BER_Decoder& source)
81 {
82 BigInt serial_number_bn;
83
84 std::unique_ptr<CRL_Entry_Data> data(new CRL_Entry_Data);
85
86 BER_Decoder entry = source.start_cons(SEQUENCE);
87
88 entry.decode(serial_number_bn).decode(data->m_time);
89 data->m_serial = BigInt::encode(serial_number_bn);
90
91 if(entry.more_items())
92 {
93 entry.decode(data->m_extensions);
94 if(auto ext = data->m_extensions.get_extension_object_as<Cert_Extension::CRL_ReasonCode>())
95 {
96 data->m_reason = ext->get_reason();
97 }
98 else
99 {
100 data->m_reason = UNSPECIFIED;
101 }
102 }
103
104 entry.end_cons();
105
106 m_data.reset(data.release());
107 }
108
109 const CRL_Entry_Data& CRL_Entry::data() const
110 {
111 if(!m_data)
112 {
113 throw Invalid_State("CRL_Entry_Data uninitialized");
114 }
115
116 return *m_data.get();
117 }
118
119 const std::vector<uint8_t>& CRL_Entry::serial_number() const
120 {
121 return data().m_serial;
122 }
123
124 const X509_Time& CRL_Entry::expire_time() const
125 {
126 return data().m_time;
127 }
128
129 CRL_Code CRL_Entry::reason_code() const
130 {
131 return data().m_reason;
132 }
133
134 const Extensions& CRL_Entry::extensions() const
135 {
136 return data().m_extensions;
137 }
138
139
140 }
Botan::operator!=
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:89
Botan::CRL_Entry::expire_time
const X509_Time & expire_time() const
Definition: crl_ent.cpp:124
Botan::X509_Certificate::serial_number
const std::vector< uint8_t > & serial_number() const
Definition: x509cert.cpp:422
Botan::BigInt
Definition: bigint.h:24
Botan::CRL_Code
CRL_Code
Definition: crl_ent.h:23
Botan::BigInt::encode
static std::vector< uint8_t > encode(const BigInt &n)
Definition: bigint.h:763
Botan::CRL_Entry::CRL_Entry
CRL_Entry()=default
Botan::Extensions
Definition: x509_ext.h:90
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:191
Botan::CRL_Entry::decode_from
void decode_from(class BER_Decoder &) override
Definition: crl_ent.cpp:80
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::Cert_Extension::CRL_ReasonCode
Definition: x509_ext.h:633
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:285
Botan::SEQUENCE
Definition: asn1_obj.h:40
Botan::DER_Encoder
Definition: der_enc.h:23
Botan::X509_Certificate
Definition: x509cert.h:40
Botan::BER_Decoder::end_cons
BER_Decoder & end_cons()
Definition: ber_dec.cpp:300
Botan::BER_Decoder::more_items
bool more_items() const
Definition: ber_dec.cpp:198
Botan::BER_Decoder::start_cons
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: ber_dec.cpp:290
Botan
Definition: alg_id.cpp:13
Botan::CRL_Entry
Definition: crl_ent.h:44
Botan::Invalid_State
Definition: exceptn.h:215
Botan::BigInt::decode
static BigInt decode(const uint8_t buf[], size_t length)
Definition: bigint.h:798
Botan::Usage_Type::UNSPECIFIED
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:181
Botan::operator==
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:74
Botan::CRL_Entry::reason_code
CRL_Code reason_code() const
Definition: crl_ent.cpp:129
Botan::CRL_Entry::extensions
const Extensions & extensions() const
Definition: crl_ent.cpp:134
Botan::BER_Decoder
Definition: ber_dec.h:21
Botan::CRL_Entry::encode_into
void encode_into(class DER_Encoder &) const override
Definition: crl_ent.cpp:66
Botan::X509_Time
Definition: asn1_time.h:19
Botan::CRL_Entry::serial_number
const std::vector< uint8_t > & serial_number() const
Definition: crl_ent.cpp:119