From 610a3e91b5be1008c5cd314d67fb997fd03c0268 Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 16 May 2011 17:21:26 +0000 Subject: Add RSA constructor that does not require a password. Patch submitted to the list by William Emmanuel S. Yu --- src/wrap/python/rsa.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wrap/python/rsa.cpp b/src/wrap/python/rsa.cpp index 5e2e0ba30..dc6053503 100644 --- a/src/wrap/python/rsa.cpp +++ b/src/wrap/python/rsa.cpp @@ -27,6 +27,8 @@ class Py_RSA_PrivateKey Py_RSA_PrivateKey(std::string pem_str, Python_RandomNumberGenerator& rng, std::string pass); + Py_RSA_PrivateKey(std::string pem_str, + Python_RandomNumberGenerator& rng); Py_RSA_PrivateKey(u32bit bits, Python_RandomNumberGenerator& rng); ~Py_RSA_PrivateKey() { delete rsa_key; } @@ -86,6 +88,21 @@ Py_RSA_PrivateKey::Py_RSA_PrivateKey(u32bit bits, rsa_key = new RSA_PrivateKey(rng.get_underlying_rng(), bits); } +Py_RSA_PrivateKey::Py_RSA_PrivateKey(std::string pem_str, + Python_RandomNumberGenerator& rng) + { + DataSource_Memory in(pem_str); + + Private_Key* pkcs8_key = + PKCS8::load_key(in, + rng.get_underlying_rng()); + + rsa_key = dynamic_cast(pkcs8_key); + + if(!rsa_key) + throw std::invalid_argument("Key is not an RSA key"); + } + Py_RSA_PrivateKey::Py_RSA_PrivateKey(std::string pem_str, Python_RandomNumberGenerator& rng, std::string passphrase) @@ -195,6 +212,7 @@ void export_rsa() python::class_ ("RSA_PrivateKey", python::init()) + .def(python::init()) .def(python::init()) .def("to_string", &Py_RSA_PrivateKey::to_string) .def("to_ber", &Py_RSA_PrivateKey::to_ber) -- cgit v1.2.3