multibase

package
v0.0.0-...-ce94876 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2019 License: MIT, MIT Imports: 5 Imported by: 0

README

go-multibase

Travis CI codecov.io

Implementation of multibase -self identifying base encodings- in Go.

Install

go-multibase is a standard Go module which can be installed with:

go get github.com/multiformats/go-multibase

Note that go-multibase is packaged with Gx, so it is recommended to use Gx to install and use it (see Usage section).

Usage

This module is packaged with Gx. In order to use it in your own project it is recommended that you:

go get -u github.com/whyrusleeping/gx
go get -u github.com/whyrusleeping/gx-go
cd <your-project-repository>
gx init
gx import github.com/multiformats/go-multibase
gx install --global
gx-go --rewrite

Please check Gx and Gx-go documentation for more information.

Maintainers

Captain: @whyrusleeping.

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2016 Protocol Labs Inc.

Documentation

Index

Constants

View Source
const (
	Identity          = 0x00
	Base1             = '1'
	Base2             = '0'
	Base8             = '7'
	Base10            = '9'
	Base16            = 'f'
	Base16Upper       = 'F'
	Base32            = 'b'
	Base32Upper       = 'B'
	Base32pad         = 'c'
	Base32padUpper    = 'C'
	Base32hex         = 'v'
	Base32hexUpper    = 'V'
	Base32hexPad      = 't'
	Base32hexPadUpper = 'T'
	Base58Flickr      = 'Z'
	Base58BTC         = 'z'
	Base64            = 'm'
	Base64url         = 'u'
	Base64pad         = 'M'
	Base64urlPad      = 'U'
)

These are the encodings specified in the standard, not are all supported yet

Variables

View Source
var EncodingToStr = map[Encoding]string{
	0x00: "identity",
	'f':  "base16",
	'F':  "base16upper",
	'b':  "base32",
	'B':  "base32upper",
	'c':  "base32pad",
	'C':  "base32padupper",
	'v':  "base32hex",
	'V':  "base32hexupper",
	't':  "base32hexpad",
	'T':  "base32hexpadupper",
	'Z':  "base58flickr",
	'z':  "base58btc",
	'm':  "base64",
	'u':  "base64url",
	'M':  "base64pad",
	'U':  "base64urlpad",
}
View Source
var Encodings = map[string]Encoding{
	"identity":          0x00,
	"base16":            'f',
	"base16upper":       'F',
	"base32":            'b',
	"base32upper":       'B',
	"base32pad":         'c',
	"base32padupper":    'C',
	"base32hex":         'v',
	"base32hexupper":    'V',
	"base32hexpad":      't',
	"base32hexpadupper": 'T',
	"base58flickr":      'Z',
	"base58btc":         'z',
	"base64":            'm',
	"base64url":         'u',
	"base64pad":         'M',
	"base64urlpad":      'U',
}

Encodigs is a map of the supported encoding, unsupported encoding specified in standard are left out

View Source
var ErrUnsupportedEncoding = fmt.Errorf("selected encoding not supported")

ErrUnsupportedEncoding is returned when the selected encoding is not known or implemented.

Functions

func Encode

func Encode(base Encoding, data []byte) (string, error)

Encode encodes a given byte slice with the selected encoding and returns a multibase string (<encoding><base-encoded-string>). It will return an error if the selected base is not known.

Types

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is a multibase encoding that is verified to be supported and supports an Encode method that does not return an error

func EncoderByName

func EncoderByName(str string) (Encoder, error)

EncoderByName creates an encoder from a string, the string can either be the multibase name or single character multibase prefix

func MustNewEncoder

func MustNewEncoder(base Encoding) Encoder

MustNewEncoder is like NewEncoder but will panic if the encoding is invalid.

func NewEncoder

func NewEncoder(base Encoding) (Encoder, error)

NewEncoder create a new Encoder from an Encoding

func (Encoder) Encode

func (p Encoder) Encode(data []byte) string

Encode encodes the multibase using the given Encoder.

func (Encoder) Encoding

func (p Encoder) Encoding() Encoding

type Encoding

type Encoding int

Encoding identifies the type of base-encoding that a multibase is carrying.

func Decode

func Decode(data string) (Encoding, []byte, error)

Decode takes a multibase string and decodes into a bytes buffer. It will return an error if the selected base is not known.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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