aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_cryptobox.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-22 19:02:51 -0400
committerJack Lloyd <[email protected]>2017-09-22 19:02:51 -0400
commit834533f5eff98ec308b8097c5709b039636aeba4 (patch)
tree00cc3028456367578e0b9bd44dc174c46a5140ec /src/tests/test_cryptobox.cpp
parentf8f2912d24bad8b162b89e34ab62c415aef98843 (diff)
Update cryptobox decryption
Diffstat (limited to 'src/tests/test_cryptobox.cpp')
-rw-r--r--src/tests/test_cryptobox.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/tests/test_cryptobox.cpp b/src/tests/test_cryptobox.cpp
index 4e2ba83c2..927c5c379 100644
--- a/src/tests/test_cryptobox.cpp
+++ b/src/tests/test_cryptobox.cpp
@@ -32,18 +32,34 @@ class Cryptobox_Tests final : public Test
const std::string ciphertext =
Botan::CryptoBox::encrypt(input.data(), input.size(), password, Test::rng());
+ // First verify decryption works
try
{
- const std::string decrypted = Botan::CryptoBox::decrypt(ciphertext, password);
-
- const uint8_t* pt_b = reinterpret_cast<const uint8_t*>(decrypted.data());
- std::vector<uint8_t> pt_vec(pt_b, pt_b + decrypted.size());
- result.test_eq("decrypt", pt_vec, input);
+ const Botan::secure_vector<uint8_t> decrypted =
+ Botan::CryptoBox::decrypt_bin(ciphertext, password);
+ result.test_eq("decrypt", decrypted, input);
}
catch(std::exception& e)
{
result.test_failure("cryptobox decrypt", e.what());
}
+
+ // Now corrupt a bit and ensure it fails
+ try
+ {
+ std::string corrupted = ciphertext;
+ corrupted[corrupted.size()/2]++;
+ const std::string decrypted = Botan::CryptoBox::decrypt(corrupted, password);
+ result.test_failure("Decrypted corrupted cryptobox message");
+ }
+ catch(Botan::Decoding_Error)
+ {
+ result.test_success("Rejected corrupted cryptobox message");
+ }
+ catch(Botan::Invalid_Argument)
+ {
+ result.test_success("Rejected corrupted cryptobox message");
+ }
}
return {result};