Botan 3.14.1
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_util.h>
12
13extern "C" {
14
15using namespace Botan_FFI;
16
20
21int botan_oid_from_string(botan_asn1_oid_t* oid_obj, const char* oid_str) {
22 return ffi_guard_thunk(__func__, [=]() -> int {
23 if(any_null_pointers(oid_obj, oid_str)) {
25 }
26 Botan::OID oid;
27 // This returns a Lookup_Error if an unknown name is passed,
28 // which would get turned into NOT_IMPLEMENTED
29 try {
30 oid = Botan::OID::from_string(oid_str);
31 } catch(Botan::Lookup_Error&) {
33 }
34 auto oid_ptr = std::make_unique<Botan::OID>(std::move(oid));
35 return ffi_new_object(oid_obj, std::move(oid_ptr));
36 });
37}
38
40 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int {
41 if(name == nullptr) {
43 }
45 return BOTAN_FFI_SUCCESS;
46 });
47}
48
50 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_string()); });
51}
52
54 return BOTAN_FFI_VISIT(
55 oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_formatted_string()); });
56}
57
59 return BOTAN_FFI_VISIT(a_w, [=](const auto& a) -> int { return a == safe_get(b_w); });
60}
61
63 return BOTAN_FFI_VISIT(a_w, [=](auto& a) {
64 if(result == nullptr) {
66 }
67 const Botan::OID b = safe_get(b_w);
68 // we don't have .cmp for OID
69 if(a == b) {
70 *result = 0;
71 } else if(a < b) {
72 *result = -1;
73 } else {
74 *result = 1;
75 }
76 return BOTAN_FFI_SUCCESS;
77 });
78}
79}
static void register_oid(const OID &oid, std::string_view name)
Definition asn1_oid.cpp:61
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
struct botan_asn1_oid_struct * botan_asn1_oid_t
Definition ffi.h:1484
void * botan_view_ctx
Definition ffi.h:152
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:131
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:132
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
Definition ffi.h:170
int botan_oid_equal(botan_asn1_oid_t a_w, botan_asn1_oid_t b_w)
Definition ffi_oid.cpp:58
int botan_oid_register(botan_asn1_oid_t oid, const char *name)
Definition ffi_oid.cpp:39
int botan_oid_view_string(botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_oid.cpp:49
int botan_oid_cmp(int *result, botan_asn1_oid_t a_w, botan_asn1_oid_t b_w)
Definition ffi_oid.cpp:62
int botan_oid_view_name(botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_oid.cpp:53
int botan_oid_from_string(botan_asn1_oid_t *oid_obj, const char *oid_str)
Definition ffi_oid.cpp:21
int botan_oid_destroy(botan_asn1_oid_t oid)
Definition ffi_oid.cpp:17
const char * name
Definition ffi_tls.h:59
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:327
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:357
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:359
auto safe_get(T *p) -> typename T::element_type &
Definition ffi_util.h:191
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:347
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:229
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54