diff options
-rw-r--r-- | src/lib/pubkey/pk_keys.h | 28 | ||||
-rw-r--r-- | src/tests/main.cpp | 29 | ||||
-rw-r--r-- | src/tests/test_pubkey.cpp | 26 | ||||
-rw-r--r-- | src/tests/tests.cpp | 12 |
4 files changed, 82 insertions, 13 deletions
diff --git a/src/lib/pubkey/pk_keys.h b/src/lib/pubkey/pk_keys.h index 13d94c085..5521f5b2c 100644 --- a/src/lib/pubkey/pk_keys.h +++ b/src/lib/pubkey/pk_keys.h @@ -35,6 +35,8 @@ class Signature; class BOTAN_DLL Public_Key { public: + virtual ~Public_Key() {} + /** * Get the name of the underlying public key scheme. * @return name of the public key scheme @@ -96,7 +98,12 @@ class BOTAN_DLL Public_Key */ virtual std::vector<byte> x509_subject_public_key() const = 0; + // Internal or non-public declarations follow + /** + * This is an internal library function exposed on key types. + * In almost all cases applications should use wrappers in pubkey.h + * * Return an encryption operation for this key/params or throw * * @param rng a random number generator. The PK_Op may maintain a @@ -109,6 +116,9 @@ class BOTAN_DLL Public_Key const std::string& provider) const; /** + * This is an internal library function exposed on key types. + * In almost all cases applications should use wrappers in pubkey.h + * * Return a KEM encryption operation for this key/params or throw * * @param rng a random number generator. The PK_Op may maintain a @@ -121,13 +131,15 @@ class BOTAN_DLL Public_Key const std::string& provider) const; /** + * This is an internal library function exposed on key types. + * In almost all cases applications should use wrappers in pubkey.h + * * Return a verification operation for this key/params or throw */ virtual std::unique_ptr<PK_Ops::Verification> create_verification_op(const std::string& params, const std::string& provider) const; - virtual ~Public_Key() {} protected: /** * Self-test after loading a key @@ -154,12 +166,17 @@ class BOTAN_DLL Private_Key : public virtual Public_Key virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const { return algorithm_identifier(); } + // Internal or non-public declarations follow + /** * @return Hash of the PKCS #8 encoding for this key object */ std::string fingerprint(const std::string& alg = "SHA") const; /** + * This is an internal library function exposed on key types. + * In almost all cases applications should use wrappers in pubkey.h + * * Return an decryption operation for this key/params or throw * * @param rng a random number generator. The PK_Op may maintain a @@ -172,6 +189,9 @@ class BOTAN_DLL Private_Key : public virtual Public_Key const std::string& provider) const; /** + * This is an internal library function exposed on key types. + * In almost all cases applications should use wrappers in pubkey.h + * * Return a KEM decryption operation for this key/params or throw * * @param rng a random number generator. The PK_Op may maintain a @@ -184,6 +204,9 @@ class BOTAN_DLL Private_Key : public virtual Public_Key const std::string& provider) const; /** + * This is an internal library function exposed on key types. + * In almost all cases applications should use wrappers in pubkey.h + * * Return a signature operation for this key/params or throw * * @param rng a random number generator. The PK_Op may maintain a @@ -196,6 +219,9 @@ class BOTAN_DLL Private_Key : public virtual Public_Key const std::string& provider) const; /** + * This is an internal library function exposed on key types. + * In almost all cases applications should use wrappers in pubkey.h + * * Return a key agreement operation for this key/params or throw * * @param rng a random number generator. The PK_Op may maintain a diff --git a/src/tests/main.cpp b/src/tests/main.cpp index b771d9614..d80049d53 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -312,14 +312,29 @@ int main(int argc, char* argv[]) BOTAN_VERSION_MINOR, BOTAN_VERSION_PATCH); - std::unique_ptr<Botan_CLI::Command> cmd(Botan_CLI::Command::get_cmd("test")); + try + { + std::unique_ptr<Botan_CLI::Command> cmd(Botan_CLI::Command::get_cmd("test")); - if(!cmd) + if(!cmd) + { + std::cout << "Unable to retrieve testing helper (program bug)\n"; // WTF + return 1; + } + + std::vector<std::string> args(argv + 1, argv + argc); + return cmd->run(args); + } + catch(Botan::Exception& e) { - std::cout << "Unable to retrieve testing helper (program bug)\n"; // WTF - return 1; + std::cout << "Exiting with library exception " << e.what() << std::endl; + } + catch(std::exception& e) + { + std::cout << "Exiting with std exception " << e.what() << std::endl; + } + catch(...) + { + std::cout << "Exiting with unknown exception\n"; } - - std::vector<std::string> args(argv + 1, argv + argc); - return cmd->run(args); } diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index 66069f110..0532eee03 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -218,9 +218,12 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string&, const VarMap& va { encryptor.reset(new Botan::PK_Encryptor_EME(*pubkey, Test::rng(),padding, enc_provider)); } + catch(Botan::Provider_Not_Found&) + { + continue; + } catch(Botan::Lookup_Error&) { - //result.test_note("Skipping encryption with provider " + enc_provider); continue; } @@ -247,9 +250,12 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string&, const VarMap& va { decryptor.reset(new Botan::PK_Decryptor_EME(*privkey, Test::rng(), padding, dec_provider)); } + catch(Botan::Provider_Not_Found&) + { + continue; + } catch(Botan::Lookup_Error&) { - //result.test_note("Skipping decryption with provider " + dec_provider); continue; } @@ -287,6 +293,11 @@ Test::Result PK_KEM_Test::run_one_test(const std::string&, const VarMap& vars) { enc.reset(new Botan::PK_KEM_Encryptor(pubkey, Test::rng(), kdf)); } + catch(Botan::Provider_Not_Found& e) + { + result.test_note("Skipping test", e.what()); + return result; + } catch(Botan::Lookup_Error&) { result.test_note("Skipping due to missing KDF: " + kdf); @@ -310,8 +321,14 @@ Test::Result PK_KEM_Test::run_one_test(const std::string&, const VarMap& vars) { dec.reset(new Botan::PK_KEM_Decryptor(*privkey, Test::rng(), kdf)); } - catch(Botan::Lookup_Error&) + catch(Botan::Provider_Not_Found& e) { + result.test_note("Skipping test", e.what()); + return result; + } + catch(Botan::Lookup_Error& e) + { + result.test_note("Skipping test", e.what()); return result; } @@ -349,6 +366,9 @@ Test::Result PK_Key_Agreement_Test::run_one_test(const std::string& header, cons kas.reset(new Botan::PK_Key_Agreement(*privkey, Test::rng(), kdf, provider)); result.test_eq(provider, "agreement", kas->derive_key(key_len, pubkey).bits_of(), shared); } + catch(Botan::Provider_Not_Found&) + { + } catch(Botan::Lookup_Error&) { //result.test_note("Skipping key agreement with with " + provider); diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 1bb8b7303..13094f5dc 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -867,8 +867,16 @@ std::vector<Test::Result> Text_Based_Test::run() } } - std::vector<Test::Result> final_tests = run_final_tests(); - results.insert(results.end(), final_tests.begin(), final_tests.end()); + try + { + std::vector<Test::Result> final_tests = run_final_tests(); + results.insert(results.end(), final_tests.begin(), final_tests.end()); + } + catch(std::exception& e) + { + results.push_back(Test::Result::Failure(header_or_name, + "run_final_tests exception " + std::string(e.what()))); + } return results; } |