monotone

monotone Mtn Source Tree

Root/botan/crl_ent.cpp

1/*************************************************
2* CRL Entry Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/crl_ent.h>
7#include <botan/asn1.h>
8#include <botan/conf.h>
9#include <botan/oids.h>
10#include <botan/x509_crl.h>
11#include <botan/util.h>
12
13namespace Botan {
14
15/*************************************************
16* Create a CRL_Entry *
17*************************************************/
18CRL_Entry::CRL_Entry()
19 {
20 reason = UNSPECIFIED;
21 }
22
23/*************************************************
24* Create a CRL_Entry *
25*************************************************/
26CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why)
27 {
28 serial = cert.serial_number();
29 time = X509_Time(system_time());
30 reason = why;
31 }
32
33/*************************************************
34* Compare two CRL_Entrys for equality *
35*************************************************/
36bool operator==(const CRL_Entry& a1, const CRL_Entry& a2)
37 {
38 if(a1.serial != a2.serial)
39 return false;
40 if(a1.time != a2.time)
41 return false;
42 if(a1.reason != a2.reason)
43 return false;
44 return true;
45 }
46
47/*************************************************
48* Compare two CRL_Entrys for inequality *
49*************************************************/
50bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2)
51 {
52 return !(a1 == a2);
53 }
54
55/*************************************************
56* Compare two CRL_Entrys *
57*************************************************/
58bool operator<(const CRL_Entry& a1, const CRL_Entry& a2)
59 {
60 return (a1.time.cmp(a2.time) < 0);
61 }
62
63namespace DER {
64
65/*************************************************
66* DER encode an CRL_Entry *
67*************************************************/
68void encode(DER_Encoder& encoder, const CRL_Entry& crl_ent)
69 {
70 encoder.start_sequence();
71 DER::encode(encoder, BigInt::decode(crl_ent.serial, crl_ent.serial.size()));
72 DER::encode(encoder, crl_ent.time);
73
74 encoder.start_sequence();
75 if(crl_ent.reason != UNSPECIFIED)
76 {
77 DER_Encoder v2_ext;
78 DER::encode(v2_ext, (u32bit)crl_ent.reason, ENUMERATED, UNIVERSAL);
79 DER::encode(encoder,
80 Extension("X509v3.ReasonCode", v2_ext.get_contents()));
81 }
82 encoder.end_sequence();
83
84 encoder.end_sequence();
85 }
86
87}
88
89namespace BER {
90
91namespace {
92
93/*************************************************
94* Decode a CRL entry extension *
95*************************************************/
96void handle_crl_entry_extension(CRL_Entry& crl_ent, const Extension& extn)
97 {
98 BER_Decoder value(extn.value);
99
100 if(extn.oid == OIDS::lookup("X509v3.ReasonCode"))
101 {
102 u32bit reason_code;
103 BER::decode(value, reason_code, ENUMERATED, UNIVERSAL);
104 crl_ent.reason = CRL_Code(reason_code);
105 }
106 else
107 {
108 if(extn.critical)
109 {
110 std::string action = Config::get_string("x509/crl/unknown_critical");
111 if(action == "throw")
112 throw Decoding_Error("Unknown critical CRL entry extension " +
113 extn.oid.as_string());
114 else if(action != "ignore")
115 throw Invalid_Argument("Bad value of x509/crl/unknown_critical: "
116 + action);
117 }
118 return;
119 }
120
121 value.verify_end();
122 }
123
124}
125
126/*************************************************
127* Decode a BER encoded CRL_Entry *
128*************************************************/
129void decode(BER_Decoder& source, CRL_Entry& crl_ent)
130 {
131 BigInt serial_number;
132
133 BER_Decoder sequence = BER::get_subsequence(source);
134 BER::decode(sequence, serial_number);
135 crl_ent.serial = BigInt::encode(serial_number);
136 BER::decode(sequence, crl_ent.time);
137
138 if(sequence.more_items())
139 {
140 BER_Decoder crl_entry_exts = BER::get_subsequence(sequence);
141 while(crl_entry_exts.more_items())
142 {
143 Extension extn;
144 BER::decode(crl_entry_exts, extn);
145 handle_crl_entry_extension(crl_ent, extn);
146 }
147 }
148
149 sequence.verify_end();
150 }
151
152}
153
154}

Archive Download this file

Branches

Tags

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