aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_ffi.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-07-19 20:12:14 -0400
committerJack Lloyd <[email protected]>2018-07-19 20:12:14 -0400
commit381ee690999318a86fa61a0ac54416230b5567da (patch)
tree0793d4c04458402cf2a6ce0d929b31d71501883d /src/tests/test_ffi.cpp
parent9b379f6bcdd7fbe688013a1d76f863ef24caec39 (diff)
Add FFI funcs to get algo name from cipher, MAC and hash objs
Diffstat (limited to 'src/tests/test_ffi.cpp')
-rw-r--r--src/tests/test_ffi.cpp64
1 files changed, 49 insertions, 15 deletions
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp
index 916388778..c0afd9ac2 100644
--- a/src/tests/test_ffi.cpp
+++ b/src/tests/test_ffi.cpp
@@ -56,6 +56,10 @@ class FFI_Unit_Tests final : public Test
{
TEST_FFI_OK(botan_rng_get, (rng, outbuf.data(), outbuf.size()));
TEST_FFI_OK(botan_rng_reseed, (rng, 256));
+
+ uint8_t not_really_entropy[32] = { 0 };
+ TEST_FFI_OK(botan_rng_add_entropy, (rng, not_really_entropy, 32));
+
// used for the rest of this function and destroyed at the end
}
else
@@ -167,7 +171,6 @@ class FFI_Unit_Tests final : public Test
std::string outstr;
std::vector<uint8_t> outbuf;
- //char namebuf[32];
outstr.resize(2 * bin.size());
TEST_FFI_OK(botan_hex_encode, (bin.data(), bin.size(), &outstr[0], 0));
@@ -404,6 +407,18 @@ class FFI_Unit_Tests final : public Test
if(TEST_FFI_OK(botan_cipher_init, (&cipher_encrypt, "AES-128/GCM", BOTAN_CIPHER_INIT_FLAG_ENCRYPT)))
{
+ char namebuf[18];
+ size_t name_len = 15;
+ TEST_FFI_FAIL("output buffer too short", botan_cipher_name, (cipher_encrypt, namebuf, &name_len));
+ result.test_eq("name len", name_len, 16);
+
+ name_len = sizeof(namebuf);
+ if(TEST_FFI_OK(botan_cipher_name, (cipher_encrypt, namebuf, &name_len)))
+ {
+ result.test_eq("name len", name_len, 16);
+ result.test_eq("name", std::string(namebuf), "AES-128/GCM(16)");
+ }
+
size_t min_keylen = 0;
size_t max_keylen = 0;
size_t nonce_len = 0;
@@ -632,14 +647,18 @@ class FFI_Unit_Tests final : public Test
if(TEST_FFI_OK(botan_hash_init, (&hash, "SHA-256", 0)))
{
- /*
- TEST_FFI_FAIL("output buffer too short", botan_hash_name, (hash, namebuf, 5));
+ char namebuf[10];
+ size_t name_len = 7;
+ TEST_FFI_FAIL("output buffer too short", botan_hash_name, (hash, namebuf, &name_len));
+ result.test_eq("name len", name_len, 8);
+
+ name_len = sizeof(namebuf);
+ if(TEST_FFI_OK(botan_hash_name, (hash, namebuf, &name_len)))
+ {
+ result.test_eq("name len", name_len, 8);
+ result.test_eq("name", std::string(namebuf), "SHA-256");
+ }
- if(TEST_FFI_OK(botan_hash_name, (hash, namebuf, sizeof(namebuf))))
- {
- result.test_eq("hash name", std::string(namebuf), "SHA-256");
- }
- */
size_t block_size;
if (TEST_FFI_OK(botan_hash_block_size, (hash, &block_size)))
{
@@ -705,14 +724,17 @@ class FFI_Unit_Tests final : public Test
if(TEST_FFI_OK(botan_mac_init, (&mac, "HMAC(SHA-256)", 0)))
{
- /*
- TEST_FFI_FAIL("output buffer too short", botan_mac_name, (mac, namebuf, 5));
+ char namebuf[16];
+ size_t name_len = 13;
+ TEST_FFI_FAIL("output buffer too short", botan_mac_name, (mac, namebuf, &name_len));
+ result.test_eq("name len", name_len, 14);
- if(TEST_FFI_OK(botan_mac_name, (mac, namebuf, 20)))
- {
- result.test_eq("mac name", std::string(namebuf), "HMAC(SHA-256)");
- }
- */
+ name_len = sizeof(namebuf);
+ if(TEST_FFI_OK(botan_mac_name, (mac, namebuf, &name_len)))
+ {
+ result.test_eq("name len", name_len, 14);
+ result.test_eq("name", std::string(namebuf), "HMAC(SHA-256)");
+ }
size_t output_len;
if(TEST_FFI_OK(botan_mac_output_length, (mac, &output_len)))
@@ -819,6 +841,18 @@ class FFI_Unit_Tests final : public Test
if(TEST_FFI_OK(botan_block_cipher_init, (&cipher, "AES-128")))
{
+ char namebuf[10];
+ size_t name_len = 7;
+ TEST_FFI_FAIL("output buffer too short", botan_block_cipher_name, (cipher, namebuf, &name_len));
+ result.test_eq("name len", name_len, 8);
+
+ name_len = sizeof(namebuf);
+ if(TEST_FFI_OK(botan_block_cipher_name, (cipher, namebuf, &name_len)))
+ {
+ result.test_eq("name len", name_len, 8);
+ result.test_eq("name", std::string(namebuf), "AES-128");
+ }
+
const std::vector<uint8_t> zero16(16, 0);
std::vector<uint8_t> block(16, 0);