static Base64Status_t preprocessBase64Index()

in source/ota_base64.c [192:250]


static Base64Status_t preprocessBase64Index( uint8_t base64Index,
                                             int64_t * pNumPadding,
                                             int64_t * pNumWhitespace )
{
    Base64Status_t returnVal = Base64Success;
    int64_t numPadding;
    int64_t numWhitespace;

    assert( pNumPadding != NULL );
    assert( pNumWhitespace != NULL );

    numPadding = *pNumPadding;
    numWhitespace = *pNumWhitespace;

    /* Validate that the Base64 index is valid and in an appropriate place. */
    if( base64Index == NON_BASE64_INDEX )
    {
        returnVal = Base64InvalidSymbol;
    }
    else if( base64Index == PADDING_SYMBOL )
    {
        if( numWhitespace != 0 )
        {
            returnVal = Base64InvalidSymbolOrdering;
        }
        else if( ++numPadding > MAX_EXPECTED_NUM_PADDING )
        {
            returnVal = Base64InvalidPaddingSymbol;
        }
        else
        {
            /* No action required. */
        }
    }
    else if( base64Index == WHITESPACE )
    {
        ++numWhitespace;
    }
    else if( base64Index == NEWLINE )
    {
        /* No action required. */
    }

    /* In this case, the input is valid because the value of its index is inclusively between 0
     * and 63. Check that there was not a whitespace or padding symbol before this valid index. */
    else
    {
        assert( base64Index <= BASE64_INDEX_VALUE_UPPER_BOUND );

        if( ( numWhitespace != 0 ) || ( numPadding != 0 ) )
        {
            returnVal = Base64InvalidSymbolOrdering;
        }
    }

    *pNumWhitespace = numWhitespace;
    *pNumPadding = numPadding;
    return returnVal;
}