Skip to content

Commit cfc4f62

Browse files
committed
also test FILE-based PEM API's
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 15fc300 commit cfc4f62

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/pem_test.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@
44

55
#if defined(LTC_PEM) && defined(LTC_TEST_READDIR) && !defined(LTC_EASY)
66

7+
#ifdef LTC_SSH
8+
9+
static int password_get_ssh(void **p, unsigned long *l, void *u)
10+
{
11+
LTC_UNUSED_PARAM(u);
12+
*p = strdup("abc123");
13+
*l = 6;
14+
return 0;
15+
}
16+
static int s_pem_decode_ssh(const void *in, unsigned long inlen, void *key)
17+
{
18+
password_ctx pw_ctx;
19+
pw_ctx.callback = password_get_ssh;
20+
return pem_decode_openssh(in, inlen, key, &pw_ctx);
21+
}
22+
static int s_pem_decode_ssh_f(FILE *f, void *key)
23+
{
24+
password_ctx pw_ctx;
25+
pw_ctx.callback = password_get_ssh;
26+
return pem_decode_openssh_filehandle(f, key, &pw_ctx);
27+
}
28+
29+
#endif
30+
731
static int password_get(void **p, unsigned long *l, void *u)
832
{
933
LTC_UNUSED_PARAM(u);
@@ -59,6 +83,17 @@ static int s_pem_decode(const void *in, unsigned long inlen, void *key)
5983
return s_key_cmp(key);
6084
}
6185

86+
static int s_pem_decode_f(FILE *f, void *key)
87+
{
88+
password_ctx pw_ctx;
89+
int err;
90+
pw_ctx.callback = password_get;
91+
if ((err = pem_decode_filehandle(f, key, &pw_ctx)) != CRYPT_OK) {
92+
return err;
93+
}
94+
return s_key_cmp(key);
95+
}
96+
6297
static void s_pem_free_key(ltc_pka_key *key)
6398
{
6499
switch (key->id) {
@@ -100,8 +135,13 @@ int pem_test(void)
100135

101136

102137
DO(test_process_dir("tests/pem", &key, s_pem_decode, NULL, (dir_cleanup_cb)s_pem_free_key, "pem_test"));
138+
DO(test_process_dir("tests/pem", &key, NULL, s_pem_decode_f, (dir_cleanup_cb)s_pem_free_key, "pem_test_filehandle"));
103139
DO(test_process_dir("tests/pem-ecc-pkcs8", &key, s_pem_decode, NULL, (dir_cleanup_cb)s_pem_free_key, "pem_test+ecc"));
140+
DO(test_process_dir("tests/pem-ecc-pkcs8", &key, NULL, s_pem_decode_f, (dir_cleanup_cb)s_pem_free_key, "pem_test_filehandle+ecc"));
141+
#ifdef LTC_SSH
104142
DO(test_process_dir("tests/ssh", &key, s_pem_decode_ssh, NULL, (dir_cleanup_cb)s_pem_free_key, "pem_test+ssh"));
143+
DO(test_process_dir("tests/ssh", &key, NULL, s_pem_decode_ssh_f, (dir_cleanup_cb)s_pem_free_key, "pem_test_filehandle+ssh"));
144+
#endif
105145

106146
#if defined(LTC_MDSA)
107147
dsa_free(&s_dsa_key_should);

0 commit comments

Comments
 (0)