FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Set KeyUsage from human readable string */
Set KeyUsage from human readable string
Set KeyUsage from human readable string
int wc_SetKeyUsage(Cert *cert, const char *value)
{
    int ret = 0;
    char *token, *str, *ptr;
    word32 len;
    if (cert == NULL || value == NULL)
        return BAD_FUNC_ARG;
    cert->keyUsage = 0;
    len = (word32)XSTRLEN(value);
    str = (char*)XMALLOC(len+1, cert->heap, DYNAMIC_TYPE_TMP_BUFFER);
    if (str == NULL)
        return MEMORY_E;
    XMEMCPY(str, value, len+1);
    if ((token = XSTRTOK(str, ",", &ptr)) == NULL) {
        XFREE(str, cert->heap, DYNAMIC_TYPE_TMP_BUFFER);
        return KEYUSAGE_E;
    }
    while (token != NULL)
    {
        len = (word32)XSTRLEN(token);
        if (!XSTRNCASECMP(token, "digitalSignature", len))
            cert->keyUsage |= KEYUSE_DIGITAL_SIG;
        else if (!XSTRNCASECMP(token, "nonRepudiation", len) ||
                 !XSTRNCASECMP(token, "contentCommitment", len))
            cert->keyUsage |= KEYUSE_CONTENT_COMMIT;
        else if (!XSTRNCASECMP(token, "keyEncipherment", len))
            cert->keyUsage |= KEYUSE_KEY_ENCIPHER;
        else if (!XSTRNCASECMP(token, "dataEncipherment", len))
            cert->keyUsage |= KEYUSE_DATA_ENCIPHER;
        else if (!XSTRNCASECMP(token, "keyAgreement", len))
            cert->keyUsage |= KEYUSE_KEY_AGREE;
        else if (!XSTRNCASECMP(token, "keyCertSign", len))
            cert->keyUsage |= KEYUSE_KEY_CERT_SIGN;
        else if (!XSTRNCASECMP(token, "cRLSign", len))
            cert->keyUsage |= KEYUSE_CRL_SIGN;
        else if (!XSTRNCASECMP(token, "encipherOnly", len))
            cert->keyUsage |= KEYUSE_ENCIPHER_ONLY;
        else if (!XSTRNCASECMP(token, "decipherOnly", len))
            cert->keyUsage |= KEYUSE_DECIPHER_ONLY;
        else {
            ret = KEYUSAGE_E;
            break;
        }
        token = XSTRTOK(NULL, ",", &ptr);
    }
    XFREE(str, cert->heap, DYNAMIC_TYPE_TMP_BUFFER);
    return ret;
}
int wc_SetKeyUsage ( Cert * cert , const char * value ) { int ret = 0 ; char * token , * str , * ptr ; word32 len ; if ( cert == NULL || value == NULL ) return BAD_FUNC_ARG ; cert -> keyUsage = 0 ; len = ( word32 ) XSTRLEN ( value ) ; str = ( char * ) XMALLOC ( len + 1 , cert -> heap , DYNAMIC_TYPE_TMP_BUFFER ) ; if ( str == NULL ) return MEMORY_E ; XMEMCPY ( str , value , len + 1 ) ; if ( ( token = XSTRTOK ( str , " " , & ptr ) ) == NULL ) { XFREE ( str , cert -> heap , DYNAMIC_TYPE_TMP_BUFFER ) ; return KEYUSAGE_E ; } while ( token != NULL ) { len = ( word32 ) XSTRLEN ( token ) ; if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_DIGITAL_SIG ; else if ( ! XSTRNCASECMP ( token , " " , len ) || ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_CONTENT_COMMIT ; else if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_KEY_ENCIPHER ; else if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_DATA_ENCIPHER ; else if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_KEY_AGREE ; else if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_KEY_CERT_SIGN ; else if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_CRL_SIGN ; else if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_ENCIPHER_ONLY ; else if ( ! XSTRNCASECMP ( token , " " , len ) ) cert -> keyUsage |= KEYUSE_DECIPHER_ONLY ; else { ret = KEYUSAGE_E ; break ; } token = XSTRTOK ( NULL , " " , & ptr ) ; } XFREE ( str , cert -> heap , DYNAMIC_TYPE_TMP_BUFFER ) ; return ret ; }
Set KeyUsage from human readable string
Set KeyUsage from human readable string
/* duplicate string (including terminator) */ /* parse value, and set corresponding Key Usage value */