monotone

monotone Mtn Source Tree

Root/botan/crl_ent.cpp

1/*************************************************
2* CRL Entry Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/crl_ent.h>
7#include <botan/x509_ext.h>
8#include <botan/der_enc.h>
9#include <botan/ber_dec.h>
10#include <botan/bigint.h>
11#include <botan/config.h>
12#include <botan/oids.h>
13#include <botan/util.h>
14
15namespace Botan {
16
17/*************************************************
18* Create a CRL_Entry *
19*************************************************/
20CRL_Entry::CRL_Entry()
21 {
22 reason = UNSPECIFIED;
23 }
24
25/*************************************************
26* Create a CRL_Entry *
27*************************************************/
28CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why)
29 {
30 serial = cert.serial_number();
31 time = X509_Time(system_time());
32 reason = why;
33 }
34
35/*************************************************
36* Compare two CRL_Entrys for equality *
37*************************************************/
38bool operator==(const CRL_Entry& a1, const CRL_Entry& a2)
39 {
40 if(a1.serial_number() != a2.serial_number())
41 return false;
42 if(a1.expire_time() != a2.expire_time())
43 return false;
44 if(a1.reason_code() != a2.reason_code())
45 return false;
46 return true;
47 }
48
49/*************************************************
50* Compare two CRL_Entrys for inequality *
51*************************************************/
52bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2)
53 {
54 return !(a1 == a2);
55 }
56
57/*************************************************
58* Compare two CRL_Entrys *
59*************************************************/
60bool operator<(const CRL_Entry& a1, const CRL_Entry& a2)
61 {
62 return (a1.expire_time().cmp(a2.expire_time()) < 0);
63 }
64
65/*************************************************
66* DER encode a CRL_Entry *
67*************************************************/
68void CRL_Entry::encode_into(DER_Encoder& der) const
69 {
70 Extensions extensions;
71
72 extensions.add(new Cert_Extension::CRL_ReasonCode(reason));
73
74 der.start_cons(SEQUENCE)
75 .encode(BigInt::decode(serial, serial.size()))
76 .encode(time)
77 .encode(extensions)
78 .end_cons();
79 }
80
81/*************************************************
82* Decode a BER encoded CRL_Entry *
83*************************************************/
84void CRL_Entry::decode_from(BER_Decoder& source)
85 {
86 BigInt serial_number_bn;
87
88 source.start_cons(SEQUENCE)
89 .decode(serial_number_bn)
90 .decode(time);
91
92 if(source.more_items())
93 {
94 std::string action =
95 global_config().option("x509/crl/unknown_critical");
96
97 if(action != "throw" && action != "ignore")
98 throw Invalid_Argument("Bad setting x509/crl/unknown_critical: "
99 + action);
100
101 Extensions extensions(action == "throw");
102 source.decode(extensions);
103 Data_Store info;
104 extensions.contents_to(info, info);
105 reason = CRL_Code(info.get1_u32bit("X509v3.CRLReasonCode"));
106 }
107
108 serial = BigInt::encode(serial_number_bn);
109 }
110
111}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status