Botan 3.9.0
Crypto and TLS for C&
ffi_oid.cpp File Reference
#include <botan/ffi.h>
#include <botan/pk_keys.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 64 of file ffi_oid.cpp.

64 {
65 return BOTAN_FFI_VISIT(a_w, [=](auto& a) {
66 if(result == nullptr) {
68 }
69 Botan::OID b = safe_get(b_w);
70 // we don't have .cmp for OID
71 if(a == b) {
72 *result = 0;
73 } else if(a < b) {
74 *result = -1;
75 } else {
76 *result = 1;
77 }
78 return BOTAN_FFI_SUCCESS;
79 });
80}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:132
@ BOTAN_FFI_SUCCESS
Definition ffi.h:115
#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)
Returns
negative number on error, or zero on success

Definition at line 19 of file ffi_oid.cpp.

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

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_oid_equal()

int botan_oid_equal ( botan_asn1_oid_t a,
botan_asn1_oid_t b )
Returns
0 if a != b
1 if a == b
negative number on error

Definition at line 60 of file ffi_oid.cpp.

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

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
oidhanlder to the resulting OID
oid_strthe name of the OID to create
Returns
negative number on error, or zero on success

Definition at line 23 of file ffi_oid.cpp.

23 {
24 return ffi_guard_thunk(__func__, [=]() -> int {
25 if(oid_obj == nullptr || oid_str == nullptr) {
27 }
28 Botan::OID oid;
29 // This returns a Lookup_Error if an unknown name is passed,
30 // which would get turned into NOT_IMPLEMENTED
31 try {
32 oid = Botan::OID::from_string(oid_str);
33 } catch(Botan::Lookup_Error&) {
35 }
36 auto oid_ptr = std::make_unique<Botan::OID>(std::move(oid));
37 return ffi_new_object(oid_obj, std::move(oid_ptr));
38 });
39}
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:86
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:133
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

References 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 41 of file ffi_oid.cpp.

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

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 55 of file ffi_oid.cpp.

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

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 51 of file ffi_oid.cpp.

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

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().