diff options
Diffstat (limited to 'misc/python')
-rw-r--r-- | misc/python/src/x509.cpp | 29 | ||||
-rwxr-xr-x | misc/python/test.py | 6 |
2 files changed, 32 insertions, 3 deletions
diff --git a/misc/python/src/x509.cpp b/misc/python/src/x509.cpp index d2fb3c5e1..f787949de 100644 --- a/misc/python/src/x509.cpp +++ b/misc/python/src/x509.cpp @@ -4,6 +4,8 @@ *************************************************/ #include <botan/oids.h> +#include <botan/pipe.h> +#include <botan/filters.h> #include <botan/x509_key.h> #include <botan/x509cert.h> using namespace Botan; @@ -20,14 +22,31 @@ python::list vector_to_list(const C& in) return out; } +python::str hex_encode(const MemoryRegion<byte>& in) + { + Pipe pipe(new Hex_Encoder); + pipe.process_msg(in); + return python::str(pipe.read_all_as_string()); + } + +python::str get_auth_keyid(const X509_Certificate* cert) + { + return hex_encode(cert->authority_key_id()); + } + +python::str get_subject_keyid(const X509_Certificate* cert) + { + return hex_encode(cert->subject_key_id()); + } + python::list get_subject_info(const X509_Certificate* cert, - const std::string& type) + const std::string& type) { return vector_to_list(cert->subject_info(type)); } python::list get_issuer_info(const X509_Certificate* cert, - const std::string& type) + const std::string& type) { return vector_to_list(cert->issuer_info(type)); } @@ -46,6 +65,8 @@ void export_x509() { python::class_<X509_Certificate> ("X509_Certificate", python::init<std::string>()) + .def(python::self == python::self) + .def(python::self != python::self) .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) @@ -55,5 +76,7 @@ void export_x509() .def("subject_info", get_subject_info) .def("issuer_info", get_issuer_info) .def("ex_constraints", get_ex_constraints) - .def("policies", get_policies); + .def("policies", get_policies) + .def("subject_key_id", get_subject_keyid) + .def("authority_key_id", get_auth_keyid); } diff --git a/misc/python/test.py b/misc/python/test.py index b20239308..f6f834003 100755 --- a/misc/python/test.py +++ b/misc/python/test.py @@ -26,6 +26,12 @@ def main(): print cert.issuer_info("X520.OrganizationalUnit") print cert.policies() print cert.ex_constraints() + print cert.subject_key_id() + + cert2 = botan.X509_Certificate("cert.crt") + cert3 = botan.X509_Certificate("cert.pem") + cert4 = botan.X509_Certificate("cert2.crt") + print cert2 == cert4 if __name__ == "__main__": sys.exit(main()) |