Skip to content

Instantly share code, notes, and snippets.

@cschamp
Created August 24, 2010 23:53
Show Gist options
  • Save cschamp/548575 to your computer and use it in GitHub Desktop.
Save cschamp/548575 to your computer and use it in GitHub Desktop.
/* Base64_EncodeLength: Returns the maximum number of bytes that 'src'
will be encoded to (not including any NULL-termination). Cannot fail. */
int
Base64_EncodedLength(const uint8 *src, uint32 srclength);
/* Base64_Encode: Encoded 'src' into 'target'. Does not NULL-terminate. Returns
the size of the encoded string on success or -1 on failure. Behavior undefined
if 'srclength' is 0. */
int
Base64_Encode(const uint8 *src, uint32 srclength, char *target, uint32 targsize);
/* VMwareEasyBase64Encode: Base-64 encodes the binary data in 'data' into a
NULL-terminated character string returned in 's'. Returns TRUE on success.
FALSE on failure. */
Bool
VMwareEasyBase64Encode(uint8 *data,
size_t dataSize,
char **s)
{
Bool succeeded;
int size;
*s = (char *) malloc(Base64_EncodeLength(data, dataSize));
size = Base64_Encode(data, dataSize, s,
Base64_EncodedLength(data, dataSize));
if (-1 == size) {
goto exit;
}
succeeded = TRUE;
exit:
return succeeded;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment