tango.util.encode.Base32

License:
BSD style:

author:
Ulrik Mikaelsson

Standards:
rfc3548, rfc4648





This module is used to decode and encode base32 char[] arrays.

Example:
char[] blah = "Hello there, my name is Jeff.";

scope encodebuf = new char[allocateEncodeSize(cast(ubyte[])blah)];
char[] encoded = encode(cast(ubyte[])blah, encodebuf);

scope decodebuf = new ubyte[encoded.length];
if (cast(char[])decode(encoded, decodebuf) == "Hello there, my name is Jeff.")
    Stdout("yay").newline;


Since v1.0

size_t allocateEncodeSize(const(ubyte[]) data);
calculates and returns the size needed to encode the length of the array passed.

Params:
const(ubyte[]) data An array that will be encoded

size_t allocateEncodeSize(size_t length);
calculates and returns the size needed to encode the length passed.

Params:
size_t length Number of bytes to be encoded

char[] encode(const(ubyte[]) data, char[] buff, bool pad = true);
encodes data and returns as an ASCII base32 string.

Params:
const(ubyte[]) data what is to be encoded
char[] buff buffer large enough to hold encoded data
bool pad Whether to pad ascii output with '='-chars

Example:
char[512] encodebuf;
char[] myEncodedString = encode(cast(ubyte[])"Hello, how are you today?", encodebuf);
Stdout(myEncodedString).newline; // JBSWY3DPFQQGQ33XEBQXEZJAPFXXKIDUN5SGC6J7


char[] encode(const(ubyte[]) data, bool pad = true);
encodes data and returns as an ASCII base32 string.

Params:
const(ubyte[]) data what is to be encoded
bool pad whether to pad output with '='-chars

Example:
char[] myEncodedString = encode(cast(ubyte[])"Hello, how are you today?");
Stdout(myEncodedString).newline; // JBSWY3DPFQQGQ33XEBQXEZJAPFXXKIDUN5SGC6J7


ubyte[] decode(const(char[]) data);
decodes an ASCII base32 string and returns it as ubyte[] data. Pre-allocates the size of the array.

This decoder will ignore non-base32 characters. So: SGVsbG8sIGhvd yBhcmUgeW91IH RvZGF5Pw==

Is valid.

Params:
const(char[]) data what is to be decoded

Example:
char[] myDecodedString = cast(char[])decode("JBSWY3DPFQQGQ33XEBQXEZJAPFXXKIDUN5SGC6J7");
Stdout(myDecodeString).newline; // Hello, how are you today?


ubyte[] decode(const(char[]) data, ubyte[] buff);
decodes an ASCII base32 string and returns it as ubyte[] data.

This decoder will ignore non-base32 characters. So: SGVsbG8sIGhvd yBhcmUgeW91IH RvZGF5Pw==

Is valid.

Params:
const(char[]) data what is to be decoded
ubyte[] buff a big enough array to hold the decoded data

Example:
ubyte[512] decodebuf;
char[] myDecodedString = cast(char[])decode("JBSWY3DPFQQGQ33XEBQXEZJAPFXXKIDUN5SGC6J7", decodebuf);
Stdout(myDecodeString).newline; // Hello, how are you today?



Page generated by Ddoc. Copyright (c) 2010 Ulrik Mikaelsson. All rights reserved