diff options
author | Jack Lloyd <[email protected]> | 2017-04-03 11:23:21 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-04-03 11:23:21 -0400 |
commit | faced4459edd144d0158f4908da75e8d649d43a1 (patch) | |
tree | 469dcd200cedb7ab9c94b846075ef73ea36d0268 | |
parent | cc8d2eec88c8744152931b34d28619e7fc6e26db (diff) |
Implement botan_pubkey_load
Declared in header, but was not defined. :(
-rw-r--r-- | src/lib/ffi/ffi.cpp | 24 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 7 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 390afae81..a47412efc 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -1162,6 +1162,30 @@ int botan_privkey_load(botan_privkey_t* key, botan_rng_t rng_obj, return -1; } +int botan_pubkey_load(botan_pubkey_t* key, + const uint8_t bits[], size_t bits_len) + { + *key = nullptr; + + try + { + Botan::DataSource_Memory src(bits, bits_len); + std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src)); + + if(pubkey) + { + *key = new botan_pubkey_struct(pubkey.release()); + return 0; + } + } + catch(std::exception& e) + { + log_exception(BOTAN_CURRENT_FUNCTION, e.what()); + } + + return -1; + } + int botan_privkey_load_rsa(botan_privkey_t* key, botan_mp_t p, botan_mp_t q, botan_mp_t d) { diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index c196cf5c4..bc71c571b 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -588,6 +588,11 @@ class FFI_Unit_Tests : public Test pubkey.resize(pubkey_len); TEST_FFI_OK(botan_pubkey_export, (pub, pubkey.data(), &pubkey_len, BOTAN_PRIVKEY_EXPORT_FLAG_PEM)); + // reimport exported public key + botan_pubkey_t pub_copy; + TEST_FFI_OK(botan_pubkey_load, (&pub_copy, pubkey.data(), pubkey_len)); + TEST_FFI_OK(botan_pubkey_check_key, (pub_copy, rng, 0)); + // export private key std::vector<uint8_t> privkey; size_t privkey_len = 0; @@ -880,7 +885,7 @@ class FFI_Unit_Tests : public Test if(TEST_FFI_OK(botan_privkey_create_ecdsa, (&priv, rng, "secp384r1"))) { botan_pubkey_t pub; - REQUIRE_FFI_OK(botan_privkey_export_pubkey, (&pub, priv)); + TEST_FFI_OK(botan_privkey_export_pubkey, (&pub, priv)); ffi_test_pubkey_export(result, pub, priv, rng); |