ocean.util.encode.Base64

This module is used to decode and encode base64 cstring / ubyte[] arrays

istring blah = "Hello there, my name is Jeff.";
scope encodebuf = new char[allocateEncodeSize(blah.length)];
mstring encoded = encode(cast(const(ubyte)[])blah, encodebuf);

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

Members

Functions

allocateEncodeSize
size_t allocateEncodeSize(ubyte[] data)

Provide the size of the data once base64 encoded

allocateEncodeSize
size_t allocateEncodeSize(size_t length)

Provide the size of the data once base64 encoded

decode
ubyte[] decode(cstring data)

Decodes an ASCII base64 string and returns it as ubyte[] data. Allocates the size of the array.

decode
ubyte[] decode(cstring data, ubyte[] buff)

Decodes an ASCCI base64 string and returns it as ubyte[] data.

decode
ubyte[] decode(cstring data)

Decodes an ASCII base64 string and returns it as ubyte[] data. Allocates the size of the array.

decode
ubyte[] decode(cstring data, ubyte[] buff)

Decodes an ASCCI base64 string and returns it as ubyte[] data.

encode
mstring encode(ubyte[] data, mstring buff, bool pad)

Encodes data and returns as an ASCII base64 string.

encode
mstring encode(ubyte[] data, bool pad)

Encodes data and returns as an ASCII base64 string

encodeChunk
int encodeChunk(ubyte[] data, mstring buff, int bytesEncoded)

Encodes data into buff and returns the number of bytes encoded. This will not terminate and pad any "leftover" bytes, and will instead only encode up to the highest number of bytes divisible by three.

Static variables

defaultDecodeTable
ubyte[char.max + 1] defaultDecodeTable;

Default base64 encode/decode table

defaultEncodeTable
istring defaultEncodeTable;

Default base64 encode/decode table

urlSafeDecodeTable
ubyte[char.max + 1] urlSafeDecodeTable;

URL-safe base64 encode/decode table

urlSafeEncodeTable
istring urlSafeEncodeTable;

URL-safe base64 encode/decode table

Meta

License

Tango Dual License: 3-Clause BSD License / Academic Free License v3.0. See LICENSE_TANGO.txt for details.

Standards

rfc3548, rfc2045

Authors

Jeff Davey