9#include <botan/internal/ffi_util.h>
11#if defined(BOTAN_HAS_TOTP)
12 #include <botan/otp.h>
19#if defined(BOTAN_HAS_TOTP)
26 botan_totp_t* totp,
const uint8_t key[],
size_t key_len,
const char* hash_algo,
size_t digits,
size_t time_step) {
27 if(totp ==
nullptr || key ==
nullptr || hash_algo ==
nullptr) {
33#if defined(BOTAN_HAS_TOTP)
35 auto otp = std::make_unique<Botan::TOTP>(key, key_len, hash_algo, digits, time_step);
36 *totp =
new botan_totp_struct(std::move(otp));
41 BOTAN_UNUSED(totp, key, key_len, hash_algo, digits, time_step);
47#if defined(BOTAN_HAS_TOTP)
56#if defined(BOTAN_HAS_TOTP)
57 if(totp ==
nullptr || totp_code ==
nullptr) {
61 return BOTAN_FFI_VISIT(totp, [=](
auto& t) { *totp_code = t.generate_totp(timestamp); });
70#if defined(BOTAN_HAS_TOTP)
72 const bool ok = t.verify_totp(totp_code, timestamp, acceptable_clock_drift);
77 BOTAN_UNUSED(totp, totp_code, timestamp, acceptable_clock_drift);
struct botan_totp_struct * botan_totp_t
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
@ BOTAN_FFI_INVALID_VERIFIER
@ BOTAN_FFI_ERROR_NULL_POINTER
int botan_totp_generate(botan_totp_t totp, uint32_t *totp_code, uint64_t timestamp)
int botan_totp_init(botan_totp_t *totp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits, size_t time_step)
int botan_totp_destroy(botan_totp_t totp)
int botan_totp_check(botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift)
#define BOTAN_FFI_VISIT(obj, lambda)
#define BOTAN_FFI_CHECKED_DELETE(o)
#define BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC)
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)