Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
base64t.c File Reference
#include "plbase64.h"
#include "plstr.h"
#include "nspr.h"
#include <stdio.h>

Go to the source code of this file.

Functions

PRBool test_001 (void)
PRBool test_002 (void)
PRBool test_003 (void)
PRBool test_004 (void)
PRBool test_005 (void)
PRBool test_006 (void)
PRBool test_007 (void)
PRBool test_008 (void)
PRBool test_009 (void)
PRBool test_010 (void)
PRBool test_011 (void)
PRBool test_012 (void)
PRBool test_013 (void)
PRBool test_014 (void)
PRBool test_015 (void)
PRBool test_016 (void)
PRBool test_017 (void)
PRBool test_018 (void)
PRBool test_019 (void)
PRBool test_020 (void)
PRBool test_021 (void)
PRBool test_022 (void)
PRBool test_023 (void)
PRBool test_024 (void)
PRBool test_025 (void)
PRBool test_026 (void)
PRBool test_027 (void)
PRBool test_028 (void)
int main (int argc, char *argv[])

Variables

static unsigned char * base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
struct {
const char * plaintext
const char * cyphertext
array []

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 2998 of file base64t.c.

{
    printf("Testing the Portable Library base64 functions:\n");
    printf("(warning: the \"triple characters\" tests are slow)\n");

    if( 1
        && test_001()
        && test_002()
        && test_003()
        && test_004()
        && test_005()
        && test_006()
        && test_007()
        && test_008()
        && test_009()
        && test_010()
        && test_011()
        && test_012()
        && test_013()
        && test_014()
        && test_015()
        && test_016()
        && test_017()
        && test_018()
        && test_019()
        && test_020()
        && test_021()
        && test_022()
        && test_023()
        && test_024()
        && test_025()
        && test_026()
        && test_027()
        && test_028()
      )
    {
        printf("Suite passed.\n");
        return 0;
    }
    else
    {
        printf("Suite failed.\n");
        return 1;
    }

    /*NOTREACHED*/
}

Here is the call graph for this function:

Definition at line 47 of file base64t.c.

{
    PRUint32 a, b;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 001 (PL_Base64Encode, single characters)                         ..."); fflush(stdout);

    plain[1] = plain[2] = plain[3] = (unsigned char)0;
    cypher[2] = cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];

        for( b = 0; b < 4; b++ )
        {
            plain[0] = (unsigned char)(a * 4 + b);
            cypher[1] = base[(b * 16)];

            rv = PL_Base64Encode((char *)plain, 1, result);
            if( rv != result )
            {
                printf("FAIL\n\t(%d, %d): return value\n", a, b);
                return PR_FALSE;
            }

            if( 0 != PL_strncmp((char *)cypher, result, 4) )
            {
                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%.4s.\"\n",
                       a, b, cypher, result);
                return PR_FALSE;
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 91 of file base64t.c.

{
    PRUint32 a, b, c, d;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 002 (PL_Base64Encode, double characters)                         ..."); fflush(stdout);

    plain[2] = plain[3] = (unsigned char)0;
    cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    cypher[2] = base[d*4];

                    rv = PL_Base64Encode((char *)plain, 2, result);
                    if( rv != result )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): return value\n", a, b, c, d);
                        return PR_FALSE;
                    }

                    if( 0 != PL_strncmp((char *)cypher, result, 4) )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%.4s.\"\n",
                               a, b, c, d, cypher, result);
                        return PR_FALSE;
                    }
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file base64t.c.

{
    PRUint32 a, b, c, d, e, f;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 003 (PL_Base64Encode, triple characters)                         ..."); fflush(stdout);

    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    for( e = 0; e < 4; e++ )
                    {
                        cypher[2] = base[d*4 + e];
                        for( f = 0; f < 64; f++ )
                        {
                            plain[2] = e * 64 + f;
                            cypher[3] = base[f];

                            rv = PL_Base64Encode((char *)plain, 3, result);
                            if( rv != result )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): return value\n", a, b, c, d, e, f);
                                return PR_FALSE;
                            }

                            if( 0 != PL_strncmp((char *)cypher, result, 4) )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.4s.\"\n",
                                       a, b, c, d, e, f, cypher, result);
                                return PR_FALSE;
                            }
                        }
                    }
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1822 of file base64t.c.

