aboutsummaryrefslogtreecommitdiffstats
path: root/misc/python/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-22 23:09:36 +0000
committerlloyd <[email protected]>2006-08-22 23:09:36 +0000
commitad2419f0168b9fe041da5c82941ef55181098646 (patch)
tree267fed977b7cbfa070d653e550230d03eaab5f0a /misc/python/src
parentae1296f866ab4ead46c08c0467ec967a4de73d5e (diff)
Start code for wrapping X.509 certificates in Python
Diffstat (limited to 'misc/python/src')
-rw-r--r--misc/python/src/x509.cpp63
1 files changed, 61 insertions, 2 deletions
diff --git a/misc/python/src/x509.cpp b/misc/python/src/x509.cpp
index dc462f48b..0107c6bf9 100644
--- a/misc/python/src/x509.cpp
+++ b/misc/python/src/x509.cpp
@@ -6,10 +6,69 @@
#include <boost/python.hpp>
using namespace boost::python;
+#include <botan/oids.h>
#include <botan/x509_key.h>
+#include <botan/x509cert.h>
+using namespace Botan;
+
+template<typename C>
+list vector_to_list(const C& in)
+ {
+ list out;
+ typename C::const_iterator i = in.begin();
+ while(i != in.end()) { out.append(*i); ++i; }
+ return out;
+ }
+
+template<typename C>
+std::vector<std::string> oid_lookup(const C& in)
+ {
+ std::vector<std::string> out;
+ typename C::const_iterator i = in.begin();
+ while(i != in.end())
+ {
+ OID oid(*i);
+ std::string string_rep = OIDS::lookup(oid);
+
+ out.push_back(OIDS::lookup(oid));
+ ++i;
+ }
+ return out;
+ }
+
+list get_subject_info(const X509_Certificate* cert,
+ const std::string& type)
+ {
+ return vector_to_list(cert->subject_info(type));
+ }
+
+list get_issuer_info(const X509_Certificate* cert,
+ const std::string& type)
+ {
+ return vector_to_list(cert->issuer_info(type));
+ }
+
+list get_policies(const X509_Certificate* cert)
+ {
+ return vector_to_list(cert->policies());
+ }
+
+list get_ex_constraints(const X509_Certificate* cert)
+ {
+ return vector_to_list(oid_lookup(cert->ex_constraints()));
+ }
void export_x509()
{
- class_<X509_PublicKey>("x509_key", no_init)
- .def(
+ class_<X509_Certificate>("X509_Certificate", init<std::string>())
+ .add_property("version", &X509_Certificate::x509_version)
+ .add_property("is_CA", &X509_Certificate::is_CA_cert)
+ .add_property("self_signed", &X509_Certificate::is_self_signed)
+ .add_property("pathlimit", &X509_Certificate::path_limit)
+ .def("start_time", &X509_Certificate::start_time)
+ .def("end_time", &X509_Certificate::end_time)
+ .def("subject_info", get_subject_info)
+ .def("issuer_info", get_issuer_info)
+ .def("ex_constraints", get_ex_constraints)
+ .def("policies", get_policies);
}