aboutsummaryrefslogtreecommitdiffstats
path: root/misc/python/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-23 01:51:34 +0000
committerlloyd <[email protected]>2006-08-23 01:51:34 +0000
commita2ceb8f50c45e9ba689c10f87a21442684791c12 (patch)
tree7322e1d58d190081eef32e5dbab489c0fd6699a0 /misc/python/src
parent1f14dc6059c70f393f7c8ac04d9fa17637cda3e1 (diff)
Add an implicit conversion from MemoryRegion<byte> to a (hex-encoded)
Python string
Diffstat (limited to 'misc/python/src')
-rw-r--r--misc/python/src/x509.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/misc/python/src/x509.cpp b/misc/python/src/x509.cpp
index 47c458f9e..32960839a 100644
--- a/misc/python/src/x509.cpp
+++ b/misc/python/src/x509.cpp
@@ -35,22 +35,23 @@ class vector_to_list
}
};
-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)
+template<typename T>
+class memvec_to_hexstr
{
- return hex_encode(cert->authority_key_id());
- }
+ public:
+ static PyObject* convert(const T& in)
+ {
+ Pipe pipe(new Hex_Encoder);
+ pipe.process_msg(in);
+ std::string result = pipe.read_all_as_string();
+ return python::incref(python::str(result).ptr());
+ }
-python::str get_subject_keyid(const X509_Certificate* cert)
- {
- return hex_encode(cert->subject_key_id());
- }
+ memvec_to_hexstr()
+ {
+ python::to_python_converter<T, memvec_to_hexstr<T> >();
+ }
+ };
class X509_Store_Search_Wrap : public X509_Store::Search_Func,
public python::wrapper<X509_Store::Search_Func>
@@ -69,6 +70,7 @@ void export_x509()
{
vector_to_list<std::string>();
vector_to_list<X509_Certificate>();
+ memvec_to_hexstr<MemoryVector<byte> >();
python::class_<X509_Certificate>
("X509_Certificate", python::init<std::string>())
@@ -85,8 +87,8 @@ void export_x509()
.def("issuer_info", &X509_Certificate::issuer_info)
.def("ex_constraints", &X509_Certificate::ex_constraints)
.def("policies", &X509_Certificate::policies)
- .def("subject_key_id", get_subject_keyid)
- .def("authority_key_id", get_auth_keyid);
+ .def("subject_key_id", &X509_Certificate::subject_key_id)
+ .def("authority_key_id", &X509_Certificate::authority_key_id);
python::enum_<X509_Code>("verify_result")
.value("verified", VERIFIED)