Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

base64.c File Reference


Detailed Description

Base64 encoding/decoding.

Author:
Raphael Manfredi
Date:
2003

#include "common.h"
#include <glib.h>
#include <string.h>
#include "base64.h"
#include "override.h"

Functions

 RCSID ("$Id:base64.c, v 1.7 2005/06/29 14:24:26 daichik Exp $")
guint encode_pad_length (guint len, guint *pad)
 Compute the number of base64 digits and amount of padding necessary to encode `len' bytes.

void base64_encode_exactly (const gchar *buf, guint len, gchar *encbuf, guint enclen)
 Encode `len' bytes from `buf' into `enclen' bytes starting from `encbuf'.

void base64_encode_into (const gchar *buf, guint len, gchar *encbuf, guint enclen)
 Encode `len' bytes from `buf' into `enclen' bytes starting from `encbuf'.

gchar * base64_encode (const gchar *buf, guint len, guint *retpad)
 Encode `len' bytes starting at `buf' into new allocated buffer.

guint base64_decode_alphabet (const gint8 valmap[256], const gchar *buf, guint len, gchar *decbuf, guint declen)
 Decode `len' bytes from `buf' into `declen' bytes starting from `decbuf'.

guint base64_decode_into (const gchar *buf, guint len, gchar *decbuf, guint declen)
 Decode `len' bytes from `buf' into `declen' bytes starting from `decbuf'.

gchar * base64_decode (const gchar *buf, guint len, guint *outlen)
 Decode `len' bytes starting at `buf' into new allocated buffer.


Variables

const gint8 values [256]
const gchar b64_alphabet []


Function Documentation

gchar* base64_decode const gchar *  buf,
guint  len,
guint *  outlen
 

Decode `len' bytes starting at `buf' into new allocated buffer.

Returns:
the new decoded buffer, or NULL if the input was not valid base64 encoding. The caller knows the length of the returned buffer: it's the size of the input divided by 4 and multiplied by 3. If `outlen' is non-NULL, it is filled with the amount of bytes decoded into the buffer (without trailing padding).

guint base64_decode_alphabet const gint8  valmap[256],
const gchar *  buf,
guint  len,
gchar *  decbuf,
guint  declen
[static]
 

Decode `len' bytes from `buf' into `declen' bytes starting from `decbuf'.

Caller must have ensured that there was sufficient room in decbuf. Uses the specified decoding alphabet.

Returns:
decoded bytes if successful, 0 if the input was not valid base64.

guint base64_decode_into const gchar *  buf,
guint  len,
gchar *  decbuf,
guint  declen
 

Decode `len' bytes from `buf' into `declen' bytes starting from `decbuf'.

Caller must have ensured that there was sufficient room in decbuf.

Returns:
the amount of bytes decoded (without trailing padding) if successful, 0 if the input was not valid base64.

gchar* base64_encode const gchar *  buf,
guint  len,
guint *  retpad
 

Encode `len' bytes starting at `buf' into new allocated buffer.

Trailing padding chars are emitted.

Returns:
the new encoded buffer, NUL-terminated, and the added amount of padding chars in `retpad' if it is a non-NULL pointer.

void base64_encode_exactly const gchar *  buf,
guint  len,
gchar *  encbuf,
guint  enclen
[static]
 

Encode `len' bytes from `buf' into `enclen' bytes starting from `encbuf'.

Caller must have ensured that there was EXACTLY the needed room in encbuf.

void base64_encode_into const gchar *  buf,
guint  len,
gchar *  encbuf,
guint  enclen
 

Encode `len' bytes from `buf' into `enclen' bytes starting from `encbuf'.

Trailing padding chars are emitted. Caller must have ensured that there was enough room in encbuf.

Attention:
NB: No trailing NUL is emitted.

guint encode_pad_length guint  len,
guint *  pad
[static]
 

Compute the number of base64 digits and amount of padding necessary to encode `len' bytes.

Returns:
the number of base64 digits necessary. Furthermore, if `pad' is a non-NULL pointer, it is filled with the amount of padding chars that would be necessary.

RCSID "$Id:base64.  c,
v 1.7 2005/06/29 14:24:26 daichik Exp $" 
 


Variable Documentation

const gchar b64_alphabet[] [static]
 

Initial value:

    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

const gint8 values[256] [static]
 


Generated on Sun Feb 12 10:49:59 2006 for Gtk-Gnutella by doxygen 1.3.6