Botan 1.10.17

certstor.cpp
Go to the documentation of this file.
1 /*
2 * Certificate Store
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/certstor.h>
9
10 namespace Botan {
11
12 Certificate_Store* Certificate_Store_Memory::clone() const
13 {
14 return new Certificate_Store_Memory(*this);
15 }
16
17 void Certificate_Store_Memory::add_certificate(const X509_Certificate& cert)
18 {
19 for(size_t i = 0; i != certs.size(); ++i)
20 {
21 if(certs[i] == cert)
22 return;
23 }
24
25 certs.push_back(cert);
26 }
27
28 std::vector<X509_Certificate>
29 Certificate_Store_Memory::find_cert_by_subject_and_key_id(
30 const X509_DN& subject_dn,
31 const MemoryRegion<byte>& key_id) const
32 {
33 std::vector<X509_Certificate> result;
34
35 for(size_t i = 0; i != certs.size(); ++i)
36 {
37 // Only compare key ids if set in both call and in the cert
38 if(key_id.size())
39 {
40 MemoryVector<byte> skid = certs[i].subject_key_id();
41
42 if(skid.size() && skid != key_id) // no match
43 continue;
44 }
45
46 if(certs[i].subject_dn() == subject_dn)
47 result.push_back(certs[i]);
48 }
49
50 return result;
51 }
52
53 void Certificate_Store_Memory::add_crl(const X509_CRL& crl)
54 {
55 X509_DN crl_issuer = crl.issuer_dn();
56
57 for(size_t i = 0; i != crls.size(); ++i)
58 {
59 // Found an update of a previously existing one; replace it
60 if(crls[i].issuer_dn() == crl_issuer)
61 {
62 if(crls[i].this_update() < crl.this_update())
63 {
64 crls[i] = crl;
65 return;
66 }
67 }
68 }
69
70 // Totally new CRL, add to the list
71 crls.push_back(crl);
72 }
73
74 std::vector<X509_CRL>
75 Certificate_Store_Memory::find_crl_by_subject_and_key_id(
76 const X509_DN& issuer_dn,
77 const MemoryRegion<byte>& key_id) const
78 {
79 std::vector<X509_CRL> result;
80
81 for(size_t i = 0; i != crls.size(); ++i)
82 {
83 // Only compare key ids if set in both call and in the CRL
84 if(key_id.size())
85 {
86 MemoryVector<byte> akid = crls[i].authority_key_id();
87
88 if(akid.size() && akid != key_id) // no match
89 continue;
90 }
91
92 if(crls[i].issuer_dn() == issuer_dn)
93 result.push_back(crls[i]);
94 }
95
96 return result;
97 }
98
99 }
Botan::Certificate_Store_Memory::add_crl
void add_crl(const X509_CRL &crl)
Definition: certstor.cpp:53
Botan::X509_CRL::this_update
X509_Time this_update() const
Definition: x509_crl.cpp:134
Botan::Certificate_Store_Memory::Certificate_Store_Memory
Certificate_Store_Memory()
Definition: certstor.h:73
Botan::X509_CRL::issuer_dn
X509_DN issuer_dn() const
Definition: x509_crl.cpp:110
Botan::X509_Certificate
Definition: x509cert.h:23
Botan::Certificate_Store_Memory::find_crl_by_subject_and_key_id
std::vector< X509_CRL > find_crl_by_subject_and_key_id(const X509_DN &issuer_dn, const MemoryRegion< byte > &key_id) const
Definition: certstor.cpp:75
Botan::X509_DN
Definition: x509_dn.h:21
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::MemoryVector< byte >
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::Certificate_Store_Memory::clone
Certificate_Store * clone() const
Definition: certstor.cpp:12
Botan::X509_CRL
Definition: x509_crl.h:20
Botan::Certificate_Store
Definition: certstor.h:19
Botan::Certificate_Store_Memory::find_cert_by_subject_and_key_id
std::vector< X509_Certificate > find_cert_by_subject_and_key_id(const X509_DN &subject_dn, const MemoryRegion< byte > &key_id) const
Definition: certstor.cpp:29
Botan::Certificate_Store_Memory::add_certificate
void add_certificate(const X509_Certificate &cert)
Definition: certstor.cpp:17