Commit 73ccd974 authored by Daniel Salzman's avatar Daniel Salzman

libdnssec: unify keystore function names

parent e186e6cf
......@@ -57,7 +57,7 @@ int kdnssec_generate_key(kdnssec_ctx_t *ctx, kdnssec_generate_flags_t flags,
// generate key in the keystore
char *id = NULL;
int r = dnssec_keystore_generate_key(ctx->keystore, algorithm, size, &id);
int r = dnssec_keystore_generate(ctx->keystore, algorithm, size, &id);
if (r != KNOT_EOK) {
return r;
}
......@@ -81,7 +81,7 @@ int kdnssec_generate_key(kdnssec_ctx_t *ctx, kdnssec_generate_flags_t flags,
dnssec_key_set_flags(dnskey, dnskey_flags(flags & DNSKEY_GENERATE_SEP_ON));
dnssec_key_set_algorithm(dnskey, algorithm);
r = dnssec_key_import_keystore(dnskey, ctx->keystore, id);
r = dnssec_keystore_export(ctx->keystore, id, dnskey);
if (r != KNOT_EOK) {
dnssec_key_free(dnskey);
free(id);
......@@ -161,7 +161,7 @@ int kdnssec_delete_key(kdnssec_ctx_t *ctx, knot_kasp_key_t *key_ptr)
}
if (!key_still_used_in_keystore && !key_ptr->is_pub_only) {
ret = dnssec_keystore_remove_key(ctx->keystore, key_ptr->id);
ret = dnssec_keystore_remove(ctx->keystore, key_ptr->id);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -322,7 +322,7 @@ static int load_private_keys(dnssec_keystore_t *keystore, zone_keyset_t *keyset)
if (!key->is_active && !key->is_post_active) {
continue;
}
int r = dnssec_key_import_keystore(key->key, keystore, key->id);
int r = dnssec_keystore_export(keystore, key->id, key->key);
switch (r) {
case DNSSEC_EOK:
case DNSSEC_KEY_ALREADY_PRESENT:
......
......@@ -35,7 +35,7 @@
* dnssec_keystore_t *store = NULL;
*
* // create key store access context
* dnssec_keystore_init_pkcs8_dir(&store);
* dnssec_keystore_init_pkcs8(&store);
*
* // open the key store
* result = dnssec_keystore_open(&store, "/path/to/keydb");
......@@ -47,7 +47,7 @@
* int algorithm = DNSSEC_KEY_ALGORITHM_RSA_SHA256;
* unsigned bits = 2048;
* char *id = NULL;
* int dnssec_keystore_generate_key(store, algorithm, bits, &key_id);
* int dnssec_keystore_generate(store, algorithm, bits, &key_id);
* if (result != DNSSEC_EOK) {
* dnssec_keystore_close(store);
* return result;
......@@ -63,8 +63,10 @@
* return result;
* }
*
* dnssec_key_set_algorithm(key, algorithm);
*
* // import the key from the key store
* result = dnssec_key_import_keystore(key, store, key_id, algorithm);
* result = dnssec_keystore_export(store, key_id, key);
* if (result != DNSSEC_EOK) {
* free(key_id);
* dnssec_key_free(key);
......@@ -154,9 +156,9 @@ int dnssec_keystore_close(dnssec_keystore_t *store);
*
* \return Error code, DNSSEC_EOK if successful.
*/
int dnssec_keystore_generate_key(dnssec_keystore_t *store,
dnssec_key_algorithm_t algorithm,
unsigned bits, char **id_ptr);
int dnssec_keystore_generate(dnssec_keystore_t *store,
dnssec_key_algorithm_t algorithm,
unsigned bits, char **id_ptr);
/*!
* Import an existing key into the key store.
......@@ -178,20 +180,20 @@ int dnssec_keystore_import(dnssec_keystore_t *store, const dnssec_binary_t *pem,
*
* \return Error code, DNSSEC_EOK if successful.
*/
int dnssec_keystore_remove_key(dnssec_keystore_t *store, const char *id);
int dnssec_keystore_remove(dnssec_keystore_t *store, const char *id);
/*!
* Import public and/or private key from the key store into a DNSSEC key.
* Export public and/or private key from the key store into a DNSSEC key.
*
* The key algorithm has to be set before calling this function.
*
* \param key DNSSEC key to be initialized.
* \param keystore Private key store.
* \param id ID of the key.
* \param store Private key store.
* \param id ID of the key.
* \param key DNSSEC key to be initialized.
*
* \return Error code, DNSSEC_EOK if successful.
*/
int dnssec_key_import_keystore(dnssec_key_t *key, dnssec_keystore_t *keystore,
const char *id);
int dnssec_keystore_export(dnssec_keystore_t *store, const char *id,
dnssec_key_t *key);
/*! @} */
......@@ -101,9 +101,9 @@ int dnssec_keystore_close(dnssec_keystore_t *store)
}
_public_
int dnssec_keystore_generate_key(dnssec_keystore_t *store,
dnssec_key_algorithm_t _algorithm,
unsigned bits, char **id_ptr)
int dnssec_keystore_generate(dnssec_keystore_t *store,
dnssec_key_algorithm_t _algorithm,
unsigned bits, char **id_ptr)
{
if (!store || !_algorithm || !id_ptr) {
return DNSSEC_EINVAL;
......@@ -135,20 +135,20 @@ int dnssec_keystore_import(dnssec_keystore_t *store, const dnssec_binary_t *pem,
}
_public_
int dnssec_keystore_remove_key(dnssec_keystore_t *store, const char *key_id)
int dnssec_keystore_remove(dnssec_keystore_t *store, const char *id)
{
if (!store || !key_id) {
if (!store || !id) {
return DNSSEC_EINVAL;
}
return store->functions->remove_key(store->ctx, key_id);
return store->functions->remove_key(store->ctx, id);
}
_public_
int dnssec_key_import_keystore(dnssec_key_t *key, dnssec_keystore_t *store,
const char *id)
int dnssec_keystore_export(dnssec_keystore_t *store, const char *id,
dnssec_key_t *key)
{
if (!key || !store || !id || dnssec_key_get_algorithm(key) == 0) {
if (!store || !id || dnssec_key_get_algorithm(key) == 0 || !key) {
return DNSSEC_EINVAL;
}
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -517,7 +517,7 @@ static int import_key(kdnssec_ctx_t *ctx, unsigned backend, const char *param,
dnssec_key_set_algorithm(key, ctx->policy->algorithm);
// fill key structure from keystore (incl. pubkey from privkey computation)
ret = dnssec_key_import_keystore(key, ctx->keystore, keyid);
ret = dnssec_keystore_export(ctx->keystore, keyid, key);
if (ret != DNSSEC_EOK) {
goto fail;
}
......
......@@ -234,7 +234,7 @@ static void create_dnskeys(dnssec_keystore_t *keystore,
r = dnssec_key_set_algorithm(p11_key, algorithm);
ok(r == DNSSEC_EOK, MSG_PKCS11 " dnssec_set_key_algorithm()");
r = dnssec_key_import_keystore(p11_key, keystore, id);
r = dnssec_keystore_export(keystore, id, p11_key);
ok(r == DNSSEC_EOK, MSG_PKCS11 " dnssec_key_import_keystore()");
// construct software public key
......@@ -336,8 +336,8 @@ static void test_algorithm(dnssec_keystore_t *store,
diag("algorithm %d, generated key", params->algorithm);
r = dnssec_keystore_generate_key(store, params->algorithm, params->bit_size, &id_generate);
ok(r == DNSSEC_EOK && id_generate != NULL, "dnssec_keystore_generate_key()");
r = dnssec_keystore_generate(store, params->algorithm, params->bit_size, &id_generate);
ok(r == DNSSEC_EOK && id_generate != NULL, "dnssec_keystore_generate()");
test_key_use(store, params->algorithm, id_generate);
diag("algorithm %d, imported key", params->algorithm);
......
......@@ -44,13 +44,13 @@ int main(void)
// writing new content
char *id_A = NULL;
r = dnssec_keystore_generate_key(store, DNSSEC_KEY_ALGORITHM_RSA_SHA256,
1024, &id_A);
r = dnssec_keystore_generate(store, DNSSEC_KEY_ALGORITHM_RSA_SHA256,
1024, &id_A);
ok(r == DNSSEC_EOK, "generate A");
char *id_B = NULL;
r = dnssec_keystore_generate_key(store, DNSSEC_KEY_ALGORITHM_RSA_SHA256,
1024, &id_B);
r = dnssec_keystore_generate(store, DNSSEC_KEY_ALGORITHM_RSA_SHA256,
1024, &id_B);
ok(r == DNSSEC_EOK, "generate B");
// reading existing content
......@@ -58,24 +58,24 @@ int main(void)
dnssec_key_t *key = NULL;
dnssec_key_new(&key);
dnssec_key_set_algorithm(key, DNSSEC_KEY_ALGORITHM_RSA_SHA256);
r = dnssec_key_import_keystore(key, store, id_A);
r = dnssec_keystore_export(store, id_A, key);
ok(r == DNSSEC_EOK, "read A");
dnssec_key_free(key);
dnssec_key_new(&key);
dnssec_key_set_algorithm(key, DNSSEC_KEY_ALGORITHM_RSA_SHA256);
r = dnssec_key_import_keystore(key, store, id_B);
r = dnssec_keystore_export(store, id_B, key);
ok(r == DNSSEC_EOK, "read B");
dnssec_key_free(key);
// content removal
r = dnssec_keystore_remove_key(store, id_A);
r = dnssec_keystore_remove(store, id_A);
ok(r == DNSSEC_EOK, "remove A");
dnssec_key_new(&key);
dnssec_key_set_algorithm(key, DNSSEC_KEY_ALGORITHM_RSA_SHA256);
r = dnssec_key_import_keystore(key, store, id_A);
r = dnssec_keystore_export(store, id_A, key);
ok(r == DNSSEC_ENOENT, "read removed");
// cleanup
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment