blob: 4eb9cdcdb453ae7df0e1761e91328e71bab2ae6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "tests.h"
#if defined(BOTAN_HAS_CRYPTO_BOX)
#include <botan/cryptobox.h>
#include <botan/hex.h>
#endif
namespace Botan_Tests {
namespace {
#if defined(BOTAN_HAS_CRYPTO_BOX)
class Cryptobox_Tests : public Test
{
public:
std::vector<Test::Result> run() override
{
std::vector<Test::Result> results;
Test::Result result("cryptobox");
const std::vector<byte> msg = Botan::hex_decode("AABBCC");
const std::string password = "secret";
std::string ciphertext = Botan::CryptoBox::encrypt(msg.data(), msg.size(),
password,
Test::rng());
try
{
std::string plaintext = Botan::CryptoBox::decrypt(ciphertext, password);
const byte* pt_b = reinterpret_cast<const byte*>(plaintext.data());
std::vector<byte> pt_vec(pt_b, pt_b + plaintext.size());
result.test_eq("decrypt", pt_vec, msg);
}
catch(std::exception& e)
{
result.test_failure("cryptobox decrypt", e.what());
}
results.push_back(result);
return results;
}
};
BOTAN_REGISTER_TEST("cryptobox", Cryptobox_Tests);
#endif
}
}
|