/src/botan/src/lib/x509/crl_ent.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #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 = CRL_Code::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 | 0 | { |
30 | 0 | m_data = std::make_shared<CRL_Entry_Data>(); |
31 | 0 | m_data->m_serial = cert.serial_number(); |
32 | 0 | m_data->m_time = X509_Time(std::chrono::system_clock::now()); |
33 | 0 | m_data->m_reason = why; |
34 | |
|
35 | 0 | if(why != CRL_Code::UNSPECIFIED) |
36 | 0 | { |
37 | 0 | m_data->m_extensions.add(std::make_unique<Cert_Extension::CRL_ReasonCode>(why)); |
38 | 0 | } |
39 | 0 | } |
40 | | |
41 | | /* |
42 | | * Compare two CRL_Entrys for equality |
43 | | */ |
44 | | bool operator==(const CRL_Entry& a1, const CRL_Entry& a2) |
45 | 0 | { |
46 | 0 | if(a1.serial_number() != a2.serial_number()) |
47 | 0 | return false; |
48 | 0 | if(a1.expire_time() != a2.expire_time()) |
49 | 0 | return false; |
50 | 0 | if(a1.reason_code() != a2.reason_code()) |
51 | 0 | return false; |
52 | 0 | return true; |
53 | 0 | } |
54 | | |
55 | | /* |
56 | | * Compare two CRL_Entrys for inequality |
57 | | */ |
58 | | bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2) |
59 | 0 | { |
60 | 0 | return !(a1 == a2); |
61 | 0 | } |
62 | | |
63 | | /* |
64 | | * DER encode a CRL_Entry |
65 | | */ |
66 | | void CRL_Entry::encode_into(DER_Encoder& der) const |
67 | 0 | { |
68 | 0 | der.start_sequence() |
69 | 0 | .encode(BigInt::decode(serial_number())) |
70 | 0 | .encode(expire_time()) |
71 | 0 | .start_sequence() |
72 | 0 | .encode(extensions()) |
73 | 0 | .end_cons() |
74 | 0 | .end_cons(); |
75 | 0 | } |
76 | | |
77 | | /* |
78 | | * Decode a BER encoded CRL_Entry |
79 | | */ |
80 | | void CRL_Entry::decode_from(BER_Decoder& source) |
81 | 12.2k | { |
82 | 12.2k | BigInt serial_number_bn; |
83 | | |
84 | 12.2k | auto data = std::make_unique<CRL_Entry_Data>(); |
85 | | |
86 | 12.2k | BER_Decoder entry = source.start_sequence(); |
87 | | |
88 | 12.2k | entry.decode(serial_number_bn).decode(data->m_time); |
89 | 12.2k | data->m_serial = BigInt::encode(serial_number_bn); |
90 | | |
91 | 12.2k | if(entry.more_items()) |
92 | 3.80k | { |
93 | 3.80k | entry.decode(data->m_extensions); |
94 | 3.80k | if(auto ext = data->m_extensions.get_extension_object_as<Cert_Extension::CRL_ReasonCode>()) |
95 | 500 | { |
96 | 500 | data->m_reason = ext->get_reason(); |
97 | 500 | } |
98 | 3.30k | else |
99 | 3.30k | { |
100 | 3.30k | data->m_reason = CRL_Code::UNSPECIFIED; |
101 | 3.30k | } |
102 | 3.80k | } |
103 | | |
104 | 12.2k | entry.end_cons(); |
105 | | |
106 | 12.2k | m_data = std::move(data); |
107 | 12.2k | } |
108 | | |
109 | | const CRL_Entry_Data& CRL_Entry::data() const |
110 | 0 | { |
111 | 0 | if(!m_data) |
112 | 0 | { |
113 | 0 | throw Invalid_State("CRL_Entry_Data uninitialized"); |
114 | 0 | } |
115 | | |
116 | 0 | return *m_data.get(); |
117 | 0 | } |
118 | | |
119 | | const std::vector<uint8_t>& CRL_Entry::serial_number() const |
120 | 0 | { |
121 | 0 | return data().m_serial; |
122 | 0 | } |
123 | | |
124 | | const X509_Time& CRL_Entry::expire_time() const |
125 | 0 | { |
126 | 0 | return data().m_time; |
127 | 0 | } |
128 | | |
129 | | CRL_Code CRL_Entry::reason_code() const |
130 | 0 | { |
131 | 0 | return data().m_reason; |
132 | 0 | } |
133 | | |
134 | | const Extensions& CRL_Entry::extensions() const |
135 | 0 | { |
136 | 0 | return data().m_extensions; |
137 | 0 | } |
138 | | |
139 | | |
140 | | } |