mirror of
https://github.com/openssl/openssl.git
synced 2025-01-30 14:01:55 +08:00
test: add test case for X508_PUBKEY_dup() function
Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14642)
This commit is contained in:
parent
239ff7f769
commit
808c63c5d0
@ -1856,31 +1856,70 @@ static int test_emptyikm_HKDF(void)
|
||||
#ifndef OPENSSL_NO_EC
|
||||
static int test_X509_PUBKEY_inplace(void)
|
||||
{
|
||||
int ret = 0;
|
||||
X509_PUBKEY *xp = NULL;
|
||||
const unsigned char *p = kExampleECPubKeyDER;
|
||||
size_t input_len = sizeof(kExampleECPubKeyDER);
|
||||
int ret = 0;
|
||||
X509_PUBKEY *xp = NULL;
|
||||
const unsigned char *p = kExampleECPubKeyDER;
|
||||
size_t input_len = sizeof(kExampleECPubKeyDER);
|
||||
|
||||
if (!TEST_ptr(xp = d2i_X509_PUBKEY(NULL, &p, input_len)))
|
||||
goto done;
|
||||
if (!TEST_ptr(xp = d2i_X509_PUBKEY(NULL, &p, input_len)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_ptr(X509_PUBKEY_get0(xp)))
|
||||
goto done;
|
||||
if (!TEST_ptr(X509_PUBKEY_get0(xp)))
|
||||
goto done;
|
||||
|
||||
p = kExampleBadECPubKeyDER;
|
||||
input_len = sizeof(kExampleBadECPubKeyDER);
|
||||
p = kExampleBadECPubKeyDER;
|
||||
input_len = sizeof(kExampleBadECPubKeyDER);
|
||||
|
||||
if (!TEST_ptr(xp = d2i_X509_PUBKEY(&xp, &p, input_len)))
|
||||
goto done;
|
||||
if (!TEST_ptr(xp = d2i_X509_PUBKEY(&xp, &p, input_len)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(X509_PUBKEY_get0(xp) == NULL))
|
||||
goto done;
|
||||
if (!TEST_true(X509_PUBKEY_get0(xp) == NULL))
|
||||
goto done;
|
||||
|
||||
ret = 1;
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
X509_PUBKEY_free(xp);
|
||||
return ret;
|
||||
done:
|
||||
X509_PUBKEY_free(xp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_X509_PUBKEY_dup(void)
|
||||
{
|
||||
int ret = 0;
|
||||
X509_PUBKEY *xp = NULL, *xq = NULL;
|
||||
const unsigned char *p = kExampleECPubKeyDER;
|
||||
size_t input_len = sizeof(kExampleECPubKeyDER);
|
||||
|
||||
if (!TEST_ptr(xp = d2i_X509_PUBKEY(NULL, &p, input_len))
|
||||
|| !TEST_ptr(xq = X509_PUBKEY_dup(xp))
|
||||
|| !TEST_ptr_ne(xp, xq))
|
||||
goto done;
|
||||
|
||||
if (!TEST_ptr(X509_PUBKEY_get0(xq))
|
||||
|| !TEST_ptr(X509_PUBKEY_get0(xp))
|
||||
|| !TEST_ptr_eq(X509_PUBKEY_get0(xq), X509_PUBKEY_get0(xp)))
|
||||
goto done;
|
||||
|
||||
X509_PUBKEY_free(xq);
|
||||
xq = NULL;
|
||||
p = kExampleBadECPubKeyDER;
|
||||
input_len = sizeof(kExampleBadECPubKeyDER);
|
||||
|
||||
if (!TEST_ptr(xp = d2i_X509_PUBKEY(&xp, &p, input_len))
|
||||
|| !TEST_ptr(xq = X509_PUBKEY_dup(xp)))
|
||||
goto done;
|
||||
|
||||
X509_PUBKEY_free(xp);
|
||||
xp = NULL;
|
||||
if (!TEST_true(X509_PUBKEY_get0(xq) == NULL))
|
||||
goto done;
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
X509_PUBKEY_free(xp);
|
||||
X509_PUBKEY_free(xq);
|
||||
return ret;
|
||||
}
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
|
||||
@ -2703,6 +2742,7 @@ int setup_tests(void)
|
||||
ADD_TEST(test_emptyikm_HKDF);
|
||||
#ifndef OPENSSL_NO_EC
|
||||
ADD_TEST(test_X509_PUBKEY_inplace);
|
||||
ADD_TEST(test_X509_PUBKEY_dup);
|
||||
ADD_ALL_TESTS(test_invalide_ec_char2_pub_range_decode,
|
||||
OSSL_NELEM(ec_der_pub_keys));
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user