diff options
Diffstat (limited to 'src/session.c')
-rw-r--r-- | src/session.c | 101 |
1 files changed, 59 insertions, 42 deletions
diff --git a/src/session.c b/src/session.c index d7dac8a..ae20c0c 100644 --- a/src/session.c +++ b/src/session.c @@ -18,13 +18,16 @@ session_info(CK_SESSION_HANDLE session, CK_SLOT_ID slot, CK_FLAGS flags, CK_STAT /** C_GetSessionInfo */ - /** - Invalid session */ - rv = (p11t_module_funcs->C_GetSessionInfo)((CK_SESSION_HANDLE)-33, &info); - p11t_check_returns("C_GetSessionInfo: with invalid session", rv, CKR_SESSION_HANDLE_INVALID); + if(p11t_test_unexpected) + { + /** - Invalid session */ + rv = (p11t_module_funcs->C_GetSessionInfo)((CK_SESSION_HANDLE)-33, &info); + p11t_check_returns("C_GetSessionInfo: with invalid session", rv, CKR_SESSION_HANDLE_INVALID); - /** - NULL arguments */ - rv = (p11t_module_funcs->C_GetSessionInfo)(session, NULL); - p11t_check_returns("C_GetSessionInfo: with null", rv, CKR_ARGUMENTS_BAD); + /** - NULL arguments */ + rv = (p11t_module_funcs->C_GetSessionInfo)(session, NULL); + p11t_check_returns("C_GetSessionInfo: with null", rv, CKR_ARGUMENTS_BAD); + } /** - Valid call */ rv = (p11t_module_funcs->C_GetSessionInfo)(session, &info); @@ -54,21 +57,24 @@ session_main(CK_SLOT_ID slot) /** C_OpenSession */ - /** - Invalid slot */ - rv = (p11t_module_funcs->C_OpenSession)((CK_SLOT_ID)-5, CKF_SERIAL_SESSION, NULL, NULL, &session_ro); - p11t_check_returns("C_OpenSession: with invalid slot", rv, CKR_SLOT_ID_INVALID); + if(p11t_test_unexpected) + { + /** - Invalid slot */ + rv = (p11t_module_funcs->C_OpenSession)((CK_SLOT_ID)-5, CKF_SERIAL_SESSION, NULL, NULL, &session_ro); + p11t_check_returns("C_OpenSession: with invalid slot", rv, CKR_SLOT_ID_INVALID); - /** - Null arguments */ - rv = (p11t_module_funcs->C_OpenSession)(slot, CKF_SERIAL_SESSION, NULL, NULL, NULL); - p11t_check_returns("C_OpenSession: with invalid slot", rv, CKR_ARGUMENTS_BAD); + /** - Null arguments */ + rv = (p11t_module_funcs->C_OpenSession)(slot, CKF_SERIAL_SESSION, NULL, NULL, NULL); + p11t_check_returns("C_OpenSession: with invalid slot", rv, CKR_ARGUMENTS_BAD); - /** - No flags */ - rv = (p11t_module_funcs->C_OpenSession)(slot, 0, NULL, NULL, &session_ro); - p11t_check_returns("C_OpenSession: with 0 flags", rv, CKR_SESSION_PARALLEL_NOT_SUPPORTED); + /** - No flags */ + rv = (p11t_module_funcs->C_OpenSession)(slot, 0, NULL, NULL, &session_ro); + p11t_check_returns("C_OpenSession: with 0 flags", rv, CKR_SESSION_PARALLEL_NOT_SUPPORTED); - /** - Without serial flag */ - rv = (p11t_module_funcs->C_OpenSession)(slot, CKF_RW_SESSION, NULL, NULL, &session_ro); - p11t_check_returns("C_OpenSession: with RW flags", rv, CKR_SESSION_PARALLEL_NOT_SUPPORTED); + /** - Without serial flag */ + rv = (p11t_module_funcs->C_OpenSession)(slot, CKF_RW_SESSION, NULL, NULL, &session_ro); + p11t_check_returns("C_OpenSession: with RW flags", rv, CKR_SESSION_PARALLEL_NOT_SUPPORTED); + } /** - Valid flags */ rv = (p11t_module_funcs->C_OpenSession)(slot, CKF_SERIAL_SESSION, NULL, NULL, &session_ro); @@ -91,9 +97,12 @@ session_main(CK_SLOT_ID slot) /** C_CloseSession */ - /** - Invalid session */ - rv = (p11t_module_funcs->C_CloseSession)((CK_SESSION_HANDLE)-10); - p11t_check_returns("C_CloseSession: invalid handle", rv, CKR_SESSION_HANDLE_INVALID); + if(p11t_test_unexpected) + { + /** - Invalid session */ + rv = (p11t_module_funcs->C_CloseSession)((CK_SESSION_HANDLE)-10); + p11t_check_returns("C_CloseSession: invalid handle", rv, CKR_SESSION_HANDLE_INVALID); + } if(session_ro != CK_INVALID) { @@ -101,21 +110,23 @@ session_main(CK_SLOT_ID slot) rv = (p11t_module_funcs->C_CloseSession)(session_ro); p11t_check_returns("C_CloseSession: valid", rv, CKR_OK); - /** - Check open session was closed */ - rv = (p11t_module_funcs->C_GetSessionInfo)(session_ro, &info); - p11t_check_returns("C_GetSessionInfo: after close", rv, CKR_SESSION_HANDLE_INVALID); - + if(p11t_test_unexpected) + { + /** - Check open session was closed */ + rv = (p11t_module_funcs->C_GetSessionInfo)(session_ro, &info); + p11t_check_returns("C_GetSessionInfo: after close", rv, CKR_SESSION_HANDLE_INVALID); - /** - Close twice */ + /** - Close twice */ - /* - * Note that CKR_SESSION_CLOSED is a valid return in this case. - * That should only be returned in the rare case when a session - * was closed during the execution of a function. A corner case. - */ + /* + * Note that CKR_SESSION_CLOSED is a valid return in this case. + * That should only be returned in the rare case when a session + * was closed during the execution of a function. A corner case. + */ - rv = (p11t_module_funcs->C_CloseSession)(session_ro); - p11t_check_returns("C_CloseSession: valid", rv, CKR_SESSION_HANDLE_INVALID); + rv = (p11t_module_funcs->C_CloseSession)(session_ro); + p11t_check_returns("C_CloseSession: valid", rv, CKR_SESSION_HANDLE_INVALID); + } } if(session_rw != CK_INVALID) @@ -126,21 +137,27 @@ session_main(CK_SLOT_ID slot) /** C_CloseAllSessions */ - /** - Invalid slot id */ - rv = (p11t_module_funcs->C_CloseAllSessions)((CK_SLOT_ID)-34); - p11t_check_returns("C_CloseAllSessions: invalid slot", rv, CKR_SLOT_ID_INVALID); + if(p11t_test_unexpected) + { + /** - Invalid slot id */ + rv = (p11t_module_funcs->C_CloseAllSessions)((CK_SLOT_ID)-34); + p11t_check_returns("C_CloseAllSessions: invalid slot", rv, CKR_SLOT_ID_INVALID); + } /** - Normal call */ rv = (p11t_module_funcs->C_CloseAllSessions)(slot); p11t_check_returns("C_CloseAllSessions", rv, CKR_OK); - /** - Check open session was closed */ - rv = (p11t_module_funcs->C_GetSessionInfo)(session_ro2, &info); - p11t_check_returns("C_GetSessionInfo: after close all", rv, CKR_SESSION_HANDLE_INVALID); + if(p11t_test_unexpected) + { + /** - Check open session was closed */ + rv = (p11t_module_funcs->C_GetSessionInfo)(session_ro2, &info); + p11t_check_returns("C_GetSessionInfo: after close all", rv, CKR_SESSION_HANDLE_INVALID); - /** - Call when no sessions open */ - rv = (p11t_module_funcs->C_CloseAllSessions)(slot); - p11t_check_returns("C_CloseAllSessions", rv, CKR_OK); + /** - Call when no sessions open */ + rv = (p11t_module_funcs->C_CloseAllSessions)(slot); + p11t_check_returns("C_CloseAllSessions", rv, CKR_OK); + } } void |