FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* encode Extended Key Usage (RFC 5280 4.2.1.12), return total bytes written */
encode Extended Key Usage (RFC 5280 4.2.1.12), return total bytes written
encode Extended Key Usage ( RFC 5280 4 . 2 . 1 . 12 ) return total bytes written
static int SetExtKeyUsage(Cert* cert, byte* output, word32 outSz, byte input)
{
    int idx = 0, oidListSz = 0, totalSz, ret = 0;
    const byte extkeyusage_oid[] = { 0x06, 0x03, 0x55, 0x1d, 0x25 };
    if (output == NULL)
        return BAD_FUNC_ARG;
    totalSz = 2 + sizeof(extkeyusage_oid) + 4;
    idx = totalSz;
    if (input & EXTKEYUSE_ANY) {
        ret |= SetOjectIdValue(output, outSz, &idx,
            extExtKeyUsageAnyOid, sizeof(extExtKeyUsageAnyOid));
    }
    else {
        if (input & EXTKEYUSE_SERVER_AUTH)
            ret |= SetOjectIdValue(output, outSz, &idx,
                extExtKeyUsageServerAuthOid, sizeof(extExtKeyUsageServerAuthOid));
        if (input & EXTKEYUSE_CLIENT_AUTH)
            ret |= SetOjectIdValue(output, outSz, &idx,
                extExtKeyUsageClientAuthOid, sizeof(extExtKeyUsageClientAuthOid));
        if (input & EXTKEYUSE_CODESIGN)
            ret |= SetOjectIdValue(output, outSz, &idx,
                extExtKeyUsageCodeSigningOid, sizeof(extExtKeyUsageCodeSigningOid));
        if (input & EXTKEYUSE_EMAILPROT)
            ret |= SetOjectIdValue(output, outSz, &idx,
                extExtKeyUsageEmailProtectOid, sizeof(extExtKeyUsageEmailProtectOid));
        if (input & EXTKEYUSE_TIMESTAMP)
            ret |= SetOjectIdValue(output, outSz, &idx,
                extExtKeyUsageTimestampOid, sizeof(extExtKeyUsageTimestampOid));
        if (input & EXTKEYUSE_OCSP_SIGN)
            ret |= SetOjectIdValue(output, outSz, &idx,
                extExtKeyUsageOcspSignOid, sizeof(extExtKeyUsageOcspSignOid));
    #ifdef WOLFSSL_EKU_OID
        if (input & EXTKEYUSE_USER) {
            int i, sz;
            for (i = 0; i < CTC_MAX_EKU_NB; i++) {
                sz = cert->extKeyUsageOIDSz[i];
                if (sz > 0) {
                    ret |= SetOjectIdValue(output, outSz, &idx,
                        cert->extKeyUsageOID[i], sz);
                }
            }
        }
    #endif 
    }
    if (ret != 0)
        return ASN_PARSE_E;
    oidListSz = idx - totalSz;
    totalSz = idx - 2; 
    idx = SetSequence(totalSz, output);
    XMEMCPY(&output[idx], extkeyusage_oid, sizeof(extkeyusage_oid));
    idx += sizeof(extkeyusage_oid);
    idx += SetOctetString(totalSz - idx, &output[idx]);
    idx += SetSequence(oidListSz, &output[idx]);
    idx += oidListSz;
    (void)cert;
    return idx;
}
static int SetExtKeyUsage ( Cert * cert , byte * output , word32 outSz , byte input ) { int idx = 0 , oidListSz = 0 , totalSz , ret = 0 ; const byte extkeyusage_oid [ ] = { 0x06 , 0x03 , 0x55 , 0x1d , 0x25 } ; if ( output == NULL ) return BAD_FUNC_ARG ; totalSz = 2 + sizeof ( extkeyusage_oid ) + 4 ; idx = totalSz ; if ( input & EXTKEYUSE_ANY ) { ret |= SetOjectIdValue ( output , outSz , & idx , extExtKeyUsageAnyOid , sizeof ( extExtKeyUsageAnyOid ) ) ; } else { if ( input & EXTKEYUSE_SERVER_AUTH ) ret |= SetOjectIdValue ( output , outSz , & idx , extExtKeyUsageServerAuthOid , sizeof ( extExtKeyUsageServerAuthOid ) ) ; if ( input & EXTKEYUSE_CLIENT_AUTH ) ret |= SetOjectIdValue ( output , outSz , & idx , extExtKeyUsageClientAuthOid , sizeof ( extExtKeyUsageClientAuthOid ) ) ; if ( input & EXTKEYUSE_CODESIGN ) ret |= SetOjectIdValue ( output , outSz , & idx , extExtKeyUsageCodeSigningOid , sizeof ( extExtKeyUsageCodeSigningOid ) ) ; if ( input & EXTKEYUSE_EMAILPROT ) ret |= SetOjectIdValue ( output , outSz , & idx , extExtKeyUsageEmailProtectOid , sizeof ( extExtKeyUsageEmailProtectOid ) ) ; if ( input & EXTKEYUSE_TIMESTAMP ) ret |= SetOjectIdValue ( output , outSz , & idx , extExtKeyUsageTimestampOid , sizeof ( extExtKeyUsageTimestampOid ) ) ; if ( input & EXTKEYUSE_OCSP_SIGN ) ret |= SetOjectIdValue ( output , outSz , & idx , extExtKeyUsageOcspSignOid , sizeof ( extExtKeyUsageOcspSignOid ) ) ; #ifdef WOLFSSL_EKU_OID if ( input & EXTKEYUSE_USER ) { int i , sz ; for ( i = 0 ; i < CTC_MAX_EKU_NB ; i ++ ) { sz = cert -> extKeyUsageOIDSz [ i ] ; if ( sz > 0 ) { ret |= SetOjectIdValue ( output , outSz , & idx , cert -> extKeyUsageOID [ i ] , sz ) ; } } } #endif } if ( ret != 0 ) return ASN_PARSE_E ; oidListSz = idx - totalSz ; totalSz = idx - 2 ; idx = SetSequence ( totalSz , output ) ; XMEMCPY ( & output [ idx ] , extkeyusage_oid , sizeof ( extkeyusage_oid ) ) ; idx += sizeof ( extkeyusage_oid ) ; idx += SetOctetString ( totalSz - idx , & output [ idx ] ) ; idx += SetSequence ( oidListSz , & output [ idx ] ) ; idx += oidListSz ; ( void ) cert ; return idx ; }
encode Extended Key Usage (RFC 5280 4.2.1.12), return total bytes written
encode Extended Key Usage ( RFC 5280 4 . 2 . 1 . 12 ) return total bytes written
/* Skip to OID List */ /* Build OID List */ /* If any set, then just use it */ /* iterate through OID values */ /* WOLFSSL_EKU_OID */ /* Calculate Sizes */ /* exclude first seq/len (2) */ /* 1. Seq + Total Len (2) */ /* 2. Object ID (2) */ /* 3. Octet String (2) */ /* 4. Seq + OidListLen (2) */ /* 5. Oid List (already set in-place above) */