Botan: src/cert/x509crl/crl_ent.cpp Source File

Botan 1.10.16

crl_ent.cpp
Go to the documentation of this file.
1 /*
2 * CRL Entry
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/crl_ent.h>
9 #include <botan/x509_ext.h>
10 #include <botan/der_enc.h>
11 #include <botan/ber_dec.h>
12 #include <botan/bigint.h>
13 #include <botan/oids.h>
14 #include <botan/time.h>
15
16 namespace Botan {
17
18 /*
19 * Create a CRL_Entry
20 */
21 CRL_Entry::CRL_Entry(bool t_on_unknown_crit) :
22 throw_on_unknown_critical(t_on_unknown_crit)
23 {
24 reason = UNSPECIFIED;
25 }
26
27 /*
28 * Create a CRL_Entry
29 */
30 CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why) :
31 throw_on_unknown_critical(false)
32 {
33 serial = cert.serial_number();
34 time = X509_Time(system_time());
35 reason = why;
36 }
37
38 /*
39 * Compare two CRL_Entrys for equality
40 */
41 bool operator==(const CRL_Entry& a1, const CRL_Entry& a2)
42 {
43 if(a1.serial_number() != a2.serial_number())
44 return false;
45 if(a1.expire_time() != a2.expire_time())
46 return false;
47 if(a1.reason_code() != a2.reason_code())
48 return false;
49 return true;
50 }
51
52 /*
53 * Compare two CRL_Entrys for inequality
54 */
55 bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2)
56 {
57 return !(a1 == a2);
58 }
59
60 /*
61 * DER encode a CRL_Entry
62 */
63 void CRL_Entry::encode_into(DER_Encoder& der) const
64 {
65 Extensions extensions;
66
67 extensions.add(new Cert_Extension::CRL_ReasonCode(reason));
68
69 der.start_cons(SEQUENCE)
70 .encode(BigInt::decode(serial))
71 .encode(time)
72 .start_cons(SEQUENCE)
73 .encode(extensions)
74 .end_cons()
75 .end_cons();
76 }
77
78 /*
79 * Decode a BER encoded CRL_Entry
80 */
81 void CRL_Entry::decode_from(BER_Decoder& source)
82 {
83 BigInt serial_number_bn;
84 reason = UNSPECIFIED;
85
86 BER_Decoder entry = source.start_cons(SEQUENCE);
87
88 entry.decode(serial_number_bn).decode(time);
89
90 if(entry.more_items())
91 {
92 Extensions extensions(throw_on_unknown_critical);
93 entry.decode(extensions);
94 Data_Store info;
95 extensions.contents_to(info, info);
96 reason = CRL_Code(info.get1_u32bit("X509v3.CRLReasonCode"));
97 }
98
99 entry.end_cons();
100
101 serial = BigInt::encode(serial_number_bn);
102 }
103
104 }
Botan::operator!=
bool operator!=(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:106
Botan::BigInt
Definition: bigint.h:22
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &)
Definition: ber_dec.cpp:344
Botan::CRL_Entry::encode_into
void encode_into(class DER_Encoder &) const
Definition: crl_ent.cpp:63
Botan::operator==
bool operator==(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:98
Botan::UNSPECIFIED
Definition: pubkey_enums.h:44
Botan::Extensions
Definition: x509_ext.h:66
Botan::BigInt::encode
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:64
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:145
Botan::BER_Decoder::start_cons
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
Definition: ber_dec.cpp:238
Botan::Cert_Extension::CRL_ReasonCode
Definition: x509_ext.h:316
Botan::Extensions::add
void add(Certificate_Extension *extn, bool critical=false)
Definition: x509_ext.cpp:77
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:209
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::X509_Certificate
Definition: x509cert.h:23
Botan::BER_Decoder::end_cons
BER_Decoder & end_cons()
Definition: ber_dec.cpp:252
Botan::CRL_Entry::expire_time
X509_Time expire_time() const
Definition: crl_ent.h:34
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::CRL_Entry::serial_number
MemoryVector< byte > serial_number() const
Definition: crl_ent.h:28
Botan
Definition: algo_base.h:14
Botan::CRL_Entry
Definition: crl_ent.h:18
Botan::Extensions::contents_to
void contents_to(Data_Store &, Data_Store &) const
Definition: x509_ext.cpp:150
Botan::Data_Store
Definition: datastor.h:22
Botan::CRL_Entry::reason_code
CRL_Code reason_code() const
Definition: crl_ent.h:40
Botan::X509_Certificate::serial_number
MemoryVector< byte > serial_number() const
Definition: x509cert.cpp:266
Botan::BigInt::decode
static BigInt decode(const byte buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:102
Botan::Data_Store::get1_u32bit
u32bit get1_u32bit(const std::string &, u32bit=0) const
Definition: datastor.cpp:120
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:135
Botan::CRL_Code
CRL_Code
Definition: pubkey_enums.h:43
Botan::CRL_Entry::CRL_Entry
CRL_Entry(bool throw_on_unknown_critical_extension=false)
Definition: crl_ent.cpp:21
Botan::BER_Decoder::more_items
bool more_items() const
Definition: ber_dec.cpp:153
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::CRL_Entry::decode_from
void decode_from(class BER_Decoder &)
Definition: crl_ent.cpp:81
Botan::system_time
u64bit system_time()
Definition: time.cpp:73
Botan::X509_Time
Definition: asn1_obj.h:41