{
    int i;
    char result[ 4096 ];

    printf("Test 004 (PL_Base64Encode, random strings)                            ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 plen = PL_strlen(array[i].plaintext);
        PRUint32 clen = ((plen + 2)/3)*4;

        char *rv = PL_Base64Encode(array[i].plaintext, plen, result);

        if( rv != result )
        {
            printf("FAIL\n\t(%d): return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strncmp(result, array[i].cyphertext, clen) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
                   i, array[i].plaintext, array[i].cyphertext, clen, result);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1855 of file base64t.c.

{
    PRUint32 a, b;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 005 (PL_Base64Encode, single characters, malloc)                 ..."); fflush(stdout);

    plain[1] = plain[2] = plain[3] = (unsigned char)0;
    cypher[2] = cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];

        for( b = 0; b < 4; b++ )
        {
            plain[0] = (unsigned char)(a * 4 + b);
            cypher[1] = base[(b * 16)];

            rv = PL_Base64Encode((char *)plain, 1, (char *)0);
            if( (char *)0 == rv )
            {
                printf("FAIL\n\t(%d, %d): no return value\n", a, b);
                return PR_FALSE;
            }

            if( 0 != PL_strcmp((char *)cypher, rv) )
            {
                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%s.\"\n",
                       a, b, cypher, rv);
                PR_DELETE(rv);
                return PR_FALSE;
            }

            PR_DELETE(rv);
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1901 of file base64t.c.

{
    PRUint32 a, b, c, d;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 006 (PL_Base64Encode, double characters, malloc)                 ..."); fflush(stdout);

    plain[2] = plain[3] = (unsigned char)0;
    cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    cypher[2] = base[d*4];

                    rv = PL_Base64Encode((char *)plain, 2, (char *)0);
                    if( (char *)0 == rv )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): no return value\n", a, b, c, d);
                        return PR_FALSE;
                    }

                    if( 0 != PL_strcmp((char *)cypher, rv) )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%s.\"\n",
                               a, b, c, d, cypher, rv);
                        PR_DELETE(rv);
                        return PR_FALSE;
                    }

                    PR_DELETE(rv);
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1954 of file base64t.c.

{
    PRUint32 a, b, c, d, e, f;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 007 (PL_Base64Encode, triple characters, malloc)                 ..."); fflush(stdout);

    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    for( e = 0; e < 4; e++ )
                    {
                        cypher[2] = base[d*4 + e];
                        for( f = 0; f < 64; f++ )
                        {
                            plain[2] = e * 64 + f;
                            cypher[3] = base[f];

                            rv = PL_Base64Encode((char *)plain, 3, (char *)0);
                            if( (char *)0 == rv )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): no return value\n", a, b, c, d, e, f);
                                return PR_FALSE;
                            }

                            if( 0 != PL_strcmp((char *)cypher, rv) )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.4s.\"\n",
                                       a, b, c, d, e, f, cypher, rv);
                                PR_DELETE(rv);
                                return PR_FALSE;
                            }

                            PR_DELETE(rv);
                        }
                    }
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2013 of file base64t.c.

{
    int i;

    printf("Test 008 (PL_Base64Encode, random strings, malloc)                    ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 plen = PL_strlen(array[i].plaintext);
        PRUint32 clen = ((plen + 2)/3)*4;

        char *rv = PL_Base64Encode(array[i].plaintext, plen, (char *)0);

        if( (char *)0 == rv )
        {
            printf("FAIL\n\t(%d): no return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strcmp(rv, array[i].cyphertext) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
                   i, array[i].plaintext, array[i].cyphertext, rv);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2045 of file base64t.c.

{
    PRUint32 a, b;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 009 (PL_Base64Decode, single characters, equals)                 ..."); fflush(stdout);

    plain[1] = plain[2] = plain[3] = (unsigned char)0;
    cypher[2] = cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];

        for( b = 0; b < 4; b++ )
        {
            plain[0] = (unsigned char)(a * 4 + b);
            cypher[1] = base[(b * 16)];

            rv = PL_Base64Decode((char *)cypher, 4, result);
            if( rv != result )
            {
                printf("FAIL\n\t(%d, %d): return value\n", a, b);
                return PR_FALSE;
            }

            if( 0 != PL_strncmp((char *)plain, result, 1) )
            {
                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%.1s.\"\n",
                       a, b, plain, result);
                return PR_FALSE;
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2089 of file base64t.c.

{
    PRUint32 a, b;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 010 (PL_Base64Decode, single characters, no equals)              ..."); fflush(stdout);

    plain[1] = plain[2] = plain[3] = (unsigned char)0;
    cypher[2] = cypher[3] = (unsigned char)0;
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];

        for( b = 0; b < 4; b++ )
        {
            plain[0] = (unsigned char)(a * 4 + b);
            cypher[1] = base[(b * 16)];

            rv = PL_Base64Decode((char *)cypher, 2, result);
            if( rv != result )
            {
                printf("FAIL\n\t(%d, %d): return value\n", a, b);
                return PR_FALSE;
            }

            if( 0 != PL_strncmp((char *)plain, result, 1) )
            {
                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%.1s.\"\n",
                       a, b, plain, result);
                return PR_FALSE;
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2133 of file base64t.c.

{
    PRUint32 a, b, c, d;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 011 (PL_Base64Decode, double characters, equals)                 ..."); fflush(stdout);

    plain[2] = plain[3] = (unsigned char)0;
    cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    cypher[2] = base[d*4];

                    rv = PL_Base64Decode((char *)cypher, 4, result);
                    if( rv != result )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): return value\n", a, b, c, d);
                        return PR_FALSE;
                    }

                    if( 0 != PL_strncmp((char *)plain, result, 2) )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%.2s.\"\n",
                               a, b, c, d, plain, result);
                        return PR_FALSE;
                    }
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2184 of file base64t.c.

{
    PRUint32 a, b, c, d;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 012 (PL_Base64Decode, double characters, no equals)              ..."); fflush(stdout);

    plain[2] = plain[3] = (unsigned char)0;
    cypher[3] = (unsigned char)0;
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    cypher[2] = base[d*4];

                    rv = PL_Base64Decode((char *)cypher, 3, result);
                    if( rv != result )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): return value\n", a, b, c, d);
                        return PR_FALSE;
                    }

                    if( 0 != PL_strncmp((char *)plain, result, 2) )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%.2s.\"\n",
                               a, b, c, d, cypher, result);
                        return PR_FALSE;
                    }
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2235 of file base64t.c.

{
    PRUint32 a, b, c, d, e, f;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char result[ 8 ];
    char *rv;

    printf("Test 013 (PL_Base64Decode, triple characters)                         ..."); fflush(stdout);

    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    for( e = 0; e < 4; e++ )
                    {
                        cypher[2] = base[d*4 + e];
                        for( f = 0; f < 64; f++ )
                        {
                            plain[2] = e * 64 + f;
                            cypher[3] = base[f];

                            rv = PL_Base64Decode((char *)cypher, 4, result);
                            if( rv != result )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): return value\n", a, b, c, d, e, f);
                                return PR_FALSE;
                            }

                            if( 0 != PL_strncmp((char *)plain, result, 3) )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.3s.\"\n",
                                       a, b, c, d, e, f, plain, result);
                                return PR_FALSE;
                            }
                        }
                    }
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2292 of file base64t.c.

{
    int i;
    char result[ 4096 ];

    printf("Test 014 (PL_Base64Decode, random strings, equals)                    ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen = PL_strlen(array[i].cyphertext);
        PRUint32 plen = (clen * 3) / 4;

        char *rv = PL_Base64Decode(array[i].cyphertext, clen, result);

        if( rv != result )
        {
            printf("FAIL\n\t(%d): return value\n", i);
            return PR_FALSE;
        }

        if( 0 == (clen & 3) )
        {
            if( '=' == array[i].cyphertext[clen-1] )
            {
                if( '=' == array[i].cyphertext[clen-2] )
                {
                    plen -= 2;
                }
                else
                {
                    plen -= 1;
                }
            }
        }

        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, plen, result);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2340 of file base64t.c.

{
    int i;
    char buffer[ 4096 ];
    char result[ 4096 ];
    char *rv;

    printf("Test 015 (PL_Base64Decode, random strings, no equals)                 ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen, plen;

        PL_strcpy(buffer, array[i].cyphertext);
        clen = PL_strlen(buffer);

        if( 0 == (clen & 3) )
        {
            if( '=' == buffer[clen-1] )
            {
                if( '=' == buffer[clen-2] )
                {
                    buffer[clen-2] = buffer[clen-1] = (char)0;
                    clen -= 2;
                }
                else
                {
                    buffer[clen-1] = (char)0;
                    clen -= 1;
                }
            }
        }

        plen = (clen * 3) / 4;

        rv = PL_Base64Decode(buffer, clen, result);

        if( rv != result )
        {
            printf("FAIL\n\t(%d): return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, plen, result);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2396 of file base64t.c.

{
    PRUint32 a, b;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 016 (PL_Base64Decode, single characters, equals, malloc)         ..."); fflush(stdout);

    plain[1] = plain[2] = plain[3] = (unsigned char)0;
    cypher[2] = cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];

        for( b = 0; b < 4; b++ )
        {
            plain[0] = (unsigned char)(a * 4 + b);
            cypher[1] = base[(b * 16)];

            rv = PL_Base64Decode((char *)cypher, 4, (char *)0);
            if( (char *)0 == rv )
            {
                printf("FAIL\n\t(%d, %d): no return value\n", a, b);
                return PR_FALSE;
            }

            if( 0 != PL_strcmp((char *)plain, rv) )
            {
                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%s.\"\n",
                       a, b, plain, rv);
                PR_DELETE(rv);
                return PR_FALSE;
            }

            PR_DELETE(rv);
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2442 of file base64t.c.

{
    PRUint32 a, b;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 017 (PL_Base64Decode, single characters, no equals, malloc)      ..."); fflush(stdout);

    plain[1] = plain[2] = plain[3] = (unsigned char)0;
    cypher[2] = cypher[3] = (unsigned char)0;
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];

        for( b = 0; b < 4; b++ )
        {
            plain[0] = (unsigned char)(a * 4 + b);
            cypher[1] = base[(b * 16)];

            rv = PL_Base64Decode((char *)cypher, 2, (char *)0);
            if( (char *)0 == rv )
            {
                printf("FAIL\n\t(%d, %d): no return value\n", a, b);
                return PR_FALSE;
            }

            if( 0 != PL_strcmp((char *)plain, rv) )
            {
                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%s.\"\n",
                       a, b, plain, rv);
                PR_DELETE(rv);
                return PR_FALSE;
            }

            PR_DELETE(rv);
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2488 of file base64t.c.

{
    PRUint32 a, b, c, d;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 018 (PL_Base64Decode, double characters, equals, malloc)         ..."); fflush(stdout);

    plain[2] = plain[3] = (unsigned char)0;
    cypher[3] = (unsigned char)'=';
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    cypher[2] = base[d*4];

                    rv = PL_Base64Decode((char *)cypher, 4, (char *)0);
                    if( (char *)0 == rv )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): no return value\n", a, b, c, d);
                        return PR_FALSE;
                    }

                    if( 0 != PL_strcmp((char *)plain, rv) )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%s.\"\n",
                               a, b, c, d, plain, rv);
                        PR_DELETE(rv);
                        return PR_FALSE;
                    }

                    PR_DELETE(rv);
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2541 of file base64t.c.

{
    PRUint32 a, b, c, d;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 019 (PL_Base64Decode, double characters, no equals, malloc)      ..."); fflush(stdout);

    plain[2] = plain[3] = (unsigned char)0;
    cypher[3] = (unsigned char)0;
    cypher[4] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    cypher[2] = base[d*4];

                    rv = PL_Base64Decode((char *)cypher, 3, (char *)0);
                    if( (char *)0 == rv )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): no return value\n", a, b, c, d);
                        return PR_FALSE;
                    }

                    if( 0 != PL_strcmp((char *)plain, rv) )
                    {
                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%s.\"\n",
                               a, b, c, d, cypher, rv);
                        PR_DELETE(rv);
                        return PR_FALSE;
                    }

                    PR_DELETE(rv);
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2594 of file base64t.c.

