cbor

package
v0.0.0-...-9865f5a Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cbor provides helpers for encoding and decoding canonical CBOR.

Using this package will produce canonical encodings which can be used in cryptographic contexts like signing as the same message is guaranteed to always have the same serialization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixSliceForSerde

func FixSliceForSerde(b []byte) []byte

FixSliceForSerde will convert `nil` to `[]byte` to work around serde brain damage.

func Marshal

func Marshal(src interface{}) []byte

Marshal serializes a given type into a CBOR byte vector.

func MustUnmarshal

func MustUnmarshal(data []byte, dst interface{})

MustUnmarshal deserializes a CBOR byte vector into a given type. Panics if unmarshal fails.

func NewDecoder

func NewDecoder(r io.Reader) *cbor.Decoder

NewDecoder creates a new CBOR decoder.

func NewEncoder

func NewEncoder(w io.Writer) *cbor.Encoder

NewEncoder creates a new CBOR encoder.

func Unmarshal

func Unmarshal(data []byte, dst interface{}) error

Unmarshal deserializes a CBOR byte vector into a given type.

func UnmarshalTrusted

func UnmarshalTrusted(data []byte, dst interface{}) error

UnmarshalTrusted deserializes a CBOR byte vector into a given type.

This method MUST ONLY BE USED FOR TRUSTED INPUTS as it relaxes some decoding restrictions.

Types

type MessageCodec

type MessageCodec struct {
	MessageReader
	MessageWriter
}

MessageCodec is a length-prefixed Message encoder/decoder.

func NewMessageCodec

func NewMessageCodec(rw io.ReadWriter, module string) *MessageCodec

NewMessageCodec constructs a new Message encoder/decoder.

type MessageReader

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

MessageReader is a reader wrapper that decodes CBOR-encoded Message structures.

func (*MessageReader) Read

func (c *MessageReader) Read(msg interface{}) error

Read deserializes a single CBOR-encoded Message from the underlying reader.

type MessageWriter

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

MessageWriter is a writer wrapper that encodes Messages structures to CBOR.

func (*MessageWriter) Write

func (c *MessageWriter) Write(msg interface{}) error

Write serializes a single Message to CBOR and writes it to the underlying writer.

type RawMessage

type RawMessage = cbor.RawMessage

RawMessage is a raw encoded CBOR value. It implements Marshaler and Unmarshaler interfaces and can be used to delay CBOR decoding or precompute a CBOR encoding.

Jump to

Keyboard shortcuts

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