aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-05-15 23:49:03 -0400
committerRob Austein <sra@hactrn.net>2016-05-15 23:49:03 -0400
commit19de5cd21bde4dcee12c40cd53d5592cbd91bc7b (patch)
tree94601108c51a3417a0bcea9c0955a55c34ab8db1
parent0690aa3d48966a4b151a468fd3a0a65bb99de439 (diff)
Tweak keystore API to allow update-in-place, so hal_ks_rename() will work.
-rw-r--r--hal_internal.h3
-rw-r--r--ks.c4
-rw-r--r--ks_flash.c5
-rw-r--r--ks_mmap.c5
-rw-r--r--ks_volatile.c5
5 files changed, 13 insertions, 9 deletions
diff --git a/hal_internal.h b/hal_internal.h
index 4b572eb..253dc09 100644
--- a/hal_internal.h
+++ b/hal_internal.h
@@ -298,7 +298,8 @@ typedef struct {
extern const hal_ks_keydb_t *hal_ks_get_keydb(void);
extern hal_error_t hal_ks_set_keydb(const hal_ks_key_t * const key,
- const int loc);
+ const int loc,
+ const int updating);
extern hal_error_t hal_ks_del_keydb(const int loc);
diff --git a/ks.c b/ks.c
index 758162b..15dcaf3 100644
--- a/ks.c
+++ b/ks.c
@@ -113,7 +113,7 @@ hal_error_t hal_ks_store(const hal_key_type_t type,
k.curve = curve;
k.flags = flags;
- if ((err = hal_ks_set_keydb(&k, *hint)) != HAL_OK)
+ if ((err = hal_ks_set_keydb(&k, *hint, 0)) != HAL_OK)
return err;
return HAL_OK;
@@ -273,7 +273,7 @@ hal_error_t hal_ks_rename(const hal_key_type_t type,
memcpy(k.name, new_name, new_name_len);
k.name_len = new_name_len;
- return hal_ks_set_keydb(&k, *hint);
+ return hal_ks_set_keydb(&k, *hint, 1);
}
hal_error_t hal_ks_list(hal_pkey_info_t *result,
diff --git a/ks_flash.c b/ks_flash.c
index eee259b..95aa6ed 100644
--- a/ks_flash.c
+++ b/ks_flash.c
@@ -46,9 +46,10 @@ const hal_ks_keydb_t *hal_ks_get_keydb(void)
}
hal_error_t hal_ks_set_keydb(const hal_ks_key_t * const key,
- const int loc)
+ const int loc,
+ const int updating)
{
- if (key == NULL || loc < 0 || loc >= sizeof(db->keys)/sizeof(*db->keys) || key->in_use)
+ if (key == NULL || loc < 0 || loc >= sizeof(db->keys)/sizeof(*db->keys) || (!key->in_use != !updating))
return HAL_ERROR_BAD_ARGUMENTS;
#error Not sure what goes here yet either
diff --git a/ks_mmap.c b/ks_mmap.c
index e62aa46..cca9d3f 100644
--- a/ks_mmap.c
+++ b/ks_mmap.c
@@ -104,9 +104,10 @@ const hal_ks_keydb_t *hal_ks_get_keydb(void)
}
hal_error_t hal_ks_set_keydb(const hal_ks_key_t * const key,
- const int loc)
+ const int loc,
+ const int updating)
{
- if (key == NULL || loc < 0 || loc >= sizeof(db->keys)/sizeof(*db->keys) || key->in_use)
+ if (key == NULL || loc < 0 || loc >= sizeof(db->keys)/sizeof(*db->keys) || (!key->in_use != !updating))
return HAL_ERROR_BAD_ARGUMENTS;
db->keys[loc] = *key;
diff --git a/ks_volatile.c b/ks_volatile.c
index 9a47d52..00f656a 100644
--- a/ks_volatile.c
+++ b/ks_volatile.c
@@ -72,9 +72,10 @@ const hal_ks_keydb_t *hal_ks_get_keydb(void)
}
hal_error_t hal_ks_set_keydb(const hal_ks_key_t * const key,
- const int loc)
+ const int loc,
+ const int updating)
{
- if (key == NULL || loc < 0 || loc >= sizeof(db->keys)/sizeof(*db->keys) || key->in_use)
+ if (key == NULL || loc < 0 || loc >= sizeof(db->keys)/sizeof(*db->keys) || (!key->in_use != !updating))
return HAL_ERROR_BAD_ARGUMENTS;
db->keys[loc] = *key;