DragonFly On-Line Manual Pages

Search: Section:  


PWS_BASE64_ENCODE(3)  DragonFly Library Functions Manual  PWS_BASE64_ENCODE(3)

NAME

pws_base64_encode, pws_base64_decode - Encode and decode strings to and from Base64

LIBRARY

-lpwstor

SYNOPSIS

#include <pwstor.h> unsigned char * pws_base64_encode(unsigned char *src, unsigned char *dst, size_t len); unsigned char * pws_base64_decode(unsigned char *src, unsigned char *dst);

DESCRIPTION

The function pws_base64_encode() will encode len bytes of data from the memory referenced by pointer src and store that data in the memory referenced by pointer dst. The pointer dst must be at least large enough to hold (( len * 2) +1) bytes of data just to be on the safe side. (While this isn't technically correct, the actual expansion is a fraction, which multiplying by floating point integers may confuse some inexperienced programmers who may then fall victim to buffer overflows. Experienced developers should know how much memory is necessary and be able to calculate it more appropriately to save a few bytes, but *2 will always work safely.) The +1 is to allow for the storage of a null- terminating byte, since pws_base64_decode expects its Base64-encoded argument to be null-terminated. Adding the null-terminating byte is up to the application, however the safest thing to do is generally to use memset() or calloc() so that the memory buffer will be initialized to 0s regardless, and it can simply be propagated by the pws_base64_encode() function. A pointer to the memory buffer referenced by dst is returned. The function pws_base64_decode() can be used to decode data stored in memory pointed to by src from Base64 back to its true value. The true value will be stored in the memory pointed to by dst. Since src is Base64 encoded, it is expected to be a null-terminated string. The dst argument is expected to be a pointer to a memory buffer large enough to store the results of decoding in. A pointer to the memory buffer referenced by dst is returned.

SEE ALSO

pwstor(3) DragonFly 6.5-DEVELOPMENT October 23, 2008 DragonFly 6.5-DEVELOPMENT

Search: Section: