zbase32

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2016 License: MIT, Apache-2.0 Imports: 3 Imported by: 0

README

zbase32 -- Human-oriented encoding for binary data

Package zbase32 implements the z-base-32 encoding as specified in http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt

This package has been extensively tested to match the behavior of the zbase32 Python package.

Note that this is not RFC 4648/3548, for that see encoding/base32. z-base-32 is a variant that aims to be more human-friendly, and in some circumstances shorter.

For usage, see godoc.

Command line utilities

Included are simple command-line utilities for encoding/decoding data. Example:

$ echo hello, world | zbase32-encode
pb1sa5dxfoo8q551pt1yw
$ zbase32-decode pb1sa5dxfoo8q551pt1yw
hello, world
$ printf '\x01binary!!!1\x00' | zbase32-encode
yftg15ubqjh1nejbgryy
$ zbase32-decode yftg15ubqjh1nejbgryy | hexdump -C
00000000  01 62 69 6e 61 72 79 21  21 21 31 00              |.binary!!!1.|
0000000c

Documentation

Overview

Package zbase32 implements the z-base-32 encoding as specified in http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt

Note that this is NOT RFC 4648, for that see encoding/base32. z-base-32 is a variant that aims to be more human-friendly, and in some circumstances shorter.

Bits

When the amount of input is not a full number of bytes, encoding the data can lead to an unnecessary, non-information-carrying, trailing character in the encoded data. This package provides 'Bits' variants of the functions that can avoid outputting this unnecessary trailing character. For example, encoding a 20-bit message:

EncodeToString([]byte{0x10, 0x11, 0x10}) == "nyety"
EncodeBitsToString([]byte{0x10, 0x11, 0x10}, 20) == "nyet"

Decoding such a message requires also using the 'Bits' variant function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(dst, src []byte) (int, error)

Decode decodes z-base-32 encoded data from src. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written.

If src contains invalid z-base-32 data, it will return the number of bytes successfully written and CorruptInputError.

func DecodeBits

func DecodeBits(dst, src []byte, bits int) (int, error)

DecodeBits decodes the specified number of bits of z-base-32 encoded data from src. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written.

If src contains invalid z-base-32 data, it will return the number of bytes successfully written and CorruptInputError.

func DecodeBitsString

func DecodeBitsString(s string, bits int) ([]byte, error)

DecodeBitsString returns the bytes represented by the z-base-32 string s containing the specified number of bits.

func DecodeString

func DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the z-base-32 string s.

func DecodedLen

func DecodedLen(n int) int

DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of z-base-32-encoded data.

func Encode

func Encode(dst, src []byte) int

Encode encodes src. It writes at most EncodedLen(len(src)) bytes to dst and returns the number of bytes written.

Encode is not appropriate for use on individual blocks of a large data stream.

func EncodeBits

func EncodeBits(dst, src []byte, bits int) int

EncodeBits encodes the specified number of bits of src. It writes at most EncodedLen(len(src)) bytes to dst and returns the number of bytes written.

EncodeBits is not appropriate for use on individual blocks of a large data stream.

func EncodeBitsToString

func EncodeBitsToString(src []byte, bits int) string

EncodeBitsToString returns the z-base-32 encoding of the specified number of bits of src.

func EncodeToString

func EncodeToString(src []byte) string

EncodeToString returns the z-base-32 encoding of src.

func EncodedLen

func EncodedLen(n int) int

EncodedLen returns the maximum length in bytes of the z-base-32 encoding of an input buffer of length n.

Types

type CorruptInputError

type CorruptInputError int64

CorruptInputError means that the byte at this offset was not a valid z-base-32 encoding byte.

func (CorruptInputError) Error

func (e CorruptInputError) Error() string

type Value

type Value []byte

Value implements flag parsing for zbase32 values.

func (*Value) Get

func (v *Value) Get() interface{}

Get the data stored in the value. Returns a value of type []byte.

func (*Value) Set

func (v *Value) Set(s string) error

Set the value to data encoded by string.

func (*Value) String

func (v *Value) String() string

String returns the z-base-32 encoding of the value.

Directories

Path Synopsis
cmd
zbase32-decode
Command zbase32-decode decodes zbase32 from arguments or lines of stdin.
Command zbase32-decode decodes zbase32 from arguments or lines of stdin.
zbase32-encode
Command zbase32-encode encodes its standard input as zbase32.
Command zbase32-encode encodes its standard input as zbase32.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL