FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* encode Certificate Policies, return total bytes written
 * each input value must be ITU-T X.690 formatted : a.b.c...
 * input must be an array of values with a NULL terminated for the latest
 * RFC5280 : non-critical */
encode Certificate Policies, return total bytes written
each input value must be ITU-T X.690 formatted : a.b.c
input must be an array of values with a NULL terminated for the latest
RFC5280 : non-critical
encode Certificate Policies return total bytes written each input value must be ITU - T X . 690 formatted : a . b . c input must be an array of values with a NULL terminated for the latest RFC5280 : non - critical
static int SetCertificatePolicies(byte *output,
                                  word32 outputSz,
                                  char input[MAX_CERTPOL_NB][MAX_CERTPOL_SZ],
                                  word16 nb_certpol,
                                  void* heap)
{
    byte    oid[MAX_OID_SZ],
            der_oid[MAX_CERTPOL_NB][MAX_OID_SZ],
            out[MAX_CERTPOL_SZ];
    word32  oidSz;
    word32  outSz, i = 0, der_oidSz[MAX_CERTPOL_NB];
    int     ret;
    const byte certpol_oid[] = { 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04 };
    const byte oid_oid[] = { 0x06 };
    if (output == NULL || input == NULL || nb_certpol > MAX_CERTPOL_NB)
        return BAD_FUNC_ARG;
    for (i = 0; i < nb_certpol; i++) {
        oidSz = sizeof(oid);
        XMEMSET(oid, 0, oidSz);
        ret = EncodePolicyOID(oid, &oidSz, input[i], heap);
        if (ret != 0)
            return ret;
        ret = SetOidValue(der_oid[i], MAX_OID_SZ, oid_oid,
                          sizeof(oid_oid), oid, oidSz);
        if (ret <= 0)
            return ret;
        else
            der_oidSz[i] = (word32)ret;
    }
    for (i = 0, outSz = 2; i < nb_certpol; i++) {
        XMEMCPY(out+outSz, der_oid[i], der_oidSz[i]);
        outSz += der_oidSz[i];
    }
    ret = SetSequence(outSz-2, out);
    if (ret <= 0)
        return ret;
    return SetOidValue(output, outputSz, certpol_oid, sizeof(certpol_oid),
                      out, outSz);
}
static int SetCertificatePolicies ( byte * output , word32 outputSz , char input [ MAX_CERTPOL_NB ] [ MAX_CERTPOL_SZ ] , word16 nb_certpol , void * heap ) { byte oid [ MAX_OID_SZ ] , der_oid [ MAX_CERTPOL_NB ] [ MAX_OID_SZ ] , out [ MAX_CERTPOL_SZ ] ; word32 oidSz ; word32 outSz , i = 0 , der_oidSz [ MAX_CERTPOL_NB ] ; int ret ; const byte certpol_oid [ ] = { 0x06 , 0x03 , 0x55 , 0x1d , 0x20 , 0x04 } ; const byte oid_oid [ ] = { 0x06 } ; if ( output == NULL || input == NULL || nb_certpol > MAX_CERTPOL_NB ) return BAD_FUNC_ARG ; for ( i = 0 ; i < nb_certpol ; i ++ ) { oidSz = sizeof ( oid ) ; XMEMSET ( oid , 0 , oidSz ) ; ret = EncodePolicyOID ( oid , & oidSz , input [ i ] , heap ) ; if ( ret != 0 ) return ret ; ret = SetOidValue ( der_oid [ i ] , MAX_OID_SZ , oid_oid , sizeof ( oid_oid ) , oid , oidSz ) ; if ( ret <= 0 ) return ret ; else der_oidSz [ i ] = ( word32 ) ret ; } for ( i = 0 , outSz = 2 ; i < nb_certpol ; i ++ ) { XMEMCPY ( out + outSz , der_oid [ i ] , der_oidSz [ i ] ) ; outSz += der_oidSz [ i ] ; } ret = SetSequence ( outSz - 2 , out ) ; if ( ret <= 0 ) return ret ; return SetOidValue ( output , outputSz , certpol_oid , sizeof ( certpol_oid ) , out , outSz ) ; }
encode Certificate Policies, return total bytes written
 each input value must be ITU-T X.690 formatted : a.b.c...
 input must be an array of values with a NULL terminated for the latest
 RFC5280 : non-critical
encode Certificate Policies return total bytes written each input value must be ITU - T X . 690 formatted : a . b . c ... input must be an array of values with a NULL terminated for the latest RFC5280 : non - critical
/* compute sequence value for the oid */ /* concatenate oid, keep two byte for sequence/size of the created value */ /* add sequence */ /* add Policy OID to compute final value */