{
P11Session_t * pxSession = prvSessionPointerFromHandle( hSession );
CK_RV xResult = CKR_OK;
if( xP11Context.xIsInitialized == ( CK_BBOOL ) CK_FALSE )
{
xResult = CKR_CRYPTOKI_NOT_INITIALIZED;
LogError( ( "Could not close a session. PKCS #11 must be initialized "
"before any operations." ) );
}
else if( pxSession == NULL )
{
xResult = CKR_SESSION_HANDLE_INVALID;
LogError( ( "Could not close a session. The PKCS #11 session handle "
"was invalid." ) );
}
else if( pxSession->xOpened == ( CK_BBOOL ) CK_TRUE )
{
mbedtls_pk_free( &pxSession->xSignKey );
pxSession->xSignKeyHandle = CK_INVALID_HANDLE;
mbedtls_mutex_free( &pxSession->xSignMutex );
mbedtls_pk_free( &pxSession->xVerifyKey );
pxSession->xVerifyKeyHandle = CK_INVALID_HANDLE;
mbedtls_mutex_free( &pxSession->xVerifyMutex );
mbedtls_sha256_free( &pxSession->xSHA256Context );
( void ) memset( pxSession, 0, sizeof( P11Session_t ) );
LogInfo( ( "Successfully closed PKCS #11 session." ) );
}
else
{
}
return xResult;
}