Base58 v0.1.0

Source
Base58 in the Bitcoin alphabet, which leaves out look-alike characters.

Base58EncodedMaxLength

pub func Base58EncodedMaxLength(length: uint) -> uint

The most characters the Base58 form of length bytes can occupy. Each byte needs at most log 256 / log 58, about 1.366, digits, so this is a bound rather than the exact length, which depends on the value. A destination of this length is always enough. Cannot fail for any length a slice in memory can have; runs in constant time and allocates nothing.

Source

Parameters

NameTypeDescription
lengthuintthe number of bytes to encode

Returns: an upper bound on the number of characters Base58Encode writes

Base58Encode

pub func Base58Encode(
    bytes: byte[..],
    into: var char8[..]
) -> uint ! FormatError

pub func Base58Encode(
    text: char8[..],
    into: var char8[..]
) -> uint ! FormatError

Writes bytes as Base58 into the front of into. Runs in time quadratic in the length of bytes, and not in constant time. Reports InsufficientCapacity when the encoded form does not fit into; Base58EncodedMaxLength(bytes.length) characters always fit. A refusal leaves into filled with zero bytes, because the conversion used it as scratch space. Room past the encoded form is not touched on success.

OverloadSummary
pub func Base58Encode(bytes: byte[..], into: var char8[..]) -> uint ! FormatErrorWrites bytes as Base58 into the front of into.
pub func Base58Encode(text: char8[..], into: var char8[..]) -> uint ! FormatErrorWrites the bytes of text as Base58 into the front of into.

Source

Parameters

NameTypeDescription
bytesbyte[..]the bytes to encode
intovar char8[..]the destination
textchar8[..]the text whose bytes to encode

Returns: the number of characters written

Base58Decode

pub func Base58Decode(
    text: char8[..],
    into: var byte[..]
) -> uint ! DecodeError

Reads Base58 text in the Bitcoin alphabet into the front of into. Each leading 1 becomes a zero byte. Runs in time quadratic in the length of text, and not in constant time. Reports InvalidCharacter at the first character outside the alphabet, leaving into untouched, and InsufficientCapacity when the decoded value does not fit into, leaving it filled with zero bytes because the conversion used it as scratch space. The count carried by that refusal is a lower bound on the length needed, not the exact length; text.length bytes are always enough.

Source

Parameters

NameTypeDescription
textchar8[..]the Base58 text to decode
intovar byte[..]the destination

Returns: the number of bytes written