diff options
author | lloyd <[email protected]> | 2006-10-28 00:25:25 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-10-28 00:25:25 +0000 |
commit | 587b5a6a3408960669e2bb8f01d78d6d2a3bcac4 (patch) | |
tree | 1babb66a02ac4d5a5a393c3552aeed98d3522939 /misc/python | |
parent | 3200e40299f6f1706b14da93636cb8b6b16e5f3c (diff) |
Somewhat better public key support, though I have a feeling this is not
really the right approach.
Diffstat (limited to 'misc/python')
-rw-r--r-- | misc/python/src/pk.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/misc/python/src/pk.cpp b/misc/python/src/pk.cpp index 8c873a487..41ab0d516 100644 --- a/misc/python/src/pk.cpp +++ b/misc/python/src/pk.cpp @@ -54,28 +54,60 @@ Public_Key* load_public(const std::string& file) return X509::load_key(file); } +std::string encrypt_string(const PK_Encryptor* enc, const std::string& in) + { + SecureVector<byte> cipher = enc->encrypt((const byte*)in.data(), in.length()); + return std::string((const char*)cipher.begin(), cipher.size()); + } + +std::string decrypt_string(const PK_Decryptor* dec, const std::string& in) + { + SecureVector<byte> plain = dec->decrypt((const byte*)in.data(), in.length()); + return std::string((const char*)plain.begin(), plain.size()); + } + void export_pk() { + python::def("private_key", load_priv, + python::return_value_policy<python::manage_new_object>()); + python::def("public_key", load_public, + python::return_value_policy<python::manage_new_object>()); + python::class_<Public_Key, boost::noncopyable> ("Public_Key", python::no_init) .add_property("name", &Public_Key::algo_name) .add_property("max_input_bits", &Public_Key::max_input_bits) .def("public_key", encode_pub); + python::class_<PK_Encrypting_Key, python::bases<Public_Key>, boost::noncopyable> + ("PK_Encrypting_Key", python::no_init); + python::class_<Private_Key, python::bases<Public_Key>, boost::noncopyable> ("Private_Key", python::no_init) .def("private_key", encode_priv); - python::def("private_key", load_priv, - python::return_value_policy<python::manage_new_object>()); - python::def("public_key", load_public, - python::return_value_policy<python::manage_new_object>()); + python::class_<PK_Decrypting_Key, python::bases<Private_Key>, boost::noncopyable> + ("PK_Decrypting_Key", python::no_init); - python::class_<RSA_PublicKey, python::bases<Public_Key> > + python::class_<RSA_PublicKey, python::bases<PK_Encrypting_Key> > ("RSA_PublicKey", python::no_init); + python::class_<DSA_PublicKey, python::bases<Public_Key> > ("DSA_PublicKey", python::no_init); - python::class_<RSA_PrivateKey, python::bases<RSA_PublicKey, Private_Key> > + python::class_<RSA_PrivateKey, python::bases<RSA_PublicKey, PK_Decrypting_Key> > ("RSA_PrivateKey", python::init<u32bit>()); + + python::class_<PK_Encryptor, boost::noncopyable> + ("PK_Encryptor", python::no_init) + .def("__init__", + python::make_constructor(get_pk_encryptor, + python::with_custodian_and_ward_postcall<0, 1>())) + .def("max_input", &PK_Encryptor::maximum_input_size). + def("encrypt", encrypt_string); + + python::class_<PK_Decryptor, boost::noncopyable> + ("PK_Decryptor", python::no_init) + .def("__init__", python::make_constructor(get_pk_decryptor)) + .def("decrypt", decrypt_string); } |