diff options
author | Jack Lloyd <[email protected]> | 2016-02-09 07:08:47 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-02-09 07:08:47 -0500 |
commit | 2becd2b8b7fe1cda319789fd96ddd7bf51b433cb (patch) | |
tree | c98a7556095da5008751cc62dc18cf86bc84a039 /src/tests | |
parent | 32753defe9e49ba7dac457210ee0617313cb1b7b (diff) |
Removes randomization from choice of keys in X509 test.
Would be better to iterate over all of the key types for this type of
coverage.
Avoids Coverity dead code warning on the error-case throw.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/unit_x509.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp index da36459c4..93e26eee2 100644 --- a/src/tests/unit_x509.cpp +++ b/src/tests/unit_x509.cpp @@ -82,27 +82,17 @@ Botan::X509_Cert_Options req_opts2() std::unique_ptr<Botan::Private_Key> make_a_private_key() { -#if defined(BOTAN_HAS_DSA) - if(Test::rng().next_byte() < 32) - { - Botan::DL_Group grp("dsa/botan/2048"); - return std::unique_ptr<Botan::Private_Key>(new Botan::DSA_PrivateKey(Test::rng(), grp)); - } -#endif - -#if defined(BOTAN_HAS_RSA) - if(Test::rng().next_byte() < 32) - { - return std::unique_ptr<Botan::Private_Key>(new Botan::RSA_PrivateKey(Test::rng(), 1536)); - } -#endif - #if defined(BOTAN_HAS_ECDSA) Botan::EC_Group grp("secp256r1"); return std::unique_ptr<Botan::Private_Key>(new Botan::ECDSA_PrivateKey(Test::rng(), grp)); +#elif defined(BOTAN_HAS_RSA) + return std::unique_ptr<Botan::Private_Key>(new Botan::RSA_PrivateKey(Test::rng(), 1024)); +#elif defined(BOTAN_HAS_DSA) + Botan::DL_Group grp("dsa/botan/2048"); + return std::unique_ptr<Botan::Private_Key>(new Botan::DSA_PrivateKey(Test::rng(), grp)); +#else + return std::unique_ptr<Botan::Private_Key>(nullptr); #endif - - throw Test_Error("Skipping X.509 cert test due to missing algos"); } class X509_Cert_Unit_Tests : public Test @@ -227,6 +217,14 @@ std::vector<Test::Result> X509_Cert_Unit_Tests::run() /* Create the CA's key and self-signed cert */ std::unique_ptr<Botan::Private_Key> ca_key(make_a_private_key()); + if(!ca_key) + { + // Failure because X.509 enabled but no RSA or ECDSA seems off + result.test_failure("Skipping due to no enabled signature algorithms"); + results.push_back(result); + return results; + } + Botan::X509_Certificate ca_cert = Botan::X509::create_self_signed_cert(ca_opts(), *ca_key, |