VirtualBox

Changeset 16762 in vbox


Ignore:
Timestamp:
Feb 14, 2009 8:21:28 AM (16 years ago)
Author:
vboxsync
Message:

RTBase64Decode testcase and bugfixes.

Location:
trunk/src/VBox/Runtime
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/base64.cpp

    r16760 r16762  
    245245     * Process input in groups of 4 input / 3 output chars.
    246246     */
    247     uint8_t    *pbData    = (uint8_t *)pbData;
    248247    uint8_t     u8Trio[3];
     248    uint8_t    *pbData    = (uint8_t *)pvData;
     249    uint8_t     u8        = BASE64_INVALID;
    249250    unsigned    c6Bits    = 0;
    250     uint8_t     u8        = BASE64_INVALID;
    251251    unsigned    ch;
    252252    AssertCompile(sizeof(char) == sizeof(uint8_t));
    253253
     254const char *pszCurStart;
    254255    for (;;)
    255256    {
     257pszCurStart = pszString;
    256258        /* The first 6-bit group. */
    257         while ((u8 = g_au8CharToVal[ch = *pszString]) != BASE64_SPACE)
     259        while ((u8 = g_au8CharToVal[ch = *pszString]) == BASE64_SPACE)
    258260            pszString++;
    259261        if (u8 >= 64)
     
    262264            break;
    263265        }
    264         u8Trio[0] = u8;
     266        u8Trio[0] = u8 << 2;
     267        pszString++;
    265268
    266269        /* The second 6-bit group. */
    267         while ((u8 = g_au8CharToVal[ch = *pszString]) != BASE64_SPACE)
     270        while ((u8 = g_au8CharToVal[ch = *pszString]) == BASE64_SPACE)
    268271            pszString++;
    269272        if (u8 >= 64)
     
    272275            break;
    273276        }
    274         u8Trio[0] |= (u8 & 0x3) << 6;
    275         u8Trio[1] = u8 >> 2;
     277        u8Trio[0] |= u8 >> 4;
     278        u8Trio[1]  = u8 << 4;
     279        pszString++;
    276280
    277281        /* The third 6-bit group. */
    278         while ((u8 = g_au8CharToVal[ch = *pszString]) != BASE64_SPACE)
     282        while ((u8 = g_au8CharToVal[ch = *pszString]) == BASE64_SPACE)
    279283            pszString++;
    280284        if (u8 >= 64)
     
    283287            break;
    284288        }
    285         u8Trio[1] |= (u8 & 0xf) << 4;
    286         u8Trio[2] = u8 >> 4;
     289        u8Trio[1] |= u8 >> 2;
     290        u8Trio[2]  = u8 << 6;
     291        pszString++;
    287292
    288293        /* The fourth 6-bit group. */
    289         while ((u8 = g_au8CharToVal[ch = *pszString]) != BASE64_SPACE)
     294        while ((u8 = g_au8CharToVal[ch = *pszString]) == BASE64_SPACE)
    290295            pszString++;
    291296        if (u8 >= 64)
     
    294299            break;
    295300        }
    296         u8Trio[2] |= u8 << 2;
     301        u8Trio[2] |= u8;
     302        pszString++;
    297303
    298304        /* flush the trio */
     
    342348     * Check padding vs. pending sextets, if anything left to do finish it off.
    343349     */
    344     if (    c6Bits + cbPad != 4
    345         &&  c6Bits + cbPad != 0)
    346         return VERR_INVALID_BASE64_ENCODING;
    347     if (c6Bits)
    348     {
     350    if (c6Bits || cbPad)
     351    {
     352        if (c6Bits + cbPad != 4)
     353            return VERR_INVALID_BASE64_ENCODING;
     354
    349355        switch (c6Bits)
    350356        {
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r15821 r16762  
    5050PROGRAMS += \
    5151        tstAvl \
     52        tstBase64 \
    5253        tstBitOperations \
    5354        tstCidr \
     
    128129tstAvl_SOURCES = tstAvl.cpp
    129130
     131tstBase64_TEMPLATE = VBOXR3TSTEXE
     132tstBase64_SOURCES = tstBase64.cpp
     133
    130134tstBitOperations_TEMPLATE = VBOXR3TSTEXE
    131135tstBitOperations_SOURCES = tstBitOperations.cpp
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette