aboutsummaryrefslogtreecommitdiffstats
path: root/src/x509stat.cpp
blob: 25ca197ca56c64f1fdf878e8ed1b9af8b950bfae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*************************************************
* Globally Saved X.509 State                     *
* (C) 1999-2006 The Botan Project                *
*************************************************/

#include <botan/x509stat.h>
#include <botan/x509_ext.h>
#include <botan/oids.h>

namespace Botan {

/*************************************************
* Add a new prototype                            *
*************************************************/
void X509_GlobalState::add(Extension_Prototype* proto)
   {
   if(proto)
      prototypes.push_back(proto);
   }

/*************************************************
* Get an extension object                        *
*************************************************/
Certificate_Extension* X509_GlobalState::get_extension(const OID& oid) const
   {
   Certificate_Extension* extension = 0;
   for(u32bit j = 0; j != prototypes.size() && !extension; ++j)
      extension = prototypes[j]->make(oid);
   return extension;
   }

/*************************************************
* Set up a new global state for X.509            *
*************************************************/
X509_GlobalState::X509_GlobalState()
   {
#define CREATE_PROTOTYPE(TYPE, NAME)                      \
   struct TYPE ## _Prototype : public Extension_Prototype \
      {                                                   \
      Certificate_Extension* make(const OID& oid)         \
         {                                                \
         if(oid == OIDS::lookup(NAME))                    \
            return new Cert_Extension::TYPE();            \
         return 0;                                        \
         }                                                \
      };                                                  \
   add(new TYPE ## _Prototype);

#if 0
   class Basic_Constraints_Prototype : public Extension_Prototype
      {
      public:
         Certificate_Extension* make(const OID& oid)
            {
            if(oid == OIDS::lookup("X509v3.BasicConstraints"))
               return new Cert_Extension::Basic_Constraints();
            return 0;
            }
      };

   add(new Basic_Constraints_Prototype);
#else

   CREATE_PROTOTYPE(Basic_Constraints, "X509v3.BasicConstraints");

#endif
   }

/*************************************************
* Destroy this global state object               *
*************************************************/
X509_GlobalState::~X509_GlobalState()
   {
   for(u32bit j = 0; j != prototypes.size(); ++j)
      delete prototypes[j];
   prototypes.clear();
   }

}