diff options
author | lloyd <[email protected]> | 2014-01-01 21:20:55 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-01 21:20:55 +0000 |
commit | 197dc467dec28a04c3b2f30da7cef122dfbb13e9 (patch) | |
tree | cdbd3ddaec051c72f0a757db461973d90c37b97a /src/tests/test_cryptobox.cpp | |
parent | 62faac373c07cfe10bc8c309e89ebdd30d8e5eaa (diff) |
Shuffle things around. Add NIST X.509 test to build.
Diffstat (limited to 'src/tests/test_cryptobox.cpp')
-rw-r--r-- | src/tests/test_cryptobox.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/tests/test_cryptobox.cpp b/src/tests/test_cryptobox.cpp new file mode 100644 index 000000000..9a53da74c --- /dev/null +++ b/src/tests/test_cryptobox.cpp @@ -0,0 +1,45 @@ +#include "tests.h" + +#include <botan/auto_rng.h> +#include <iostream> + +#if defined(BOTAN_HAS_CRYPTO_BOX) + #include <botan/cryptobox.h> +#endif + +using namespace Botan; + +size_t test_cryptobox() + { + size_t fails = 0; + +#if defined(BOTAN_HAS_CRYPTO_BOX) + AutoSeeded_RNG rng; + + const byte msg[] = { 0xAA, 0xBB, 0xCC }; + std::string ciphertext = CryptoBox::encrypt(msg, sizeof(msg), + "secret password", + rng); + + try + { + std::string plaintext = CryptoBox::decrypt(ciphertext, + "secret password"); + + if(plaintext.size() != sizeof(msg) || + !same_mem(reinterpret_cast<const byte*>(&plaintext[0]), msg, sizeof(msg))) + ++fails; + + } + catch(std::exception& e) + { + std::cout << "Error during Cryptobox test " << e.what() << "\n"; + ++fails; + } + + test_report("Cryptobox", 1, fails); +#endif + + return fails; + } + |