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
10namespace Botan {
11
16
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
28std::vector<X509_Certificate>
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
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
74std::vector<X509_CRL>
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}
void add_certificate(const X509_Certificate &cert)
Definition certstor.cpp:17
Certificate_Store * clone() const
Definition certstor.cpp:12
void add_crl(const X509_CRL &crl)
Definition certstor.cpp:53
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
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
size_t size() const
Definition secmem.h:29
X509_DN issuer_dn() const
Definition x509_crl.cpp:110
X509_Time this_update() const
Definition x509_crl.cpp:134