diff options
author | lloyd <[email protected]> | 2011-05-16 17:21:26 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-05-16 17:21:26 +0000 |
commit | 610a3e91b5be1008c5cd314d67fb997fd03c0268 (patch) | |
tree | 129294b93da08bccf293796b48df3bb985901a0d /src/wrap | |
parent | 3c0e96e6555b0e658684e55f4c23ca21fd6f3a19 (diff) |
Add RSA constructor that does not require a password. Patch submitted
to the list by William Emmanuel S. Yu <[email protected]>
Diffstat (limited to 'src/wrap')
-rw-r--r-- | src/wrap/python/rsa.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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; } @@ -87,6 +89,21 @@ Py_RSA_PrivateKey::Py_RSA_PrivateKey(u32bit 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<RSA_PrivateKey*>(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_<Py_RSA_PrivateKey> ("RSA_PrivateKey", python::init<std::string, Python_RandomNumberGenerator&, std::string>()) + .def(python::init<std::string, Python_RandomNumberGenerator&>()) .def(python::init<u32bit, Python_RandomNumberGenerator&>()) .def("to_string", &Py_RSA_PrivateKey::to_string) .def("to_ber", &Py_RSA_PrivateKey::to_ber) |