Back to index

lightning-sunbird  0.9+nobinonly
Functions
plbase64.h File Reference
#include "prtypes.h"

Go to the source code of this file.

Functions

PR_BEGIN_EXTERN_C PL_Base64Encode (const char *src, PRUint32 srclen, char *dest)
 PL_Base64Decode (const char *src, PRUint32 srclen, char *dest)

Function Documentation

PL_Base64Decode ( const char *  src,
PRUint32  srclen,
char *  dest 
)

Definition at line 370 of file base64.c.

{
    PRStatus status;
    PRBool allocated = PR_FALSE;

    if( (char *)0 == src )
    {
        return (char *)0;
    }

    if( 0 == srclen )
    {
        srclen = PL_strlen(src);
    }

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

    if( (char *)0 == dest )
    {
        PRUint32 destlen = ((srclen * 3) / 4);
        dest = (char *)PR_MALLOC(destlen + 1);
        if( (char *)0 == dest )
        {
            return (char *)0;
        }
        dest[ destlen ] = (char)0; /* null terminate */
        allocated = PR_TRUE;
    }

    status = decode((const unsigned char *)src, srclen, (unsigned char *)dest);
    if( PR_SUCCESS != status )
    {
        if( PR_TRUE == allocated )
        {
            PR_DELETE(dest);
        }

        return (char *)0;
    }

    return dest;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PR_BEGIN_EXTERN_C PL_Base64Encode ( const char *  src,
PRUint32  srclen,
char *  dest 
)

Definition at line 145 of file base64.c.

{
    if( 0 == srclen )
    {
        srclen = PL_strlen(src);
    }

    if( (char *)0 == dest )
    {
        PRUint32 destlen = ((srclen + 2)/3) * 4;
        dest = (char *)PR_MALLOC(destlen + 1);
        if( (char *)0 == dest )
        {
            return (char *)0;
        }
        dest[ destlen ] = (char)0; /* null terminate */
    }

    encode((const unsigned char *)src, srclen, (unsigned char *)dest);
    return dest;
}

Here is the call graph for this function:

Here is the caller graph for this function: