static CK_RV prvGetCertificateHandle()

in components/ota_pal/source/ota_pal.c [338:372]


static CK_RV prvGetCertificateHandle(CK_FUNCTION_LIST_PTR pxFunctionList,
                                     CK_SESSION_HANDLE xSession,
                                     const char *pcLabelName,
                                     CK_OBJECT_HANDLE_PTR pxCertHandle)
{
    CK_ATTRIBUTE xTemplate;
    CK_RV xResult = CKR_OK;
    CK_ULONG ulCount = 0;
    CK_BBOOL xFindInit = CK_FALSE;

    /* Get the certificate handle. */
    if (0 == xResult)
    {
        xTemplate.type = CKA_LABEL;
        xTemplate.ulValueLen = strlen(pcLabelName) + 1;
        xTemplate.pValue = (char *)pcLabelName;
        xResult = pxFunctionList->C_FindObjectsInit(xSession, &xTemplate, 1);
    }

    if (0 == xResult)
    {
        xFindInit = CK_TRUE;
        xResult = pxFunctionList->C_FindObjects(xSession,
                                                (CK_OBJECT_HANDLE_PTR)pxCertHandle,
                                                1,
                                                &ulCount);
    }

    if (CK_TRUE == xFindInit)
    {
        xResult = pxFunctionList->C_FindObjectsFinal(xSession);
    }

    return xResult;
}