Coverage Report

Created: 2020-05-23 13:54

/src/botan/src/lib/x509/crl_ent.cpp
Line
Count
Source (jump to first uncovered line)
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
15
namespace Botan {
16
17
struct CRL_Entry_Data
18
   {
19
   std::vector<uint8_t> m_serial;
20
   X509_Time m_time;
21
   CRL_Code m_reason = UNSPECIFIED;
22
   Extensions m_extensions;
23
   };
24
25
/*
26
* Create a CRL_Entry
27
*/
28
CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why)
29
0
   {
30
0
   m_data.reset(new CRL_Entry_Data);
31
0
   m_data->m_serial = cert.serial_number();
32
0
   m_data->m_time = X509_Time(std::chrono::system_clock::now());
33
0
   m_data->m_reason = why;
34
0
35
0
   if(why != UNSPECIFIED)
36
0
      {
37
0
      m_data->m_extensions.add(new Cert_Extension::CRL_ReasonCode(why));
38
0
      }
39
0
   }
40
41
/*
42
* Compare two CRL_Entrys for equality
43
*/
44
bool operator==(const CRL_Entry& a1, const CRL_Entry& a2)
45
0
   {
46
0
   if(a1.serial_number() != a2.serial_number())
47
0
      return false;
48
0
   if(a1.expire_time() != a2.expire_time())
49
0
      return false;
50
0
   if(a1.reason_code() != a2.reason_code())
51
0
      return false;
52
0
   return true;
53
0
   }
54
55
/*
56
* Compare two CRL_Entrys for inequality
57
*/
58
bool operator!=(const CRL_Entry& a1, const CRL_Entry& a2)
59
0
   {
60
0
   return !(a1 == a2);
61
0
   }
62
63
/*
64
* DER encode a CRL_Entry
65
*/
66
void CRL_Entry::encode_into(DER_Encoder& der) const
67
0
   {
68
0
   der.start_cons(SEQUENCE)
69
0
      .encode(BigInt::decode(serial_number()))
70
0
      .encode(expire_time())
71
0
      .start_cons(SEQUENCE)
72
0
         .encode(extensions())
73
0
      .end_cons()
74
0
   .end_cons();
75
0
   }
76
77
/*
78
* Decode a BER encoded CRL_Entry
79
*/
80
void CRL_Entry::decode_from(BER_Decoder& source)
81
11.3k
   {
82
11.3k
   BigInt serial_number_bn;
83
11.3k
84
11.3k
   std::unique_ptr<CRL_Entry_Data> data(new CRL_Entry_Data);
85
11.3k
86
11.3k
   BER_Decoder entry = source.start_cons(SEQUENCE);
87
11.3k
88
11.3k
   entry.decode(serial_number_bn).decode(data->m_time);
89
11.3k
   data->m_serial = BigInt::encode(serial_number_bn);
90
11.3k
91
11.3k
   if(entry.more_items())
92
3.42k
      {
93
3.42k
      entry.decode(data->m_extensions);
94
3.42k
      if(auto ext = data->m_extensions.get_extension_object_as<Cert_Extension::CRL_ReasonCode>())
95
976
         {
96
976
         data->m_reason = ext->get_reason();
97
976
         }
98
2.44k
      else
99
2.44k
         {
100
2.44k
         data->m_reason = UNSPECIFIED;
101
2.44k
         }
102
3.42k
      }
103
11.3k
104
11.3k
   entry.end_cons();
105
11.3k
106
11.3k
   m_data.reset(data.release());
107
11.3k
   }
108
109
const CRL_Entry_Data& CRL_Entry::data() const
110
0
   {
111
0
   if(!m_data)
112
0
      {
113
0
      throw Invalid_State("CRL_Entry_Data uninitialized");
114
0
      }
115
0
116
0
   return *m_data.get();
117
0
   }
118
119
const std::vector<uint8_t>& CRL_Entry::serial_number() const
120
0
   {
121
0
   return data().m_serial;
122
0
   }
123
124
const X509_Time& CRL_Entry::expire_time() const
125
0
   {
126
0
   return data().m_time;
127
0
   }
128
129
CRL_Code CRL_Entry::reason_code() const
130
0
   {
131
0
   return data().m_reason;
132
0
   }
133
134
const Extensions& CRL_Entry::extensions() const
135
0
   {
136
0
   return data().m_extensions;
137
0
   }
138
139
140
}