Botan  2.1.0
Crypto and TLS for C++11
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 #include <botan/oids.h>
15 
16 namespace Botan {
17 
18 /*
19 * Create a CRL_Entry
20 */
21 CRL_Entry::CRL_Entry(bool t_on_unknown_crit) :
22  m_throw_on_unknown_critical(t_on_unknown_crit)
23  {
24  m_reason = UNSPECIFIED;
25  }
26 
27 /*
28 * Create a CRL_Entry
29 */
31  m_throw_on_unknown_critical(false)
32  {
33  m_serial = cert.serial_number();
34  m_time = X509_Time(std::chrono::system_clock::now());
35  m_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 */
64  {
65  Extensions extensions;
66 
67  extensions.add(new Cert_Extension::CRL_ReasonCode(m_reason));
68 
69  der.start_cons(SEQUENCE)
70  .encode(BigInt::decode(m_serial))
71  .encode(m_time)
73  .encode(extensions)
74  .end_cons()
75  .end_cons();
76  }
77 
78 /*
79 * Decode a BER encoded CRL_Entry
80 */
82  {
83  BigInt serial_number_bn;
84  m_reason = UNSPECIFIED;
85 
86  BER_Decoder entry = source.start_cons(SEQUENCE);
87 
88  entry.decode(serial_number_bn).decode(m_time);
89 
90  if(entry.more_items())
91  {
92  Extensions extensions(m_throw_on_unknown_critical);
93  entry.decode(extensions);
94  Data_Store info;
95  extensions.contents_to(info, info);
96  m_reason = CRL_Code(info.get1_uint32("X509v3.CRLReasonCode"));
97  }
98 
99  entry.end_cons();
100 
101  m_serial = BigInt::encode(serial_number_bn);
102  }
103 
104 }
std::vector< uint8_t > serial_number() const
Definition: x509cert.cpp:427
uint32_t get1_uint32(const std::string &, uint32_t=0) const
Definition: datastor.cpp:109
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:82
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:67
std::vector< uint8_t > serial_number() const
Definition: crl_ent.h:50
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:376
void contents_to(Data_Store &, Data_Store &) const
Definition: x509_ext.cpp:254
DER_Encoder & end_cons()
Definition: der_enc.cpp:147
void decode_from(class BER_Decoder &) override
Definition: crl_ent.cpp:81
void add(Certificate_Extension *extn, bool critical=false)
Definition: x509_ext.cpp:91
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:216
BER_Decoder & end_cons()
Definition: ber_dec.cpp:272
bool more_items() const
Definition: ber_dec.cpp:158
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: ber_dec.cpp:258
Definition: alg_id.cpp:13
Definition: crl_ent.h:40
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:137
X509_Time expire_time() const
Definition: crl_ent.h:56
CRL_Code
Definition: crl_ent.h:20
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:54
CRL_Code reason_code() const
Definition: crl_ent.h:62
CRL_Entry(bool throw_on_unknown_critical_extension=false)
Definition: crl_ent.cpp:21
void encode_into(class DER_Encoder &) const override
Definition: crl_ent.cpp:63
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:114