diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-05-06 18:33:02 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-05-06 18:33:02 +0200 |
commit | 3526c44a38195aaea2ab48a220728df175ab9429 (patch) | |
tree | a2aaf925bb0a73658febb175720c4996ea6e1571 /src/exchangedb/exchangedb_keyio.c | |
parent | c334ba61f4b371755cc3e4e5afd22fc4054c0836 (diff) | |
download | exchange-3526c44a38195aaea2ab48a220728df175ab9429.tar.xz |
refactor code to write signing keys in same module where we read them
Diffstat (limited to 'src/exchangedb/exchangedb_keyio.c')
-rw-r--r-- | src/exchangedb/exchangedb_keyio.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/exchangedb/exchangedb_keyio.c b/src/exchangedb/exchangedb_keyio.c index 5f29cb0d8..773fc9284 100644 --- a/src/exchangedb/exchangedb_keyio.c +++ b/src/exchangedb/exchangedb_keyio.c @@ -114,6 +114,63 @@ TALER_EXCHANGEDB_signing_keys_iterate (const char *exchange_base_dir, /** + * Obtain the name of the directory we use to store signing + * keys created at time @a start. + * + * @param start time at which we create the signing key + * @return name of the directory we should use, basically "$EXCHANGEDIR/$TIME/"; + * (valid until next call to this function) + */ +static char * +get_signkey_file (const char *exchange_directory, + struct GNUNET_TIME_Absolute start) +{ + char *dir; + + GNUNET_asprintf (&dir, + "%s" DIR_SEPARATOR_STR TALER_EXCHANGEDB_DIR_SIGNING_KEYS DIR_SEPARATOR_STR "%llu", + exchange_directory, + (unsigned long long) start.abs_value_us); + return dir; +} + + +/** + * Exports a signing key to the given file. + * + * @param exchange_base_dir base directory for the keys + * @param start start time of the validity for the key + * @param ski the signing key + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure. + */ +int +TALER_EXCHANGEDB_signing_key_write (const char *exchange_base_dir, + struct GNUNET_TIME_Absolute start, + const struct TALER_EXCHANGEDB_PrivateSigningKeyInformationP *ski) +{ + char *skf; + ssize_t nwrite; + + skf = get_signkey_file (exchange_base_dir, + start); + nwrite = GNUNET_DISK_fn_write (skf, + ski, + sizeof (struct TALER_EXCHANGEDB_PrivateSigningKeyInformationP), + GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_USER_READ); + if (sizeof (struct TALER_EXCHANGEDB_PrivateSigningKeyInformationP) != nwrite) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "write", + skf); + GNUNET_free (skf); + return GNUNET_SYSERR; + } + GNUNET_free (skf); + return GNUNET_OK; +} + + +/** * Import a denomination key from the given file. * * @param filename the file to import the key from |