diff options
author | Jack Lloyd <[email protected]> | 2017-08-15 16:10:28 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-08-15 16:10:28 -0400 |
commit | c917ab6ebdd2f4661eb7045887e3945078f62082 (patch) | |
tree | a5c2e1880aa6fbf9715514655941e468de1b1c77 /src/tests/test_ffi.cpp | |
parent | 3739081a4de5cc70695dd210c38cd64611c53665 (diff) |
Add botan_hex_decode, botan_base64_encode, botan_base64_decode FFI funcs
Diffstat (limited to 'src/tests/test_ffi.cpp')
-rw-r--r-- | src/tests/test_ffi.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index 3b825ad4e..34d832026 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -361,6 +361,7 @@ class FFI_Unit_Tests : public Test std::vector<Test::Result> results; results.push_back(ffi_test_errors()); + results.push_back(ffi_test_base64()); results.push_back(ffi_test_mp(rng)); results.push_back(ffi_test_block_ciphers()); results.push_back(ffi_test_ciphers_cbc()); @@ -697,6 +698,35 @@ class FFI_Unit_Tests : public Test return result; } + Test::Result ffi_test_base64() + { + Test::Result result("FFI base64"); + + const uint8_t bin[9] = { 0x16, 0x8a, 0x1f, 0x06, 0xe9, 0xe7, 0xcb, 0xdd, 0x34 }; + char out_buf[1024] = { 0 }; + + size_t out_len = sizeof(out_buf); + TEST_FFI_OK(botan_base64_encode, (bin, sizeof(bin), out_buf, &out_len)); + + result.test_eq("encoded string", out_buf, "FoofBunny900"); + + out_len -= 1; + TEST_FFI_RC(BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, + botan_base64_encode, + (bin, sizeof(bin), out_buf, &out_len)); + + const char* base64 = "U3VjaCBiYXNlNjQgd293IQ=="; + uint8_t out_bin[1024] = { 0 }; + out_len = sizeof(out_bin); + TEST_FFI_OK(botan_base64_decode, (base64, strlen(base64), out_bin, &out_len)); + + result.test_eq("decoded string", + std::string(reinterpret_cast<const char*>(out_bin), out_len), + "Such base64 wow!"); + + return result; + } + Test::Result ffi_test_mp(botan_rng_t rng) { Test::Result result("FFI MP"); |