From 8f874750f29a08e4a5a2bebcdb66d77d037f7e41 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 29 Mar 2015 22:51:42 +0000 Subject: Key agreement was missing the return check, add it to get_pk_op instead --- src/lib/pubkey/pubkey.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/lib') diff --git a/src/lib/pubkey/pubkey.cpp b/src/lib/pubkey/pubkey.cpp index 1d32697f5..685cccfc1 100644 --- a/src/lib/pubkey/pubkey.cpp +++ b/src/lib/pubkey/pubkey.cpp @@ -15,18 +15,19 @@ namespace Botan { namespace { template -T* get_pk_op(const Key& key, const std::string& pad) +T* get_pk_op(const std::string& what, const Key& key, const std::string& pad) { - return Algo_Registry::global_registry().make(typename T::Spec(key, pad)); + T* p = Algo_Registry::global_registry().make(typename T::Spec(key, pad)); + if(!p) + throw Lookup_Error(what + " with " + key.algo_name() + "/" + pad + " not supported"); + return p; } } PK_Encryptor_EME::PK_Encryptor_EME(const Public_Key& key, const std::string& eme) { - m_op.reset(get_pk_op(key, eme)); - if(!m_op) - throw Lookup_Error("Encryption with " + key.algo_name() + "/" + eme + " not supported"); + m_op.reset(get_pk_op("Encryption", key, eme)); } std::vector @@ -42,9 +43,7 @@ size_t PK_Encryptor_EME::maximum_input_size() const PK_Decryptor_EME::PK_Decryptor_EME(const Private_Key& key, const std::string& eme) { - m_op.reset(get_pk_op(key, eme)); - if(!m_op) - throw Lookup_Error("Decryption with " + key.algo_name() + "/" + eme + " not supported"); + m_op.reset(get_pk_op("Decryption", key, eme)); } secure_vector PK_Decryptor_EME::dec(const byte msg[], size_t length) const @@ -52,9 +51,9 @@ secure_vector PK_Decryptor_EME::dec(const byte msg[], size_t length) const return m_op->decrypt(msg, length); } -PK_Key_Agreement::PK_Key_Agreement(const Private_Key& key, const std::string& kdf_name) +PK_Key_Agreement::PK_Key_Agreement(const Private_Key& key, const std::string& kdf) { - m_op.reset(get_pk_op(key, kdf_name)); + m_op.reset(get_pk_op("Key agreement", key, kdf)); } SymmetricKey PK_Key_Agreement::derive_key(size_t key_len, @@ -111,9 +110,7 @@ PK_Signer::PK_Signer(const Private_Key& key, const std::string& emsa, Signature_Format format) { - m_op.reset(get_pk_op(key, emsa)); - if(!m_op) - throw Lookup_Error("Signing with " + key.algo_name() + "/" + emsa + " not supported"); + m_op.reset(get_pk_op("Signing", key, emsa)); m_sig_format = format; } @@ -140,10 +137,7 @@ PK_Verifier::PK_Verifier(const Public_Key& key, const std::string& emsa_name, Signature_Format format) { - m_op.reset(get_pk_op(key, emsa_name)); - if(!m_op) - throw Lookup_Error("Verification with " + key.algo_name() + " not supported"); - + m_op.reset(get_pk_op("Verification", key, emsa_name)); m_sig_format = format; } -- cgit v1.2.3