monotone

monotone Mtn Source Tree

Root/botan/x509stat.cpp

1/*************************************************
2* Globally Saved X.509 State Source *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/x509stat.h>
7#include <botan/x509_ext.h>
8#include <botan/oids.h>
9
10namespace Botan {
11
12/*************************************************
13* Add a new prototype *
14*************************************************/
15void X509_GlobalState::add(Extension_Prototype* proto)
16 {
17 if(proto)
18 prototypes.push_back(proto);
19 }
20
21/*************************************************
22* Get an extension object *
23*************************************************/
24Certificate_Extension* X509_GlobalState::get_extension(const OID& oid) const
25 {
26 Certificate_Extension* extension = 0;
27 for(u32bit j = 0; j != prototypes.size() && !extension; ++j)
28 extension = prototypes[j]->make(oid);
29 return extension;
30 }
31
32/*************************************************
33* Set up a new global state for X.509 *
34*************************************************/
35X509_GlobalState::X509_GlobalState()
36 {
37
38#define CREATE_PROTOTYPE(NAME, TYPE) \
39 do { \
40 struct TYPE ## _Prototype : public Extension_Prototype \
41 { \
42 Certificate_Extension* make(const OID& oid) \
43 { \
44 if(OIDS::name_of(oid, NAME)) \
45 return new Cert_Extension::TYPE(); \
46 return 0; \
47 } \
48 }; \
49 \
50 add(new TYPE ## _Prototype); \
51 } while(0);
52
53 CREATE_PROTOTYPE("X509v3.KeyUsage", Key_Usage);
54 CREATE_PROTOTYPE("X509v3.BasicConstraints", Basic_Constraints);
55 CREATE_PROTOTYPE("X509v3.SubjectKeyIdentifier", Subject_Key_ID);
56 CREATE_PROTOTYPE("X509v3.AuthorityKeyIdentifier", Authority_Key_ID);
57 CREATE_PROTOTYPE("X509v3.ExtendedKeyUsage", Extended_Key_Usage);
58 CREATE_PROTOTYPE("X509v3.IssuerAlternativeName", Issuer_Alternative_Name);
59 CREATE_PROTOTYPE("X509v3.SubjectAlternativeName", Subject_Alternative_Name);
60 CREATE_PROTOTYPE("X509v3.CRLNumber", CRL_Number);
61 CREATE_PROTOTYPE("X509v3.CertificatePolicies", Certificate_Policies);
62
63#undef CREATE_PROTOTYPE
64 }
65
66/*************************************************
67* Destroy this global state object *
68*************************************************/
69X509_GlobalState::~X509_GlobalState()
70 {
71 for(u32bit j = 0; j != prototypes.size(); ++j)
72 delete prototypes[j];
73 prototypes.clear();
74 }
75
76}

Archive Download this file

Branches

Tags

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