{
    PRUint32 a, b, c, d, e, f;
    unsigned char plain[ 4 ];
    unsigned char cypher[ 5 ];
    char *rv;

    printf("Test 020 (PL_Base64Decode, triple characters, malloc)                 ..."); fflush(stdout);

    cypher[4] = (unsigned char)0;
    plain[3] = (unsigned char)0;

    for( a = 0; a < 64; a++ )
    {
        cypher[0] = base[a];
        for( b = 0; b < 4; b++ )
        {
            plain[0] = (a*4) + b;
            for( c = 0; c < 16; c++ )
            {
                cypher[1] = base[b*16 + c];
                for( d = 0; d < 16; d++ )
                {
                    plain[1] = c*16 + d;
                    for( e = 0; e < 4; e++ )
                    {
                        cypher[2] = base[d*4 + e];
                        for( f = 0; f < 64; f++ )
                        {
                            plain[2] = e * 64 + f;
                            cypher[3] = base[f];

                            rv = PL_Base64Decode((char *)cypher, 4, (char *)0);
                            if( (char *)0 == rv )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): no return value\n", a, b, c, d, e, f);
                                return PR_FALSE;
                            }

                            if( 0 != PL_strcmp((char *)plain, rv) )
                            {
                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.3s.\"\n",
                                       a, b, c, d, e, f, plain, rv);
                                PR_DELETE(rv);
                                return PR_FALSE;
                            }

                            PR_DELETE(rv);
                        }
                    }
                }
            }
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2654 of file base64t.c.

