From 421626cdc49cab03f9b4071ee9e836f8d095aa20 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 11 Sep 2016 16:39:20 -0400 Subject: Explicit initialization of keystore drivers instead of guessing. --- ks_volatile.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'ks_volatile.c') 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, -- cgit v1.2.3