Botan
3.6.1
Crypto and TLS for C&
src
lib
x509
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
16
namespace
Botan
{
17
18
struct
CRL_Entry_Data {
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
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
*/
42
bool
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
*/
58
bool
operator!=
(
const
CRL_Entry
& a1,
const
CRL_Entry
& a2) {
59
return
!(a1 == a2);
60
}
61
62
/*
63
* DER encode a CRL_Entry
64
*/
65
void
CRL_Entry::encode_into
(
DER_Encoder
& der)
const
{
66
der.
start_sequence
()
67
.
encode
(
BigInt::from_bytes
(
serial_number
()))
68
.
encode
(
expire_time
())
69
.
start_sequence
()
70
.
encode
(
extensions
())
71
.
end_cons
()
72
.
end_cons
();
73
}
74
75
/*
76
* Decode a BER encoded CRL_Entry
77
*/
78
void
CRL_Entry::decode_from
(
BER_Decoder
& source) {
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
102
const
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
110
const
std::vector<uint8_t>&
CRL_Entry::serial_number
()
const
{
111
return
data().m_serial;
112
}
113
114
const
X509_Time
&
CRL_Entry::expire_time
()
const
{
115
return
data().m_time;
116
}
117
118
CRL_Code
CRL_Entry::reason_code
()
const
{
119
return
data().m_reason;
120
}
121
122
const
Extensions
&
CRL_Entry::extensions
()
const
{
123
return
data().m_extensions;
124
}
125
126
}
// namespace Botan
Botan::ASN1_Time
Definition
asn1_obj.h:348
Botan::BER_Decoder
Definition
ber_dec.h:22
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition
ber_dec.h:186
Botan::BER_Decoder::more_items
bool more_items() const
Definition
ber_dec.cpp:201
Botan::BER_Decoder::end_cons
BER_Decoder & end_cons()
Definition
ber_dec.cpp:309
Botan::BER_Decoder::start_sequence
BER_Decoder start_sequence()
Definition
ber_dec.h:123
Botan::BigInt
Definition
bigint.h:26
Botan::BigInt::from_bytes
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition
bigint.cpp:95
Botan::BigInt::serialize
T serialize(size_t len) const
Definition
bigint.h:712
Botan::CRL_Entry
Definition
x509_crl.h:28
Botan::CRL_Entry::reason_code
CRL_Code reason_code() const
Definition
crl_ent.cpp:118
Botan::CRL_Entry::expire_time
const X509_Time & expire_time() const
Definition
crl_ent.cpp:114
Botan::CRL_Entry::CRL_Entry
CRL_Entry()=default
Botan::CRL_Entry::serial_number
const std::vector< uint8_t > & serial_number() const
Definition
crl_ent.cpp:110
Botan::CRL_Entry::decode_from
void decode_from(BER_Decoder &) override
Definition
crl_ent.cpp:78
Botan::CRL_Entry::encode_into
void encode_into(DER_Encoder &) const override
Definition
crl_ent.cpp:65
Botan::CRL_Entry::extensions
const Extensions & extensions() const
Definition
crl_ent.cpp:122
Botan::Cert_Extension::CRL_ReasonCode
Definition
x509_ext.h:368
Botan::DER_Encoder
Definition
der_enc.h:22
Botan::DER_Encoder::start_sequence
DER_Encoder & start_sequence()
Definition
der_enc.h:64
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition
der_enc.cpp:171
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition
der_enc.cpp:250
Botan::Extensions
Definition
pkix_types.h:465
Botan::Extensions::get_extension_object_as
const T * get_extension_object_as(const OID &oid=T::static_oid()) const
Definition
pkix_types.h:477
Botan::Invalid_State
Definition
exceptn.h:206
Botan::X509_Certificate
Definition
x509cert.h:36
Botan::X509_Certificate::serial_number
const std::vector< uint8_t > & serial_number() const
Definition
x509cert.cpp:383
Botan
Definition
alg_id.cpp:13
Botan::X509_Time
ASN1_Time X509_Time
Definition
asn1_obj.h:409
Botan::CRL_Code
CRL_Code
Definition
pkix_enums.h:187
Botan::CRL_Code::Unspecified
@ Unspecified
Botan::operator!=
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition
alg_id.cpp:69
Botan::operator==
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition
alg_id.cpp:54
Generated by
1.12.0