Skip to content

Commit ae3c00f

Browse files
committed
Add test for wolfSSL_use_AltPrivateKey_Label to verify successful key label allocation
1 parent 13af706 commit ae3c00f

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
@@ -1715,6 +1715,36 @@ static int test_wolfSSL_use_AltPrivateKey_Id(void)
17151715
return EXPECT_RESULT();
17161716
}
17171717

1718+
/* Test wolfSSL_use_AltPrivateKey_Label.
1719+
* Verify that a valid key label can be set successfully. Guards against an
1720+
* inverted AllocDer return check (== 0 vs != 0) that would treat successful
1721+
* allocation as failure. */
1722+
static int test_wolfSSL_use_AltPrivateKey_Label(void)
1723+
{
1724+
EXPECT_DECLS;
1725+
#if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_TLS) && \
1726+
!defined(NO_WOLFSSL_CLIENT)
1727+
WOLFSSL_CTX* ctx = NULL;
1728+
WOLFSSL* ssl = NULL;
1729+
1730+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
1731+
ExpectNotNull(ssl = wolfSSL_new(ctx));
1732+
1733+
/* Negative tests. */
1734+
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(NULL, "label", INVALID_DEVID),
1735+
0);
1736+
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, NULL, INVALID_DEVID), 0);
1737+
1738+
/* Positive test — valid label should succeed. */
1739+
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, "test_label",
1740+
INVALID_DEVID), 1);
1741+
1742+
wolfSSL_free(ssl);
1743+
wolfSSL_CTX_free(ctx);
1744+
#endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_TLS && !NO_WOLFSSL_CLIENT */
1745+
return EXPECT_RESULT();
1746+
}
1747+
17181748

17191749
/*----------------------------------------------------------------------------*
17201750
| Context
@@ -35158,6 +35188,7 @@ TEST_CASE testCases[] = {
3515835188
TEST_DECL(test_dual_alg_ecdsa_mldsa),
3515935189

3516035190
TEST_DECL(test_wolfSSL_use_AltPrivateKey_Id),
35191+
TEST_DECL(test_wolfSSL_use_AltPrivateKey_Label),
3516135192

3516235193
/*********************************
3516335194
* OpenSSL compatibility API tests

0 commit comments

Comments
 (0)