/************************************************* * Boost.Python module definition * * (C) 1999-2007 Jack Lloyd * *************************************************/ #include #include #include #include using namespace Botan; #include namespace python = boost::python; std::string encode_pub(const Public_Key* key, const std::string& type) { if(type == "DER") { Pipe pipe; pipe.start_msg(); X509::encode(*key, pipe, RAW_BER); pipe.end_msg(); return pipe.read_all_as_string(); } else if(type == "PEM") return X509::PEM_encode(*key); else throw Encoding_Error("Unknown key encoding method " + type); } std::string encode_priv(const Private_Key* key, const std::string& type) { if(type == "DER") { Pipe pipe; PKCS8::encode(*key, pipe, RAW_BER); return pipe.read_all_as_string(); } else if(type == "PEM") return PKCS8::PEM_encode(*key); else throw Encoding_Error("Unknown key encoding method " + type); } /* Private_Key* load_priv(const std::string& file, const std::string& pass) { return PKCS8::load_key(file, pass); } 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 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 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::def("public_key", load_public, python::return_value_policy()); */ python::class_ ("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_, boost::noncopyable> ("PK_Encrypting_Key", python::no_init); python::class_, boost::noncopyable> ("Private_Key", python::no_init) .def("private_key", encode_priv); python::class_, boost::noncopyable> ("PK_Decrypting_Key", python::no_init); python::class_ > ("RSA_PublicKey", python::no_init); python::class_ > ("DSA_PublicKey", python::no_init); /* python::class_ > ("RSA_PrivateKey", python::init()); */ /* python::class_ ("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", python::no_init) .def("__init__", python::make_constructor(get_pk_decryptor)) .def("decrypt", decrypt_string); */ }