Botan  2.4.0
Crypto and TLS for C++11
Functions
ffi_pkey.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_util.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/internal/ffi_rng.h>
#include <botan/data_src.h>
#include <botan/hash.h>
#include <botan/pkcs8.h>
#include <botan/pk_keys.h>
#include <botan/x509_key.h>
#include <botan/pk_algs.h>

Go to the source code of this file.

Functions

int botan_pkcs_hash_id (const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
 
int botan_privkey_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_privkey_create (botan_privkey_t *key_obj, const char *algo_name, const char *algo_params, botan_rng_t rng_obj)
 
int botan_privkey_destroy (botan_privkey_t key)
 
int botan_privkey_export (botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_privkey_export_encrypted (botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, const char *, uint32_t flags)
 
int botan_privkey_export_encrypted_pbkdf_iter (botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, size_t pbkdf_iter, const char *maybe_cipher, const char *maybe_pbkdf_hash, uint32_t flags)
 
int botan_privkey_export_encrypted_pbkdf_msec (botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, uint32_t pbkdf_msec, size_t *pbkdf_iters_out, const char *maybe_cipher, const char *maybe_pbkdf_hash, uint32_t flags)
 
int botan_privkey_export_pubkey (botan_pubkey_t *pubout, botan_privkey_t key_obj)
 
int botan_privkey_load (botan_privkey_t *key, botan_rng_t rng_obj, const uint8_t bits[], size_t len, const char *password)
 
int botan_pubkey_algo_name (botan_pubkey_t key, char out[], size_t *out_len)
 
int botan_pubkey_check_key (botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_pubkey_destroy (botan_pubkey_t key)
 
int botan_pubkey_estimated_strength (botan_pubkey_t key, size_t *estimate)
 
int botan_pubkey_export (botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_pubkey_fingerprint (botan_pubkey_t key, const char *hash_fn, uint8_t out[], size_t *out_len)
 
int botan_pubkey_load (botan_pubkey_t *key, const uint8_t bits[], size_t bits_len)
 

Function Documentation

◆ botan_pkcs_hash_id()

int botan_pkcs_hash_id ( const char *  hash_name,
uint8_t  pkcs_id[],
size_t *  pkcs_id_len 
)

Definition at line 260 of file ffi_pkey.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan_FFI::ffi_guard_thunk(), Botan::pkcs_hash_id(), and Botan_FFI::write_output().

261  {
262 #if defined(BOTAN_HAS_HASH_ID)
263  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
264  const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
265  return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
266  });
267 #else
269 #endif
270  }
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
int write_output(uint8_t out[], size_t *out_len, const uint8_t buf[], size_t buf_len)
Definition: ffi_util.h:128
std::vector< uint8_t > pkcs_hash_id(const std::string &name)
Definition: hash_id.cpp:77

◆ botan_privkey_check_key()

int botan_privkey_check_key ( botan_privkey_t  key,
botan_rng_t  rng,
uint32_t  flags 
)

Definition at line 139 of file ffi_pkey.cpp.

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, BOTAN_FFI_DO, and Botan_FFI::safe_get().

140  {
141  const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
142  return BOTAN_FFI_DO(Botan::Private_Key, key, k,
143  { return (k.check_key(safe_get(rng), strong) == true) ? 0 : -1; });
144  }
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:696
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_privkey_create()

int botan_privkey_create ( botan_privkey_t key_obj,
const char *  algo_name,
const char *  algo_params,
botan_rng_t  rng_obj 
)

Definition at line 26 of file ffi_pkey.cpp.

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

Referenced by botan_privkey_create_dh(), botan_privkey_create_ecdh(), botan_privkey_create_ecdsa(), botan_privkey_create_mceliece(), and botan_privkey_create_rsa().

30  {
31  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
32  if(key_obj == nullptr)
34 
35  *key_obj = nullptr;
36  if(rng_obj == nullptr)
38 
39  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
40  std::unique_ptr<Botan::Private_Key> key(
41  Botan::create_private_key(algo_name ? algo_name : "RSA",
42  rng,
43  algo_params ? algo_params : ""));
44 
45  if(key)
46  {
47  *key_obj = new botan_privkey_struct(key.release());
48  return BOTAN_FFI_SUCCESS;
49  }
50  else
51  {
53  }
54  });
55  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
std::unique_ptr< Private_Key > create_private_key(const std::string &alg_name, RandomNumberGenerator &rng, const std::string &params, const std::string &provider)
Definition: pk_algs.cpp:273
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_privkey_destroy()

int botan_privkey_destroy ( botan_privkey_t  key)

Definition at line 88 of file ffi_pkey.cpp.

References BOTAN_FFI_CHECKED_DELETE.

89  {
90  return BOTAN_FFI_CHECKED_DELETE(key);
91  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_privkey_export()

int botan_privkey_export ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len,
uint32_t  flags 
)

Definition at line 158 of file ffi_pkey.cpp.

References Botan::PKCS8::BER_encode(), BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::PKCS8::PEM_encode(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

159  {
160  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
162  return write_vec_output(out, out_len, Botan::PKCS8::BER_encode(k));
164  return write_str_output(out, out_len, Botan::PKCS8::PEM_encode(k));
165  else
167  });
168  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
Flags flags(Flag flags)
Definition: p11.h:858
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:140
secure_vector< uint8_t > BER_encode(const Private_Key &key)
Definition: pkcs8.cpp:131
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_privkey_export_encrypted()

int botan_privkey_export_encrypted ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len,
botan_rng_t  rng_obj,
const char *  pass,
const char *  ,
uint32_t  flags 
)

