Botan  1.10.9
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 */
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 */
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)
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  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 }
bool operator!=(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:106
BER_Decoder & decode(bool &)
Definition: ber_dec.cpp:338
bool operator==(const OctetString &s1, const OctetString &s2)
Definition: symkey.cpp:98
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:64
void contents_to(Data_Store &, Data_Store &) const
Definition: x509_ext.cpp:150
DER_Encoder & end_cons()
Definition: der_enc.cpp:145
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
Definition: ber_dec.cpp:232
void encode_into(class DER_Encoder &) const
Definition: crl_ent.cpp:63
void add(Certificate_Extension *extn, bool critical=false)
Definition: x509_ext.cpp:77
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:209
BER_Decoder & end_cons()
Definition: ber_dec.cpp:246
bool more_items() const
Definition: ber_dec.cpp:150
Definition: crl_ent.h:18
MemoryVector< byte > serial_number() const
Definition: x509cert.cpp:266
u32bit get1_u32bit(const std::string &, u32bit=0) const
Definition: datastor.cpp:120
static BigInt decode(const byte buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:102
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:135
X509_Time expire_time() const
Definition: crl_ent.h:34
MemoryVector< byte > serial_number() const
Definition: crl_ent.h:28
CRL_Code reason_code() const
Definition: crl_ent.h:40
CRL_Entry(bool throw_on_unknown_critical_extension=false)
Definition: crl_ent.cpp:21
void decode_from(class BER_Decoder &)
Definition: crl_ent.cpp:81
u64bit system_time()
Definition: time.cpp:73