aboutsummaryrefslogtreecommitdiff
path: root/ks_volatile.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-09-11 16:39:20 -0400
committerRob Austein <sra@hactrn.net>2016-09-11 16:39:20 -0400
commit421626cdc49cab03f9b4071ee9e836f8d095aa20 (patch)
tree8cf7ebc4c706f009bfcde3b21ee8a64061cce007 /ks_volatile.c
parent52bafc94397795e196aa516df044994692f4705f (diff)
Explicit initialization of keystore drivers instead of guessing.
Diffstat (limited to 'ks_volatile.c')
-rw-r--r--ks_volatile.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/ks_volatile.c b/ks_volatile.c
index c38d568..290c356 100644
--- a/ks_volatile.c
+++ b/ks_volatile.c
@@ -88,11 +88,7 @@ typedef struct {
} ks_t;
static db_t volatile_db;
-
-static ks_t volatile_ks = {
- { hal_ks_volatile_driver },
- &volatile_db
-};
+static ks_t volatile_ks;
static inline ks_t *ks_to_ksv(hal_ks_t *ks)
{
@@ -128,12 +124,29 @@ static hal_error_t ks_init(db_t *db)
return err;
}
+static hal_error_t ks_volatile_init(const hal_ks_driver_t * const driver)
+{
+ if (volatile_ks.ks.driver != NULL)
+ return HAL_ERROR_KEYSTORE_ACCESS;
+ volatile_ks.ks.driver = driver;
+ volatile_ks.db = &volatile_db;
+ return ks_init(volatile_ks.db);
+}
+
+static hal_error_t ks_volatile_shutdown(const hal_ks_driver_t * const driver)
+{
+ if (volatile_ks.ks.driver != driver)
+ return HAL_ERROR_KEYSTORE_ACCESS;
+ memset(&volatile_ks, 0, sizeof(volatile_ks));
+ return HAL_OK;
+}
+
static hal_error_t ks_volatile_open(const hal_ks_driver_t * const driver,
hal_ks_t **ks)
{
assert(driver != NULL && ks != NULL);
*ks = &volatile_ks.ks;
- return ks_init(volatile_ks.db);
+ return HAL_OK;
}
static hal_error_t ks_volatile_close(hal_ks_t *ks)
@@ -294,6 +307,8 @@ static hal_error_t ks_list(hal_ks_t *ks,
}
const hal_ks_driver_t hal_ks_volatile_driver[1] = {{
+ ks_volatile_init,
+ ks_volatile_shutdown,
ks_volatile_open,
ks_volatile_close,
ks_store,