Definition at line 170 of file ffi_pkey.cpp.

References botan_privkey_export_encrypted_pbkdf_iter().

176  {
177  return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
178  }
Flags flags(Flag flags)
Definition: p11.h:858
int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, size_t pbkdf_iter, const char *maybe_cipher, const char *maybe_pbkdf_hash, uint32_t flags)
Definition: ffi_pkey.cpp:214

◆ botan_privkey_export_encrypted_pbkdf_iter()

int botan_privkey_export_encrypted_pbkdf_iter ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len,
botan_rng_t  rng_obj,
const char *  pass,
size_t  pbkdf_iter,
const char *  maybe_cipher,
const char *  maybe_pbkdf_hash,
uint32_t  flags 
)

Definition at line 214 of file ffi_pkey.cpp.

References Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(), Botan_FFI::safe_get(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

Referenced by botan_privkey_export_encrypted().

222  {
223  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
224  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
225 
226  const std::string cipher = (maybe_cipher ? maybe_cipher : "");
227  const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
228 
230  {
231  return write_vec_output(out, out_len,
232  Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
233  }
235  {
236  return write_str_output(out, out_len,
237  Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
238  }
239  else
240  {
241  return -2;
242  }
243  });
244  }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
Flags flags(Flag flags)
Definition: p11.h:858
std::vector< uint8_t > BER_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, size_t pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:209
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
std::string PEM_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, size_t pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:234
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_privkey_export_encrypted_pbkdf_msec()

int botan_privkey_export_encrypted_pbkdf_msec ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len,
botan_rng_t  rng_obj,
const char *  pass,
uint32_t  pbkdf_msec,
size_t *  pbkdf_iters_out,
const char *  maybe_cipher,
const char *  maybe_pbkdf_hash,
uint32_t  flags 
)

Definition at line 180 of file ffi_pkey.cpp.

References Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(), Botan_FFI::safe_get(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

189  {
190  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
191  const std::chrono::milliseconds pbkdf_time(pbkdf_msec);
192  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
193 
194  const std::string cipher = (maybe_cipher ? maybe_cipher : "");
195  const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
196 
198  {
199  return write_vec_output(out, out_len,
200  Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
201  }
203  {
204  return write_str_output(out, out_len,
205  Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
206  }
207  else
208  {
209  return -2;
210  }
211  });
212  }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
Flags flags(Flag flags)
Definition: p11.h:858
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
std::vector< uint8_t > BER_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:249
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
std::string PEM_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:275

◆ botan_privkey_export_pubkey()

int botan_privkey_export_pubkey ( botan_pubkey_t pubout,
botan_privkey_t  key_obj 
)

Definition at line 115 of file ffi_pkey.cpp.

References Botan::X509::BER_encode(), BOTAN_CURRENT_FUNCTION, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::X509::load_key(), and Botan_FFI::safe_get().

116  {
117  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
118  std::unique_ptr<Botan::Public_Key>
120 
121  *pubout = new botan_pubkey_struct(pubkey.release());
122  return BOTAN_FFI_SUCCESS;
123  });
124  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37

◆ botan_privkey_load()

int botan_privkey_load ( botan_privkey_t key,
botan_rng_t  rng_obj,
const uint8_t  bits[],
size_t  len,
const char *  password 
)

