summaryrefslogtreecommitdiff
path: root/datatest.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-03-27 03:29:56 -0400
committerJeffrey Walton <noloader@gmail.com>2018-03-27 03:29:56 -0400
commitf26a07ad98774272532cef1e7cc5b3ec256c4df4 (patch)
tree43b52baec80b79044e9cf254b70cb2941f08d7e9 /datatest.cpp
parent3b8bc690bb254ab497f32c67ceecd8f3b5b93ae2 (diff)
downloadcryptopp-git-f26a07ad98774272532cef1e7cc5b3ec256c4df4.tar.gz
Add extraneous calls for code coverage
Diffstat (limited to 'datatest.cpp')
-rw-r--r--datatest.cpp46
1 files changed, 34 insertions, 12 deletions
diff --git a/datatest.cpp b/datatest.cpp
index a7dbd7db..d3c58423 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -237,7 +237,6 @@ private:
void TestKeyPairValidAndConsistent(CryptoMaterial &pub, const CryptoMaterial &priv)
{
- // "!!" converts between bool <-> integral.
if (!pub.Validate(Test::GlobalRNG(), 2U+!!s_thorough))
SignalTestFailure();
if (!priv.Validate(Test::GlobalRNG(), 2U+!!s_thorough))
@@ -261,6 +260,10 @@ void TestSignatureScheme(TestData &v)
TestDataNameValuePairs pairs(v);
+ // Code coverage
+ (void)signer->AlgorithmName();
+ (void)verifier->AlgorithmName();
+
if (test == "GenerateKey")
{
signer->AccessPrivateKey().GenerateRandom(Test::GlobalRNG(), pairs);
@@ -360,6 +363,10 @@ void TestAsymmetricCipher(TestData &v)
encryptor->AccessMaterial().AssignFrom(pairs);
}
+ // Code coverage
+ (void)encryptor->AlgorithmName();
+ (void)decryptor->AlgorithmName();
+
if (test == "DecryptMatch")
{
std::string decrypted, expected = GetDecodedDatum(v, "Plaintext");
@@ -422,6 +429,16 @@ void TestSymmetricCipher(TestData &v, const NameValuePairs &overrideParameters)
decryptor->SetKey((const byte *)key.data(), key.size(), pairs);
}
+ // Code coverage
+ (void)encryptor->AlgorithmName();
+ (void)decryptor->AlgorithmName();
+ (void)encryptor->MinKeyLength();
+ (void)decryptor->MinKeyLength();
+ (void)encryptor->MaxKeyLength();
+ (void)decryptor->MaxKeyLength();
+ (void)encryptor->DefaultKeyLength();
+ (void)decryptor->DefaultKeyLength();
+
int seek = pairs.GetIntValueWithDefault("Seek", 0);
if (seek)
{
@@ -539,21 +556,24 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
if (test == "Encrypt" || test == "EncryptXorDigest" || test == "NotVerify")
{
- member_ptr<AuthenticatedSymmetricCipher> asc1, asc2;
- asc1.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, ENCRYPTION>::Registry().CreateObject(name.c_str()));
- asc2.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, DECRYPTION>::Registry().CreateObject(name.c_str()));
- asc1->SetKey((const byte *)key.data(), key.size(), pairs);
- asc2->SetKey((const byte *)key.data(), key.size(), pairs);
+ member_ptr<AuthenticatedSymmetricCipher> encryptor, decryptor;
+ encryptor.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, ENCRYPTION>::Registry().CreateObject(name.c_str()));
+ decryptor.reset(ObjectFactoryRegistry<AuthenticatedSymmetricCipher, DECRYPTION>::Registry().CreateObject(name.c_str()));
+ encryptor->SetKey((const byte *)key.data(), key.size(), pairs);
+ decryptor->SetKey((const byte *)key.data(), key.size(), pairs);
+
+ (void)encryptor->AlgorithmName();
+ (void)decryptor->AlgorithmName();
std::string encrypted, decrypted;
- AuthenticatedEncryptionFilter ef(*asc1, new StringSink(encrypted));
+ AuthenticatedEncryptionFilter ef(*encryptor, new StringSink(encrypted));
bool macAtBegin = !mac.empty() && !Test::GlobalRNG().GenerateBit(); // test both ways randomly
- AuthenticatedDecryptionFilter df(*asc2, new StringSink(decrypted), macAtBegin ? AuthenticatedDecryptionFilter::MAC_AT_BEGIN : 0);
+ AuthenticatedDecryptionFilter df(*decryptor, new StringSink(decrypted), macAtBegin ? AuthenticatedDecryptionFilter::MAC_AT_BEGIN : 0);
- if (asc1->NeedsPrespecifiedDataLengths())
+ if (encryptor->NeedsPrespecifiedDataLengths())
{
- asc1->SpecifyDataLengths(header.size(), plaintext.size(), footer.size());
- asc2->SpecifyDataLengths(header.size(), plaintext.size(), footer.size());
+ encryptor->SpecifyDataLengths(header.size(), plaintext.size(), footer.size());
+ decryptor->SpecifyDataLengths(header.size(), plaintext.size(), footer.size());
}
StringStore sh(header), sp(plaintext), sc(ciphertext), sf(footer), sm(mac);
@@ -589,7 +609,7 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
SignalTestFailure();
}
- if (ciphertext.size()+mac.size()-plaintext.size() != asc1->DigestSize())
+ if (ciphertext.size()+mac.size()-plaintext.size() != encryptor->DigestSize())
{
std::cout << "\nbad MAC size\n";
SignalTestFailure();
@@ -623,6 +643,7 @@ void TestDigestOrMAC(TestData &v, bool testDigest)
{
hash.reset(ObjectFactoryRegistry<HashTransformation>::Registry().CreateObject(name.c_str()));
pHash = hash.get();
+ (void)hash->AlgorithmName();
}
else
{
@@ -630,6 +651,7 @@ void TestDigestOrMAC(TestData &v, bool testDigest)
pHash = mac.get();
std::string key = GetDecodedDatum(v, "Key");
mac->SetKey((const byte *)key.c_str(), key.size(), pairs);
+ (void)mac->AlgorithmName();
}
if (test == "Verify" || test == "VerifyTruncated" || test == "NotVerify")