FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Return bytes written to buff or < 0 for error */
Return bytes written to buff or < 0 for error
Return bytes written to buff or < 0 for error
int wc_CertPemToDer(const unsigned char* pem, int pemSz,
                        unsigned char* buff, int buffSz, int type)
{
    int            eccKey = 0;
    int            ret;
    DerBuffer*     der = NULL;
    WOLFSSL_ENTER("wc_CertPemToDer");
    if (pem == NULL || buff == NULL || buffSz <= 0) {
        WOLFSSL_MSG("Bad pem der args");
        return BAD_FUNC_ARG;
    }
    if (type != CERT_TYPE && type != CA_TYPE && type != CERTREQ_TYPE) {
        WOLFSSL_MSG("Bad cert type");
        return BAD_FUNC_ARG;
    }
    ret = PemToDer(pem, pemSz, type, &der, NULL, NULL, &eccKey);
    if (ret < 0 || der == NULL) {
        WOLFSSL_MSG("Bad Pem To Der");
    }
    else {
        if (der->length <= (word32)buffSz) {
            XMEMCPY(buff, der->buffer, der->length);
            ret = der->length;
        }
        else {
            WOLFSSL_MSG("Bad der length");
            ret = BAD_FUNC_ARG;
        }
    }
    FreeDer(&der);
    return ret;
}
int wc_CertPemToDer ( const unsigned char * pem , int pemSz , unsigned char * buff , int buffSz , int type ) { int eccKey = 0 ; int ret ; DerBuffer * der = NULL ; WOLFSSL_ENTER ( " " ) ; if ( pem == NULL || buff == NULL || buffSz <= 0 ) { WOLFSSL_MSG ( " " ) ; return BAD_FUNC_ARG ; } if ( type != CERT_TYPE && type != CA_TYPE && type != CERTREQ_TYPE ) { WOLFSSL_MSG ( " " ) ; return BAD_FUNC_ARG ; } ret = PemToDer ( pem , pemSz , type , & der , NULL , NULL , & eccKey ) ; if ( ret < 0 || der == NULL ) { WOLFSSL_MSG ( " " ) ; } else { if ( der -> length <= ( word32 ) buffSz ) { XMEMCPY ( buff , der -> buffer , der -> length ) ; ret = der -> length ; } else { WOLFSSL_MSG ( " " ) ; ret = BAD_FUNC_ARG ; } } FreeDer ( & der ) ; return ret ; }
Return bytes written to buff or < 0 for error
Return bytes written to buff or < 0 for error