Botan 3.11.0
Crypto and TLS for C&
ffi_oid.cpp
Go to the documentation of this file.
1/*
2* (C) 2025 Jack Lloyd
3* (C) 2025 Dominik Schricker
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/ffi.h>
9
10#include <botan/internal/ffi_oid.h>
11#include <botan/internal/ffi_pkey.h>
12#include <botan/internal/ffi_util.h>
13
14extern "C" {
15
16using namespace Botan_FFI;
17
21
22int botan_oid_from_string(botan_asn1_oid_t* oid_obj, const char* oid_str) {
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 if(oid_obj == nullptr || oid_str == nullptr) {
26 }
27 Botan::OID oid;
28 // This returns a Lookup_Error if an unknown name is passed,
29 // which would get turned into NOT_IMPLEMENTED
30 try {
31 oid = Botan::OID::from_string(oid_str);
32 } catch(Botan::Lookup_Error&) {
34 }
35 auto oid_ptr = std::make_unique<Botan::OID>(std::move(oid));
36 return ffi_new_object(oid_obj, std::move(oid_ptr));
37 });
38}
39
40int botan_oid_register(botan_asn1_oid_t oid, const char* name) {
41 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int {
42 if(name == nullptr) {
44 }
46 return BOTAN_FFI_SUCCESS;
47 });
48}
49
51 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_string()); });
52}
53
55 return BOTAN_FFI_VISIT(
56 oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_formatted_string()); });
57}
58
60 return BOTAN_FFI_VISIT(a_w, [=](const auto& a) -> int { return a == safe_get(b_w); });
61}
62
64 return BOTAN_FFI_VISIT(a_w, [=](auto& a) {
65 if(result == nullptr) {
67 }
68 const Botan::OID b = safe_get(b_w);
69 // we don't have .cmp for OID
70 if(a == b) {
71 *result = 0;
72 } else if(a < b) {
73 *result = -1;
74 } else {
75 *result = 1;
76 }
77 return BOTAN_FFI_SUCCESS;
78 });
79}
80}
static void register_oid(const OID &oid, std::string_view name)
Definition asn1_oid.cpp:67
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:86
struct botan_asn1_oid_struct * botan_asn1_oid_t
Definition ffi.h:1224
void * botan_view_ctx
Definition ffi.h:154
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:133
@ BOTAN_FFI_SUCCESS
Definition ffi.h:116
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:134
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
Definition ffi.h:172
int botan_oid_equal(botan_asn1_oid_t a_w, botan_asn1_oid_t b_w)
Definition ffi_oid.cpp:59
int botan_oid_register(botan_asn1_oid_t oid, const char *name)
Definition ffi_oid.cpp:40
int botan_oid_view_string(botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_oid.cpp:50
int botan_oid_cmp(int *result, botan_asn1_oid_t a_w, botan_asn1_oid_t b_w)
Definition ffi_oid.cpp:63
int botan_oid_view_name(botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_oid.cpp:54
int botan_oid_from_string(botan_asn1_oid_t *oid_obj, const char *oid_str)
Definition ffi_oid.cpp:22
int botan_oid_destroy(botan_asn1_oid_t oid)
Definition ffi_oid.cpp:18
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:185
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:187
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95