[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: GNUNET_CRYPTO_eddsa_key_from_file handle
From: |
gnunet |
Subject: |
[gnunet] branch master updated: GNUNET_CRYPTO_eddsa_key_from_file handles do_create correctly |
Date: |
Wed, 15 Dec 2021 14:32:44 +0100 |
This is an automated email from the git hooks/post-receive script.
oec pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new f27fe484c GNUNET_CRYPTO_eddsa_key_from_file handles do_create correctly
f27fe484c is described below
commit f27fe484c60be69e762e038a84331a3a72111957
Author: Özgür Kesim <oec@codeblau.de>
AuthorDate: Wed Dec 15 14:27:00 2021 +0100
GNUNET_CRYPTO_eddsa_key_from_file handles do_create correctly
The function GNUNET_CRYPTO_eddsa_key_from_file returns now
- GNUNET_OK on success,
- GNUNET_NO if do_create was set but we found an existing file,
- GNUNET_SYSERR on failure _or_ if the file didn't exist and
do_create was not set
Fixes #7106
---
src/util/crypto_ecc_setup.c | 11 +++++++++--
src/util/test_crypto_eddsa.c | 16 ++++++++--------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c
index f7cd8c6d9..21ce48eef 100644
--- a/src/util/crypto_ecc_setup.c
+++ b/src/util/crypto_ecc_setup.c
@@ -134,8 +134,10 @@ read_from_file (const char *filename,
* @param filename name of file to use to store the key
* @param do_create should a file be created?
* @param[out] pkey set to the private key from @a filename on success
- * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
- * we found an existing file, #GNUNET_SYSERR on failure
+ * @return - #GNUNET_OK on success,
+ * - #GNUNET_NO if @a do_create was set but we found an existing file,
+ * - #GNUNET_SYSERR on failure _or_ if the file didn't exist and @a
+ * do_create was not set
*/
enum GNUNET_GenericReturnValue
GNUNET_CRYPTO_eddsa_key_from_file (const char *filename,
@@ -152,6 +154,11 @@ GNUNET_CRYPTO_eddsa_key_from_file (const char *filename,
/* file existed, report that we didn't create it... */
return (do_create) ? GNUNET_NO : GNUNET_OK;
}
+ else if (! do_create)
+ {
+ return GNUNET_SYSERR;
+ }
+
GNUNET_CRYPTO_eddsa_key_create (pkey);
ret = GNUNET_DISK_fn_write (filename,
pkey,
diff --git a/src/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c
index 10d6a4e91..459619ff2 100644
--- a/src/util/test_crypto_eddsa.c
+++ b/src/util/test_crypto_eddsa.c
@@ -216,12 +216,16 @@ testCreateFromFile (void)
struct GNUNET_CRYPTO_EddsaPublicKey p1;
struct GNUNET_CRYPTO_EddsaPublicKey p2;
- GNUNET_assert (0 <=
+ /* do_create == GNUNET_YES and non-existing file MUST return GNUNET_YES */
+ GNUNET_assert (0 == unlink (KEYFILE) || ENOENT == errno);
+ GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE,
GNUNET_YES,
&key));
GNUNET_CRYPTO_eddsa_key_get_public (&key,
&p1);
+
+ /* do_create == GNUNET_YES and _existing_ file MUST return GNUNET_NO */
GNUNET_assert (GNUNET_NO ==
GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE,
GNUNET_YES,
@@ -231,16 +235,13 @@ testCreateFromFile (void)
GNUNET_assert (0 ==
GNUNET_memcmp (&p1,
&p2));
+
+ /* do_create == GNUNET_NO and non-existing file MUST return GNUNET_SYSERR */
GNUNET_assert (0 == unlink (KEYFILE));
- GNUNET_assert (GNUNET_OK ==
+ GNUNET_assert (GNUNET_SYSERR ==
GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE,
GNUNET_NO,
&key));
- GNUNET_CRYPTO_eddsa_key_get_public (&key,
- &p2);
- GNUNET_assert (0 !=
- GNUNET_memcmp (&p1,
- &p2));
return GNUNET_OK;
}
@@ -299,7 +300,6 @@ main (int argc, char *argv[])
failure_count++;
if (GNUNET_OK != testCreateFromFile ())
failure_count++;
- GNUNET_assert (0 == unlink (KEYFILE));
perf_keygen ();
if (0 != failure_count)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: GNUNET_CRYPTO_eddsa_key_from_file handles do_create correctly,
gnunet <=