Definition at line 57 of file ffi_pkey.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::PKCS8::load_key(), and Botan_FFI::safe_get().

60  {
61  *key = nullptr;
62 
63  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
64  Botan::DataSource_Memory src(bits, len);
65 
66  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
67 
68  std::unique_ptr<Botan::Private_Key> pkcs8;
69 
70  if(password == nullptr)
71  {
72  pkcs8.reset(Botan::PKCS8::load_key(src, rng));
73  }
74  else
75  {
76  pkcs8.reset(Botan::PKCS8::load_key(src, rng, static_cast<std::string>(password)));
77  }
78 
79  if(pkcs8)
80  {
81  *key = new botan_privkey_struct(pkcs8.release());
82  return BOTAN_FFI_SUCCESS;
83  }
85  });
86  }
#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_UNKNOWN_ERROR
Definition: ffi.h:152
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::unique_ptr< Private_Key > load_key(DataSource &source, std::function< std::string()> get_pass)
Definition: pkcs8.cpp:314

◆ botan_pubkey_algo_name()

int botan_pubkey_algo_name ( botan_pubkey_t  key,
char  out[],
size_t *  out_len 
)

Definition at line 126 of file ffi_pkey.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

127  {
128  return BOTAN_FFI_DO(Botan::Public_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
129  }
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_pubkey_check_key()

int botan_pubkey_check_key ( botan_pubkey_t  key,
botan_rng_t  rng,
uint32_t  flags 
)

Returns 0 if key is valid, negative if invalid key or some other error

Definition at line 131 of file ffi_pkey.cpp.

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, BOTAN_FFI_DO, and Botan_FFI::safe_get().

132  {
133  const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
134 
135  return BOTAN_FFI_DO(Botan::Public_Key, key, k,
136  { return (k.check_key(safe_get(rng), strong) == true) ? 0 : -1; });
137  }
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:696
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_destroy()

int botan_pubkey_destroy ( botan_pubkey_t  key)

Definition at line 110 of file ffi_pkey.cpp.

References BOTAN_FFI_CHECKED_DELETE.

111  {
112  return BOTAN_FFI_CHECKED_DELETE(key);
113  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_pubkey_estimated_strength()

int botan_pubkey_estimated_strength ( botan_pubkey_t  key,
size_t *  estimate 
)

Definition at line 246 of file ffi_pkey.cpp.

References BOTAN_FFI_DO, and Botan::Public_Key::estimated_strength().

247  {
248  return BOTAN_FFI_DO(Botan::Public_Key, key, k, { *estimate = k.estimated_strength(); });
249  }
virtual size_t estimated_strength() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_export()

int botan_pubkey_export ( botan_pubkey_t  key,
uint8_t  out[],
size_t *  out_len,
uint32_t  flags 
)

Definition at line 146 of file ffi_pkey.cpp.

References Botan::X509::BER_encode(), BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::X509::PEM_encode(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

147  {
148  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
150  return write_vec_output(out, out_len, Botan::X509::BER_encode(k));
152  return write_str_output(out, out_len, Botan::X509::PEM_encode(k));
153  else
155  });
156  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
std::string PEM_encode(const Public_Key &key)
Definition: x509_key.cpp:28
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
Flags flags(Flag flags)
Definition: p11.h:858
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_fingerprint()

int botan_pubkey_fingerprint ( botan_pubkey_t  key,
const char *  hash_fn,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 251 of file ffi_pkey.cpp.

References BOTAN_FFI_DO, Botan::HashFunction::create(), and Botan_FFI::write_vec_output().

253  {
254  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
255  std::unique_ptr<Botan::HashFunction> h(Botan::HashFunction::create(hash_fn));
256  return write_vec_output(out, out_len, h->process(k.public_key_bits()));
257  });
258  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:106
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_load()

int botan_pubkey_load ( botan_pubkey_t key,
const uint8_t  bits[],
size_t  bits_len 
)

Definition at line 93 of file ffi_pkey.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::X509::load_key().

95  {
96  *key = nullptr;
97 
98  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
99  Botan::DataSource_Memory src(bits, bits_len);
100  std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
101 
102  if(pubkey == nullptr)
104 
105  *key = new botan_pubkey_struct(pubkey.release());
106  return BOTAN_FFI_SUCCESS;
107  });
108  }
#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_UNKNOWN_ERROR
Definition: ffi.h:152
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37