HTTP_CLIENT_RESULT uhttp_client_set_X509_cert()

in src/uhttp.c [1497:1532]


HTTP_CLIENT_RESULT uhttp_client_set_X509_cert(HTTP_CLIENT_HANDLE handle, bool ecc_type, const char* certificate, const char* private_key)
{
    HTTP_CLIENT_RESULT result;
    if (handle == NULL || certificate == NULL || private_key == NULL)
    {
        /* Codes_SRS_UHTTP_07_038: [If handle is NULL then http_client_set_trace shall return HTTP_CLIENT_INVALID_ARG] */
        result = HTTP_CLIENT_INVALID_ARG;
        LogError("invalid parameter handle: %p certificate: %p private_key: %p", handle, certificate, private_key);
    }
    else if (handle->recv_msg.recv_state != state_initial)
    {
        result = HTTP_CLIENT_INVALID_STATE;
        LogError("You must set the X509 certificates before opening the connection");
    }
    else
    {
        handle->cert_type_ecc = ecc_type;
        if (mallocAndStrcpy_s(&handle->x509_cert, certificate) != 0)
        {
            result = HTTP_CLIENT_ERROR;
            LogError("failure allocating certificate");
        }
        else if (mallocAndStrcpy_s(&handle->x509_pk, private_key) != 0)
        {
            free(handle->x509_cert);
            handle->x509_cert = NULL;
            result = HTTP_CLIENT_ERROR;
            LogError("failure allocating private key");
        }
        else
        {
            result = HTTP_CLIENT_OK;
        }
    }
    return result;
}