aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ffi/ffi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ffi/ffi.cpp')
-rw-r--r--src/lib/ffi/ffi.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index 28eac401a..1cd8e4b90 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -9,6 +9,7 @@
#include <botan/version.h>
#include <botan/mem_ops.h>
#include <botan/hex.h>
+#include <botan/base64.h>
#include <cstdio>
namespace Botan_FFI {
@@ -74,5 +75,36 @@ int botan_hex_encode(const uint8_t* in, size_t len, char* out, uint32_t flags)
});
}
+int botan_hex_decode(const char* hex_str, size_t in_len, uint8_t* out, size_t* out_len)
+ {
+ return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() {
+ const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
+ return Botan_FFI::write_vec_output(out, out_len, bin);
+ });
+ }
+
+int botan_base64_encode(const uint8_t* in, size_t len, char* out, size_t* out_len)
+ {
+ return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() {
+ const std::string base64 = Botan::base64_encode(in, len);
+ return Botan_FFI::write_str_output(out, out_len, base64);
+ });
+ }
+
+int botan_base64_decode(const char* base64_str, size_t in_len,
+ uint8_t* out, size_t* out_len)
+ {
+ return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() {
+ if(*out_len < Botan::base64_decode_max_output(in_len))
+ {
+ *out_len = Botan::base64_decode_max_output(in_len);
+ return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
+ }
+
+ *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
+ return BOTAN_FFI_SUCCESS;
+ });
+ }
+
}