aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_stream.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-10-26 20:31:30 -0400
committerJack Lloyd <[email protected]>2017-10-26 22:26:15 -0400
commite6d45052efedfe49e99adb6318aaf56e0a9e8d7b (patch)
treec6c3ccd3cff3d04285940bf1d518c809e0653947 /src/tests/test_stream.cpp
parent315b002ecf00f6b6bb0f0d5200d1f39a83527e8f (diff)
Add checks that keyed algorithms are actually keyed before use
Previously calling update or encrypt without calling set_key first would result in invalid outputs or else crashing.
Diffstat (limited to 'src/tests/test_stream.cpp')
-rw-r--r--src/tests/test_stream.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/tests/test_stream.cpp b/src/tests/test_stream.cpp
index 50012fe97..357b8c769 100644
--- a/src/tests/test_stream.cpp
+++ b/src/tests/test_stream.cpp
@@ -56,6 +56,18 @@ class Stream_Cipher_Tests final : public Text_Based_Test
const std::string provider(cipher->provider());
result.test_is_nonempty("provider", provider);
result.test_eq(provider, cipher->name(), algo);
+
+ try
+ {
+ std::vector<uint8_t> buf(128);
+ cipher->cipher1(buf.data(), buf.size());
+ result.test_failure("Was able to encrypt without a key being set");
+ }
+ catch(Botan::Invalid_State&)
+ {
+ result.test_success("Trying to encrypt with no key set fails");
+ }
+
cipher->set_key(key);
if(nonce.size())
@@ -96,6 +108,17 @@ class Stream_Cipher_Tests final : public Text_Based_Test
cipher->clear();
+ try
+ {
+ std::vector<uint8_t> buf(128);
+ cipher->cipher1(buf.data(), buf.size());
+ result.test_failure("Was able to encrypt without a key being set (after clear)");
+ }
+ catch(Botan::Invalid_State&)
+ {
+ result.test_success("Trying to encrypt with no key set (after clear) fails");
+ }
+
result.test_eq(provider, "encrypt", buf, expected);
}