Botan 3.13.0
Crypto and TLS for C&
ffi_oid.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_oid.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/internal/ffi_util.h>

Go to the source code of this file.

Functions

int botan_oid_cmp (int *result, botan_asn1_oid_t a_w, botan_asn1_oid_t b_w)
int botan_oid_destroy (botan_asn1_oid_t oid)
int botan_oid_equal (botan_asn1_oid_t a_w, botan_asn1_oid_t b_w)
int botan_oid_from_string (botan_asn1_oid_t *oid_obj, const char *oid_str)
int botan_oid_register (botan_asn1_oid_t oid, const char *name)
int botan_oid_view_name (botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
int botan_oid_view_string (botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)

Function Documentation

◆ botan_oid_cmp()

int botan_oid_cmp ( int * result,
botan_asn1_oid_t a,
botan_asn1_oid_t b )

Sets

Parameters
resultto comparison result: -1 if a < b, 0 if a == b, 1 if a > b
Returns
negative number on error or zero on success

Definition at line 63 of file ffi_oid.cpp.

63 {
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}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:131
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_oid_destroy()

int botan_oid_destroy ( botan_asn1_oid_t oid)

Frees all resources of the OID object

Parameters
oidthe OID object to destroy
Returns
negative number on error, or zero on success

Definition at line 18 of file ffi_oid.cpp.

18 {
19 return BOTAN_FFI_CHECKED_DELETE(oid);
20}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:188

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_oid_equal()

int botan_oid_equal ( botan_asn1_oid_t a,
botan_asn1_oid_t b )

Test if two OIDs are equal

Parameters
athe first OID
bthe second OID
Returns
0 if a != b
1 if a == b
negative number on error

Definition at line 59 of file ffi_oid.cpp.

59 {
60 return BOTAN_FFI_VISIT(a_w, [=](const auto& a) -> int { return a == safe_get(b_w); });
61}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_oid_from_string()

int botan_oid_from_string ( botan_asn1_oid_t * oid,
const char * oid_str )

Create an OID from a string, either dot notation (e.g. '1.2.3.4') or a registered name (e.g. 'RSA')

Parameters
oidhandle to the resulting OID
oid_strthe name of the OID to create
Returns
negative number on error, or zero on success

Definition at line 22 of file ffi_oid.cpp.

22 {
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 if(any_null_pointers(oid_obj, oid_str)) {
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}
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:132
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
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan::OID::from_string().

◆ botan_oid_register()

int botan_oid_register ( botan_asn1_oid_t oid,
const char * name )

Registers an OID so that it may later be retrieved by name

Returns
negative number on error, or zero on success

Definition at line 40 of file ffi_oid.cpp.

40 {
41 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int {
42 if(name == nullptr) {
44 }
46 return BOTAN_FFI_SUCCESS;
47 });
48}
static void register_oid(const OID &oid, std::string_view name)
Definition asn1_oid.cpp:61

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and Botan::OID::register_oid().

◆ botan_oid_view_name()

int botan_oid_view_name ( botan_asn1_oid_t oid,
botan_view_ctx ctx,
botan_view_str_fn view )

View an OIDs registered name if it exists, else its dot notation

Definition at line 54 of file ffi_oid.cpp.

54 {
55 return BOTAN_FFI_VISIT(
56 oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_formatted_string()); });
57}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:190

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_oid_view_string()

int botan_oid_view_string ( botan_asn1_oid_t oid,
botan_view_ctx ctx,
botan_view_str_fn view )

View an OID in dot notation

Definition at line 50 of file ffi_oid.cpp.

50 {
51 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_string()); });
52}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().