7 #ifndef BOTAN_FFI_UTILS_H_ 8 #define BOTAN_FFI_UTILS_H_ 13 #include <botan/exceptn.h> 14 #include <botan/mem_ops.h> 21 explicit FFI_Error(
const std::string& what) : Exception(
"FFI error", what) {}
24 template<
typename T, u
int32_t MAGIC>
31 bool magic_ok()
const {
return (m_magic == MAGIC); }
39 std::unique_ptr<T> m_obj;
42 #define BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC) \ 43 struct NAME final : public Botan_FFI::botan_struct<TYPE, MAGIC> { explicit NAME(TYPE* x) : botan_struct(x) {} } 48 template<
typename T, u
int32_t M>
54 throw FFI_Error(
"Bad magic in ffi object");
60 throw FFI_Error(
"Invalid object pointer");
63 template<
typename Thunk>
70 catch(std::bad_alloc&)
74 catch(std::exception& e)
86 template<
typename T, u
int32_t M,
typename F>
98 #define BOTAN_FFI_DO(T, obj, param, block) \ 99 apply_fn(obj, BOTAN_CURRENT_FUNCTION, \ 100 [=](T& param) -> int { do { block } while(0); return BOTAN_FFI_SUCCESS; }) 102 template<
typename T, u
int32_t M>
116 catch(std::exception& e)
126 #define BOTAN_FFI_CHECKED_DELETE(o) ffi_delete_object(o, BOTAN_CURRENT_FUNCTION) 128 inline int write_output(uint8_t out[],
size_t* out_len,
const uint8_t buf[],
size_t buf_len)
130 const size_t avail = *out_len;
145 template<
typename Alloc>
146 int write_vec_output(uint8_t out[],
size_t* out_len,
const std::vector<uint8_t, Alloc>& buf)
148 return write_output(out, out_len, buf.data(), buf.size());
163 inline int write_str_output(
char out[],
size_t* out_len,
const std::vector<uint8_t>& str_vec)
#define BOTAN_UNSTABLE_API
void clear_mem(T *ptr, size_t n)
int ffi_error_exception_thrown(const char *func_name, const char *exn)
int ffi_guard_thunk(const char *func_name, Thunk thunk)
const uint8_t * cast_char_ptr_to_uint8(const char *s)
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
void copy_mem(T *out, const T *in, size_t n)
int apply_fn(botan_struct< T, M > *o, const char *func_name, F func)
T & safe_get(botan_struct< T, M > *p)
int ffi_delete_object(botan_struct< T, M > *obj, const char *func_name)
FFI_Error(const std::string &what)
int write_output(uint8_t out[], size_t *out_len, const uint8_t buf[], size_t buf_len)