Skip to content

Commit bf94f31

Browse files
committed
tests: Verify the C_GetMechanismInfo does fails for not allowed mechanisms
1 parent f5124cc commit bf94f31

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lib/test/InfoTests.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void InfoTests::testGetMechanismListConfig()
329329
CK_RV rv;
330330
CK_ULONG ulMechCount = 0;
331331
CK_MECHANISM_TYPE_PTR pMechanismList;
332+
CK_MECHANISM_INFO info;
332333

333334
#ifndef _WIN32
334335
setenv("SOFTHSM2_CONF", "./softhsm2-mech.conf", 1);
@@ -358,6 +359,20 @@ void InfoTests::testGetMechanismListConfig()
358359
CPPUNIT_ASSERT(pMechanismList[1] == CKM_RSA_PKCS);
359360
free(pMechanismList);
360361

362+
/* Get good mechanism info */
363+
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_RSA_X_509, &info) );
364+
CPPUNIT_ASSERT(rv == CKR_OK);
365+
CPPUNIT_ASSERT(info.flags & CKF_SIGN);
366+
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_RSA_PKCS, &info) );
367+
CPPUNIT_ASSERT(rv == CKR_OK);
368+
CPPUNIT_ASSERT(info.flags & CKF_SIGN);
369+
370+
/* Get bad mechanism info */
371+
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_ECDSA, &info) );
372+
CPPUNIT_ASSERT(rv == CKR_MECHANISM_INVALID);
373+
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_DSA, &info) );
374+
CPPUNIT_ASSERT(rv == CKR_MECHANISM_INVALID);
375+
361376
CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) );
362377
#ifndef _WIN32
363378
setenv("SOFTHSM2_CONF", "./softhsm2.conf", 1);

0 commit comments

Comments
 (0)