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

base32.c File Reference


Detailed Description

Base32 encoding/decoding.

We decode case insentively but encode using the specified alphabet, which is upper-cased only.

Author:
Raphael Manfredi
Date:
2001-2003

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

Functions

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

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

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

void base32_encode_str_into (const gchar *buf, gint len, gchar *encbuf, gint enclen, gboolean padding)
 Encode `len' bytes from `buf' into `enclen' bytes starting from `encbuf'.

gchar * base32_encode (const gchar *buf, gint len, gint *retpad, gboolean padding)
 Encode `len' bytes starting at `buf' into new allocated buffer.

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

gint base32_decode_into (const gchar *buf, gint len, gchar *decbuf, gint declen)
 Decode `len' bytes from `buf' into `declen' bytes starting from `decbuf', faking the necessary amount of padding if necessary.

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

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


Variables

const gint8 values [256]
const gchar * b32_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
const gint8 old_values [256]
 Older base32 alphabet: "ABCDEFGHIJK MN PQRSTUVWXYZ 23456789" We decode it only.


Function Documentation

gchar* base32_decode const gchar *  buf,
gint  len,
gint *  outlen
 

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

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

gint base32_decode_alphabet const gint8  valmap[256],
const gchar *  buf,
gint  len,
gchar *  decbuf,
gint  declen,
gint  padding
[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.

`padding', when non-zero, is the amount of padding that is missing from the input buffer and which we must assume.

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

gint base32_decode_into const gchar *  buf,
gint  len,
gchar *  decbuf,
gint  declen
 

Decode `len' bytes from `buf' into `declen' bytes starting from `decbuf', faking the necessary amount of padding if necessary.

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 base32.

gint base32_decode_old_into const gchar *  buf,
gint  len,
gchar *  decbuf,
gint  declen
 

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

faking the necessary amount of padding if necessary. Caller must have ensured that there was sufficient room in decbuf. The "old" base32 alphabet is used for decoding.

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

gchar* base32_encode const gchar *  buf,
gint  len,
gint *  retpad,
gboolean  padding
 

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

Trailing padding chars are emitted when `padding' is TRUE.

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

void base32_encode_exactly const gchar *  buf,
guint  len,
gchar *  encbuf,
gint  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 base32_encode_into const gchar *  buf,
gint  len,
gchar *  encbuf,
gint  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.

void base32_encode_str_into const gchar *  buf,
gint  len,
gchar *  encbuf,
gint  enclen,
gboolean  padding
 

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

Trailing padding chars are emitted when `padding' is TRUE. A trailing NUL is emitted at the end of the encoded buffer. Caller must have ensured that there was enough room in encbuf.

gint encode_pad_length gint  len,
gint *  pad
[static]
 

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

Returns:
the number of base32 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:base32.  c,
v 1.5 2005/06/29 14:24:26 daichik Exp $" 
 


Variable Documentation

const gchar* b32_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" [static]
 

const gint8 old_values[256] [static]
 

Older base32 alphabet: "ABCDEFGHIJK MN PQRSTUVWXYZ 23456789" We decode it only.

const gint8 values[256] [static]
 


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