FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* Decode ITU-T X.690 OID format to a string representation
 * return string length */
Decode ITU-T X.690 OID format to a string representation
return string length
Decode ITU - T X . 690 OID format to a string representation return string length
int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz)
{
    word32 val, inIdx = 0, outIdx = 0;
    int w = 0;
    if (out == NULL || in == NULL || outSz < 4 || inSz < 2)
        return BAD_FUNC_ARG;
    val = in[inIdx++];
    w = XSNPRINTF(out, outSz, "%u.%u", val / 40, val % 40);
    if (w < 0)
        goto exit;
    outIdx += w;
    val = 0;
    while (inIdx < inSz && outIdx < outSz) {
        if (in[inIdx] & 0x80) {
            val += in[inIdx] & 0x7F;
            val *= 128;
        }
        else {
            val += in[inIdx];
            w = XSNPRINTF(out + outIdx, outSz - outIdx, ".%u", val);
            if (w < 0)
                goto exit;
            outIdx += w;
            val = 0;
        }
        inIdx++;
    }
    if (outIdx == outSz)
        outIdx--;
    out[outIdx] = 0;
    w = (int)outIdx;
exit:
    return w;
}
int DecodePolicyOID ( char * out , word32 outSz , const byte * in , word32 inSz ) { word32 val , inIdx = 0 , outIdx = 0 ; int w = 0 ; if ( out == NULL || in == NULL || outSz < 4 || inSz < 2 ) return BAD_FUNC_ARG ; val = in [ inIdx ++ ] ; w = XSNPRINTF ( out , outSz , " " , val / 40 , val % 40 ) ; if ( w < 0 ) goto exit ; outIdx += w ; val = 0 ; while ( inIdx < inSz && outIdx < outSz ) { if ( in [ inIdx ] & 0x80 ) { val += in [ inIdx ] & 0x7F ; val *= 128 ; } else { val += in [ inIdx ] ; w = XSNPRINTF ( out + outIdx , outSz - outIdx , " " , val ) ; if ( w < 0 ) goto exit ; outIdx += w ; val = 0 ; } inIdx ++ ; } if ( outIdx == outSz ) outIdx -- ; out [ outIdx ] = 0 ; w = ( int ) outIdx ; exit : return w ; }
Decode ITU-T X.690 OID format to a string representation
 return string length
Decode ITU - T X . 690 OID format to a string representation return string length
/* The first byte expands into b/40 dot b%40. */ /* extract the next OID digit from in to val */ /* first bit is used to set if value is coded on 1 or multiple bytes */ /* write val as text into out */