monotone

monotone Mtn Source Tree

Root/botan/x509find.cpp

1/*************************************************
2* X.509 Certificate Store Searching Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/x509find.h>
7#include <botan/charset.h>
8#include <algorithm>
9
10namespace Botan {
11
12namespace {
13
14/*************************************************
15* Compare based on case-insensive substrings *
16*************************************************/
17bool substring_match(const std::string& searching_for,
18 const std::string& found)
19 {
20 if(std::search(found.begin(), found.end(), searching_for.begin(),
21 searching_for.end(), Charset::caseless_cmp) != found.end())
22 return true;
23 return false;
24 }
25
26/*************************************************
27* Compare based on case-insensive match *
28*************************************************/
29bool ignore_case(const std::string& searching_for, const std::string& found)
30 {
31 if(searching_for.size() != found.size())
32 return false;
33
34 return std::equal(found.begin(), found.end(),
35 searching_for.begin(), Charset::caseless_cmp);
36 }
37
38}
39
40/*************************************************
41* Search based on the contents of a DN entry *
42*************************************************/
43bool DN_Check::match(const X509_Certificate& cert) const
44 {
45 std::vector<std::string> info = cert.subject_info(dn_entry);
46
47 for(u32bit j = 0; j != info.size(); ++j)
48 if(compare(info[j], looking_for))
49 return true;
50 return false;
51 }
52
53/*************************************************
54* DN_Check Constructor *
55*************************************************/
56DN_Check::DN_Check(const std::string& dn_entry, const std::string& looking_for,
57 compare_fn func)
58 {
59 this->dn_entry = dn_entry;
60 this->looking_for = looking_for;
61 compare = func;
62 }
63
64/*************************************************
65* DN_Check Constructor *
66*************************************************/
67DN_Check::DN_Check(const std::string& dn_entry, const std::string& looking_for,
68 Search_Type method)
69 {
70 this->dn_entry = dn_entry;
71 this->looking_for = looking_for;
72
73 if(method == SUBSTRING_MATCHING)
74 compare = &substring_match;
75 else if(method == IGNORE_CASE)
76 compare = &ignore_case;
77 else
78 throw Invalid_Argument("Unknown method argument to DN_Check()");
79 }
80
81/*************************************************
82* Match by issuer and serial number *
83*************************************************/
84bool IandS_Match::match(const X509_Certificate& cert) const
85 {
86 if(cert.serial_number() != serial)
87 return false;
88 return (cert.issuer_dn() == issuer);
89 }
90
91/*************************************************
92* IandS_Match Constructor *
93*************************************************/
94IandS_Match::IandS_Match(const X509_DN& issuer,
95 const MemoryRegion<byte>& serial)
96 {
97 this->issuer = issuer;
98 this->serial = serial;
99 }
100
101/*************************************************
102* Match by subject key identifier *
103*************************************************/
104bool SKID_Match::match(const X509_Certificate& cert) const
105 {
106 return (cert.subject_key_id() == skid);
107 }
108
109}

Archive Download this file

Branches

Tags

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