From b1214089088d0321142f64abf2c820da9561bba9 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Fri, 9 Sep 2016 00:33:52 -0400 Subject: Simplify hal_rpc_pkey_find() by removing `type` argument. Now that key names are UUIDs generated by the HSM, there's no real need to specify type key type when looking up a key, and removing the `type` argument allows a few simplifications of both the internal keystore API and of client code calling the public RPC API. --- ks_flash.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ks_flash.c') diff --git a/ks_flash.c b/ks_flash.c index c3d12aa..9393100 100644 --- a/ks_flash.c +++ b/ks_flash.c @@ -291,13 +291,12 @@ static inline int acceptable_key_type(const hal_key_type_t type) } } -static inline hal_ks_key_t *find(const hal_key_type_t type, - const hal_uuid_t * const name) +static inline hal_ks_key_t *find(const hal_uuid_t * const name) { - assert(name != NULL && acceptable_key_type(type)); + assert(name != NULL); for (int i = 0; i < sizeof(db.keys)/sizeof(*db.keys); i++) - if (db.keys[i].in_use && db.keys[i].type == type && hal_uuid_cmp(&db.keys[i].name, name) == 0) + if (db.keys[i].in_use && hal_uuid_cmp(&db.keys[i].name, name) == 0) return &db.keys[i]; return NULL; @@ -310,11 +309,12 @@ static hal_error_t ks_fetch(hal_ks_t *ks, if (ks != &db.ks || slot == NULL || !acceptable_key_type(slot->type)) return HAL_ERROR_BAD_ARGUMENTS; - const hal_ks_key_t * const k = find(slot->type, &slot->name); + const hal_ks_key_t * const k = find(&slot->name); if (k == NULL) return HAL_ERROR_KEY_NOT_FOUND; + slot->type = k->type; slot->curve = k->curve; slot->flags = k->flags; @@ -384,7 +384,7 @@ static hal_error_t ks_store(hal_ks_t *ks, if (ks != &db.ks || slot == NULL || der == NULL || der_len == 0 || !acceptable_key_type(slot->type)) return HAL_ERROR_BAD_ARGUMENTS; - if (find(slot->type, &slot->name) != NULL) + if (find(&slot->name) != NULL) return HAL_ERROR_KEY_NAME_IN_USE; int loc = -1; @@ -482,7 +482,7 @@ static hal_error_t ks_delete(hal_ks_t *ks, if (ks != &db.ks || slot == NULL || !acceptable_key_type(slot->type)) return HAL_ERROR_BAD_ARGUMENTS; - hal_ks_key_t *k = find(slot->type, &slot->name); + hal_ks_key_t *k = find(&slot->name); if (k == NULL) return HAL_ERROR_KEY_NOT_FOUND; -- cgit v1.2.3