Skip to content

Commit b74731d

Browse files
committed
Add test for wolfSSL_use_AltPrivateKey_Label to verify successful key label allocation
1 parent 72c1dd7 commit b74731d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/api.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,36 @@ static int test_wolfSSL_use_AltPrivateKey_Id(void)
17281728
return EXPECT_RESULT();
17291729
}
17301730

1731+
/* Test wolfSSL_use_AltPrivateKey_Label.
1732+
* Verify that a valid key label can be set successfully. Guards against an
1733+
* inverted AllocDer return check (== 0 vs != 0) that would treat successful
1734+
* allocation as failure. */
1735+
static int test_wolfSSL_use_AltPrivateKey_Label(void)
1736+
{
1737+
EXPECT_DECLS;
1738+
#if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_TLS) && \
1739+
!defined(NO_WOLFSSL_CLIENT)
1740+
WOLFSSL_CTX* ctx = NULL;
1741+
WOLFSSL* ssl = NULL;
1742+
1743+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
1744+
ExpectNotNull(ssl = wolfSSL_new(ctx));
1745+
1746+
/* Negative tests. */
1747+
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(NULL, "label", INVALID_DEVID),
1748+
0);
1749+
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, NULL, INVALID_DEVID), 0);
1750+
1751+
/* Positive test — valid label should succeed. */
1752+
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, "test_label",
1753+
INVALID_DEVID), 1);
1754+
1755+
wolfSSL_free(ssl);
1756+
wolfSSL_CTX_free(ctx);
1757+
#endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_TLS && !NO_WOLFSSL_CLIENT */
1758+
return EXPECT_RESULT();
1759+
}
1760+
17311761

17321762
/*----------------------------------------------------------------------------*
17331763
| Context
@@ -35346,6 +35376,7 @@ TEST_CASE testCases[] = {
3534635376
TEST_DECL(test_dual_alg_ecdsa_mldsa),
3534735377

3534835378
TEST_DECL(test_wolfSSL_use_AltPrivateKey_Id),
35379+
TEST_DECL(test_wolfSSL_use_AltPrivateKey_Label),
3534935380

3535035381
/*********************************
3535135382
* OpenSSL compatibility API tests

0 commit comments

Comments
 (0)