Skip to content

Commit ec00f78

Browse files
Rename parameter in wolfSSL_EVP_CIPHER_type_string and add test
Co-Authored-By: lealem@wolfssl.com <lealem@wolfssl.com>
1 parent af1f654 commit ec00f78

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89710,6 +89710,7 @@ TEST_CASE testCases[] = {
8971089710
TEST_DECL(test_wolfSSL_EVP_EncodeInit),
8971189711
TEST_DECL(test_wolfSSL_EVP_EncodeUpdate),
8971289712
TEST_DECL(test_wolfSSL_EVP_CipherUpdate_Null),
89713+
TEST_DECL(test_wolfSSL_EVP_CIPHER_type_string),
8971389714
TEST_DECL(test_wolfSSL_EVP_EncodeFinal),
8971489715
TEST_DECL(test_wolfSSL_EVP_DecodeInit),
8971589716
TEST_DECL(test_wolfSSL_EVP_DecodeUpdate),

tests/api/test_evp.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,38 @@ int test_wolfSSL_EVP_CipherUpdate_Null(void)
6868
return EXPECT_RESULT();
6969
}
7070

71+
/* Test for wolfSSL_EVP_CIPHER_type_string() */
72+
int test_wolfSSL_EVP_CIPHER_type_string(void)
73+
{
74+
EXPECT_DECLS;
75+
#ifdef OPENSSL_EXTRA
76+
const char* cipherStr;
77+
78+
/* Test with valid cipher types */
79+
#ifndef NO_AES
80+
#ifdef WOLFSSL_AES_128
81+
cipherStr = wolfSSL_EVP_CIPHER_type_string(WC_AES_128_CBC_TYPE);
82+
ExpectNotNull(cipherStr);
83+
ExpectStrEQ(cipherStr, "AES-128-CBC");
84+
#endif
85+
#endif
86+
87+
#ifndef NO_DES3
88+
cipherStr = wolfSSL_EVP_CIPHER_type_string(WC_DES_CBC_TYPE);
89+
ExpectNotNull(cipherStr);
90+
ExpectStrEQ(cipherStr, "DES-CBC");
91+
#endif
92+
93+
/* Test with NULL cipher type */
94+
cipherStr = wolfSSL_EVP_CIPHER_type_string(WC_NULL_CIPHER_TYPE);
95+
ExpectNotNull(cipherStr);
96+
ExpectStrEQ(cipherStr, "NULL");
97+
98+
/* Test with invalid cipher type */
99+
cipherStr = wolfSSL_EVP_CIPHER_type_string(0xFFFF);
100+
ExpectNull(cipherStr);
101+
#endif /* OPENSSL_EXTRA */
102+
103+
return EXPECT_RESULT();
104+
}
105+

tests/api/test_evp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
#define WOLFSSL_TEST_EVP_H
2424

2525
int test_wolfSSL_EVP_CipherUpdate_Null(void);
26+
int test_wolfSSL_EVP_CIPHER_type_string(void);
2627

2728
#endif /* WOLFSSL_TEST_EVP_H */

wolfcrypt/src/evp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,15 +2056,15 @@ static unsigned int cipherType(const WOLFSSL_EVP_CIPHER *cipher)
20562056

20572057
/* Getter function for cipher type string
20582058
*
2059-
* type cipherType enum value to get string for
2059+
* cipherType cipherType enum value to get string for
20602060
*
20612061
* Returns string representation of the cipher type or NULL if not found
20622062
*/
2063-
const char* wolfSSL_EVP_CIPHER_type_string(unsigned int type)
2063+
const char* wolfSSL_EVP_CIPHER_type_string(unsigned int cipherType)
20642064
{
20652065
WOLFSSL_ENTER("wolfSSL_EVP_CIPHER_type_string");
20662066

2067-
switch (type) {
2067+
switch (cipherType) {
20682068
#ifndef NO_DES3
20692069
case WC_DES_CBC_TYPE: return EVP_DES_CBC;
20702070
case WC_DES_EDE3_CBC_TYPE: return EVP_DES_EDE3_CBC;

0 commit comments

Comments
 (0)