Botan  2.4.0
Crypto and TLS for C++11
Functions
ffi_cert.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_util.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/x509cert.h>
#include <botan/data_src.h>

Go to the source code of this file.

Functions

 BOTAN_FFI_DECLARE_STRUCT (botan_x509_cert_struct, Botan::X509_Certificate, 0x8F628937)
 
int botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
 
int botan_x509_cert_destroy (botan_x509_cert_t cert)
 
int botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_issuer_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
 
int botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_subject_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
 
int botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
 
int botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert_bits[], size_t cert_bits_len)
 
int botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *cert_path)
 
int botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
 

Function Documentation

◆ BOTAN_FFI_DECLARE_STRUCT()

BOTAN_FFI_DECLARE_STRUCT ( botan_x509_cert_struct  ,
Botan::X509_Certificate  ,
0x8F628937   
)

◆ botan_x509_cert_allowed_usage()

int botan_x509_cert_allowed_usage ( botan_x509_cert_t  cert,
unsigned int  key_usage 
)

Definition at line 86 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and BOTAN_FFI_SUCCESS.

87  {
88  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, {
89  const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
90  if(c.allowed_usage(k))
91  return BOTAN_FFI_SUCCESS;
92  return 1;
93  });
94  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_destroy()

int botan_x509_cert_destroy ( botan_x509_cert_t  cert)

Definition at line 96 of file ffi_cert.cpp.

References BOTAN_FFI_CHECKED_DELETE.

97  {
98  return BOTAN_FFI_CHECKED_DELETE(cert);
99  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_x509_cert_get_authority_key_id()

int botan_x509_cert_get_authority_key_id ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 121 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

122  {
123  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.authority_key_id()); });
124  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_fingerprint()

int botan_x509_cert_get_fingerprint ( botan_x509_cert_t  cert,
const char *  hash,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 116 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

117  {
118  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.fingerprint(hash)); });
119  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
MechanismType hash

◆ botan_x509_cert_get_issuer_dn()

int botan_x509_cert_get_issuer_dn ( botan_x509_cert_t  cert,
const char *  key,
size_t  index,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 67 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

70  {
71  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.issuer_info(key).at(index)); });
72  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_public_key()

int botan_x509_cert_get_public_key ( botan_x509_cert_t  cert,
botan_pubkey_t key 
)

Definition at line 49 of file ffi_cert.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

50  {
51  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
52  if(key == nullptr)
54 
55  *key = nullptr;
56 
57 #if defined(BOTAN_HAS_RSA)
58  std::unique_ptr<Botan::Public_Key> publicKey = safe_get(cert).load_subject_public_key();
59  *key = new botan_pubkey_struct(publicKey.release());
60  return BOTAN_FFI_SUCCESS;
61 #else
63 #endif
64  });
65  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_x509_cert_get_public_key_bits()

int botan_x509_cert_get_public_key_bits ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 131 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

132  {
133  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_public_key_bits()); });
134  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_serial_number()

int botan_x509_cert_get_serial_number ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 111 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

112  {
113  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.serial_number()); });
114  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_subject_dn()

int botan_x509_cert_get_subject_dn ( botan_x509_cert_t  cert,
const char *  key,
size_t  index,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 74 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

77  {
78  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.subject_info(key).at(index)); });
79  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_subject_key_id()

int botan_x509_cert_get_subject_key_id ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 126 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

127  {
128  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_key_id()); });
129  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_time_expires()

int botan_x509_cert_get_time_expires ( botan_x509_cert_t  cert,
char  out[],
size_t *  out_len 
)

Definition at line 106 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

107  {
108  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.not_after().to_string()); });
109  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_time_starts()

int botan_x509_cert_get_time_starts ( botan_x509_cert_t  cert,
char  out[],
size_t *  out_len 
)

Definition at line 101 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

102  {
103  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.not_before().to_string()); });
104  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_load()

int botan_x509_cert_load ( botan_x509_cert_t cert_obj,
const uint8_t  cert_bits[],
size_t  cert_bits_len 
)

Definition at line 35 of file ffi_cert.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().

36  {
37  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
38  if(!cert_obj || !cert_bits)
40 
41  Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
42 
43  std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(bits));
44  *cert_obj = new botan_x509_cert_struct(c.release());
45  return BOTAN_FFI_SUCCESS;
46  });
47  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_x509_cert_load_file()

int botan_x509_cert_load_file ( botan_x509_cert_t cert_obj,
const char *  cert_path 
)

Definition at line 19 of file ffi_cert.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().

20  {
21  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
22  if(!cert_obj || !cert_path)
24 
25 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
26  std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(cert_path));
27  *cert_obj = new botan_x509_cert_struct(c.release());
28  return BOTAN_FFI_SUCCESS;
29 #else
31 #endif
32  });
33  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_x509_cert_to_string()

int botan_x509_cert_to_string ( botan_x509_cert_t  cert,
char  out[],
size_t *  out_len 
)

Definition at line 81 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

82  {
83  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.to_string()); });
84  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98