commit 64d634574a41ce62d503d5363f43d28d1ee61b18
parent e8b0df236debe5f9500acba4eec72c230edfa6ac
Author: lash <dev@holbrook.no>
Date: Tue, 15 Apr 2025 23:08:41 +0100
Add lock key test
Diffstat:
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/src/lq/crypto.h b/src/lq/crypto.h
@@ -60,7 +60,7 @@ enum lq_keystate_e {
*/
struct lq_privatekey_t {
short key_typ; ///< Key type identifier. Unused for now.
- char key_state; ///< Key state flags.
+ unsigned char key_state; ///< Key state flags.
void *impl; ///< Private key implementation object
};
typedef struct lq_privatekey_t LQPrivKey;
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <string.h>
+#include <rerr.h>
+
#include "lq/crypto.h"
#include "lq/config.h"
#include "lq/io.h"
@@ -49,6 +51,33 @@ START_TEST(check_privatekey) {
}
END_TEST
+START_TEST(check_privatekey_lock) {
+ int r;
+ LQPrivKey *pk;
+
+ pk = lq_privatekey_new(passphrase, passphrase_len);
+ ck_assert_ptr_nonnull(pk);
+
+ lq_privatekey_lock(pk, passphrase, passphrase_len);
+ r = lq_privatekey_lock(pk, passphrase, passphrase_len);
+ ck_assert_int_eq(r, ERR_NOOP);
+
+ r = lq_privatekey_unlock(pk, passphrase, passphrase_len);
+ ck_assert_int_eq(r, ERR_OK);
+
+ r = lq_privatekey_unlock(pk, passphrase, passphrase_len);
+ ck_assert_int_eq(r, ERR_NOOP);
+
+ r = lq_privatekey_lock(pk, passphrase, passphrase_len);
+ ck_assert_int_eq(r, ERR_OK);
+
+ r = lq_privatekey_lock(pk, passphrase, passphrase_len);
+ ck_assert_int_eq(r, ERR_NOOP);
+
+ lq_privatekey_free(pk);
+}
+END_TEST
+
START_TEST(check_publickey) {
LQPrivKey *pk;
LQPubKey *pubk;
@@ -182,6 +211,7 @@ Suite * common_suite(void) {
tc = tcase_create("file");
tcase_add_test(tc, check_digest);
tcase_add_test(tc, check_privatekey);
+ tcase_add_test(tc, check_privatekey_lock);
tcase_add_test(tc, check_publickey);
tcase_add_test(tc, check_signature);
tcase_add_test(tc, check_verify);