diff options
author | slontis <shane.lontis@oracle.com> | 2022-05-30 14:32:36 +1000 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-11-02 11:25:48 +0100 |
commit | 820723dde0c9ec9a4fc68406a0e5aee1dc83f836 (patch) | |
tree | 5c25c3e402d732de0b57ca62bb30977502ce00bf /test/evp_extra_test2.c | |
parent | 57d2bccdb2112cc09de1bec585da878161b1364f (diff) |
Add d2i_PUBKEY_ex_fp and d2i_PUBKEY_ex_bio.
These functions pass a library content and prop query.
The i2d documentation related to these functions has been corrected since the bio and fp functions always return 0 or 1.
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18427)
Diffstat (limited to 'test/evp_extra_test2.c')
-rw-r--r-- | test/evp_extra_test2.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/evp_extra_test2.c b/test/evp_extra_test2.c index fc73994ca3..b03b6bd234 100644 --- a/test/evp_extra_test2.c +++ b/test/evp_extra_test2.c @@ -359,6 +359,35 @@ static int test_dh_tofrom_data_select(void) #endif #ifndef OPENSSL_NO_EC + +static int test_ec_d2i_i2d_pubkey(void) +{ + int ret = 0; + FILE *fp = NULL; + EVP_PKEY *key = NULL, *outkey = NULL; + static const char *filename = "pubkey.der"; + + if (!TEST_ptr(fp = fopen(filename, "wb")) + || !TEST_ptr(key = EVP_PKEY_Q_keygen(mainctx, NULL, "EC", "P-256")) + || !TEST_true(i2d_PUBKEY_fp(fp, key)) + || !TEST_int_eq(fclose(fp), 0)) + goto err; + fp = NULL; + + if (!TEST_ptr(fp = fopen(filename, "rb")) + || !TEST_ptr(outkey = d2i_PUBKEY_ex_fp(fp, NULL, mainctx, NULL)) + || !TEST_int_eq(EVP_PKEY_eq(key, outkey), 1)) + goto err; + + ret = 1; + +err: + EVP_PKEY_free(outkey); + EVP_PKEY_free(key); + fclose(fp); + return ret; +} + static int test_ec_tofrom_data_select(void) { int ret; @@ -1117,6 +1146,7 @@ int setup_tests(void) ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 2); ADD_TEST(test_ec_tofrom_data_select); ADD_TEST(test_ecx_tofrom_data_select); + ADD_TEST(test_ec_d2i_i2d_pubkey); #else ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 1); #endif |