{
    int i;

    printf("Test 021 (PL_Base64Decode, random strings, equals, malloc)            ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen = PL_strlen(array[i].cyphertext);

        char *rv = PL_Base64Decode(array[i].cyphertext, clen, (char *)0);

        if( (char *)0 == rv )
        {
            printf("FAIL\n\t(%d): no return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strcmp(rv, array[i].plaintext) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, rv);
            PR_DELETE(rv);
            return PR_FALSE;
        }

        PR_DELETE(rv);
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2688 of file base64t.c.

{
    int i;
    char buffer[ 4096 ];
    char *rv;

    printf("Test 022 (PL_Base64Decode, random strings, no equals, malloc)         ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen;

        PL_strcpy(buffer, array[i].cyphertext);
        clen = PL_strlen(buffer);

        if( 0 == (clen & 3) )
        {
            if( '=' == buffer[clen-1] )
            {
                if( '=' == buffer[clen-2] )
                {
                    buffer[clen-2] = buffer[clen-1] = (char)0;
                    clen -= 2;
                }
                else
                {
                    buffer[clen-1] = (char)0;
                    clen -= 1;
                }
            }
        }

        rv = PL_Base64Decode(buffer, clen, (char *)0);

        if( (char *)0 == rv )
        {
            printf("FAIL\n\t(%d): no return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strcmp(rv, array[i].plaintext) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, rv);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2741 of file base64t.c.

{
    int i;
    char result[ 4096 ];

    printf("Test 023 (PL_Base64Encode, random strings, strlen)                    ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 plen = PL_strlen(array[i].plaintext);
        PRUint32 clen = ((plen + 2)/3)*4;

        char *rv = PL_Base64Encode(array[i].plaintext, 0, result);

        if( rv != result )
        {
            printf("FAIL\n\t(%d): return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strncmp(result, array[i].cyphertext, clen) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
                   i, array[i].plaintext, array[i].cyphertext, clen, result);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2774 of file base64t.c.

{
    int i;

    printf("Test 024 (PL_Base64Encode, random strings, malloc, strlen)            ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 plen = PL_strlen(array[i].plaintext);
        PRUint32 clen = ((plen + 2)/3)*4;

        char *rv = PL_Base64Encode(array[i].plaintext, 0, (char *)0);

        if( (char *)0 == rv )
        {
            printf("FAIL\n\t(%d): no return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strcmp(rv, array[i].cyphertext) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
                   i, array[i].plaintext, array[i].cyphertext, rv);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2806 of file base64t.c.

{
    int i;
    char result[ 4096 ];

    printf("Test 025 (PL_Base64Decode, random strings, equals, strlen)            ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen = PL_strlen(array[i].cyphertext);
        PRUint32 plen = (clen * 3) / 4;

        char *rv = PL_Base64Decode(array[i].cyphertext, 0, result);

        if( rv != result )
        {
            printf("FAIL\n\t(%d): return value\n", i);
            return PR_FALSE;
        }

        if( 0 == (clen & 3) )
        {
            if( '=' == array[i].cyphertext[clen-1] )
            {
                if( '=' == array[i].cyphertext[clen-2] )
                {
                    plen -= 2;
                }
                else
                {
                    plen -= 1;
                }
            }
        }

        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, plen, result);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2854 of file base64t.c.

{
    int i;
    char buffer[ 4096 ];
    char result[ 4096 ];
    char *rv;

    printf("Test 026 (PL_Base64Decode, random strings, no equals, strlen)         ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen, plen;

        PL_strcpy(buffer, array[i].cyphertext);
        clen = PL_strlen(buffer);

        if( 0 == (clen & 3) )
        {
            if( '=' == buffer[clen-1] )
            {
                if( '=' == buffer[clen-2] )
                {
                    buffer[clen-2] = buffer[clen-1] = (char)0;
                    clen -= 2;
                }
                else
                {
                    buffer[clen-1] = (char)0;
                    clen -= 1;
                }
            }
        }

        plen = (clen * 3) / 4;

        rv = PL_Base64Decode(buffer, 0, result);

        if( rv != result )
        {
            printf("FAIL\n\t(%d): return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, plen, result);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2910 of file base64t.c.

{
    int i;

    printf("Test 027 (PL_Base64Decode, random strings, equals, malloc, strlen)    ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen = PL_strlen(array[i].cyphertext);

        char *rv = PL_Base64Decode(array[i].cyphertext, 0, (char *)0);

        if( (char *)0 == rv )
        {
            printf("FAIL\n\t(%d): no return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strcmp(rv, array[i].plaintext) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, rv);
            PR_DELETE(rv);
            return PR_FALSE;
        }

        PR_DELETE(rv);
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2944 of file base64t.c.

{
    int i;
    char buffer[ 4096 ];
    char *rv;

    printf("Test 028 (PL_Base64Decode, random strings, no equals, malloc, strlen) ..."); fflush(stdout);

    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
    {
        PRUint32 clen;

        PL_strcpy(buffer, array[i].cyphertext);
        clen = PL_strlen(buffer);

        if( 0 == (clen & 3) )
        {
            if( '=' == buffer[clen-1] )
            {
                if( '=' == buffer[clen-2] )
                {
                    buffer[clen-2] = buffer[clen-1] = (char)0;
                    clen -= 2;
                }
                else
                {
                    buffer[clen-1] = (char)0;
                    clen -= 1;
                }
            }
        }

        rv = PL_Base64Decode(buffer, 0, (char *)0);

        if( (char *)0 == rv )
        {
            printf("FAIL\n\t(%d): no return value\n", i);
            return PR_FALSE;
        }

        if( 0 != PL_strcmp(rv, array[i].plaintext) )
        {
            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
                   i, array[i].cyphertext, array[i].plaintext, rv);
            return PR_FALSE;
        }
    }

    printf("PASS\n");
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct { ... } array[] [static]
unsigned char* base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" [static]

Definition at line 44 of file base64t.c.