diff options
author | Jack Lloyd <[email protected]> | 2018-01-02 10:42:11 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-01-02 10:42:11 -0500 |
commit | 8326a481c1c7ae6ce18db8b4af9f413bd8435c3e (patch) | |
tree | 8210b7428915f3d485c260e6c679bd15a2082988 /src/tests/test_ecies.cpp | |
parent | 0b957292b1c854a12356503d5b5c13e540101843 (diff) |
Cleanup ECIES test
And avoid warnings from Sonar about adding booleans
Diffstat (limited to 'src/tests/test_ecies.cpp')
-rw-r--r-- | src/tests/test_ecies.cpp | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/tests/test_ecies.cpp b/src/tests/test_ecies.cpp index 6a4bcfeb0..5c5af0a41 100644 --- a/src/tests/test_ecies.cpp +++ b/src/tests/test_ecies.cpp @@ -150,40 +150,33 @@ class ECIES_ISO_Tests final : public Text_Based_Test result.test_eq("derived secret key", secret_key.bits_of(), k); // test encryption / decryption - for(int i_cofactor_mode = 0; i_cofactor_mode < 2; ++i_cofactor_mode) + + for(auto comp_type : { Botan::PointGFp::UNCOMPRESSED, Botan::PointGFp::COMPRESSED, Botan::PointGFp::HYBRID }) { - for(int i_single_hash_mode = 0; i_single_hash_mode < 2; ++i_single_hash_mode) + for(bool cofactor_mode : { true, false }) { - for(int i_old_cofactor_mode = 0; i_old_cofactor_mode < 2; ++i_old_cofactor_mode) + for(bool single_hash_mode : { true, false }) { - for(int i_check_mode = 0; i_check_mode < 2; ++i_check_mode) + for(bool old_cofactor_mode : { true, false }) { - for(int i_compression_type = 0; i_compression_type < 3; ++i_compression_type) + for(bool check_mode : { true, false }) { - const bool cofactor_mode = i_cofactor_mode != 0; - const bool single_hash_mode = i_single_hash_mode != 0; - const bool old_cofactor_mode = i_old_cofactor_mode != 0; - const bool check_mode = i_check_mode != 0; - const Botan::PointGFp::Compression_Type gen_compression_type = - static_cast<Botan::PointGFp::Compression_Type>(i_compression_type); - Flags flags = ecies_flags(cofactor_mode, old_cofactor_mode, check_mode, single_hash_mode); - if(cofactor_mode + check_mode + old_cofactor_mode > 1) + if(size_t(cofactor_mode) + size_t(check_mode) + size_t(old_cofactor_mode) > 1) { auto onThrow = [&]() { - Botan::ECIES_System_Params( - eph_private_key.domain(), + Botan::ECIES_System_Params(eph_private_key.domain(), "KDF2(SHA-1)", "AES-256/CBC", 32, "HMAC(SHA-1)", 20, - gen_compression_type, flags); + comp_type, flags); }; result.test_throws("throw on invalid ECIES_Flags", onThrow); continue; } Botan::ECIES_System_Params ecies_params(eph_private_key.domain(), "KDF2(SHA-1)", "AES-256/CBC", - 32, "HMAC(SHA-1)", 20, gen_compression_type, flags); + 32, "HMAC(SHA-1)", 20, comp_type, flags); check_encrypt_decrypt(result, eph_private_key, other_private_key, ecies_params, 16); } } |