aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ffi/ffi.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2015-06-28 03:36:12 -0400
committerJack Lloyd <[email protected]>2015-06-28 03:36:12 -0400
commitdacc3733305ede05a20c428b0a1f2a704873483a (patch)
tree96e2acbe5d598340db44a780364f64552b16dd39 /src/lib/ffi/ffi.cpp
parentd6044e49cefc7fb1415033ed7f7ed74e9a985d33 (diff)
Add OCaml binding for RNG and hash functions. Add hex_encode to FFI
Diffstat (limited to 'src/lib/ffi/ffi.cpp')
-rw-r--r--src/lib/ffi/ffi.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index 2151c33a9..4fcdb63c1 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -15,6 +15,7 @@
#include <botan/version.h>
#include <botan/pubkey.h>
#include <botan/data_src.h>
+#include <botan/hex.h>
#include <botan/mem_ops.h>
#include <cstring>
#include <memory>
@@ -177,6 +178,27 @@ uint32_t botan_version_minor() { return Botan::version_minor(); }
uint32_t botan_version_patch() { return Botan::version_patch(); }
uint32_t botan_version_datestamp() { return Botan::version_datestamp(); }
+int botan_same_mem(const uint8_t* x, const uint8_t* y, size_t len)
+ {
+ return Botan::same_mem(x, y, len) ? 0 : 1;
+ }
+
+int botan_hex_encode(const uint8_t* in, size_t len, char* out, uint32_t flags)
+ {
+ try
+ {
+ const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
+ Botan::hex_encode(out, in, len, uppercase);
+ return 0;
+ }
+ catch(std::exception& e)
+ {
+ log_exception(BOTAN_CURRENT_FUNCTION, e.what());
+ }
+
+ return 1;
+ }
+
int botan_rng_init(botan_rng_t* rng_out, const char* rng_type)
{
// Just gives unique_ptr something to delete, really