cbor

package
v0.0.0-...-61460eb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 4 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

View Source
var (
	// ErrInvalidVersion is the error returned when a versioned
	// serialized blob is either missing, or has an invalid version.
	ErrInvalidVersion = errors.New("cbor: missing or invalid version")
)

Functions

func FixSliceForSerde

func FixSliceForSerde(b []byte) []byte

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

func GetVersion

func GetVersion(data []byte) (uint16, error)

GetVersion returns the version of a versioned serializable data structure, if any.

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 Marshaler

type Marshaler = cbor.Marshaler

Marshaler is the interface implemented by types that can marshal themselves into valid CBOR.

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.

type Unmarshaler

type Unmarshaler = cbor.Unmarshaler

Unmarshaler is the interface implemented by types that wish to unmarshal CBOR data themselves. The input is a valid CBOR value. UnmarshalCBOR must copy the CBOR data if it needs to use it after returning.

type Versioned

type Versioned struct {
	V uint16 `json:"v"`
}

Versioned is a generic versioned serializable data structure.

func NewVersioned

func NewVersioned(v uint16) Versioned

NewVersioned creates a new Versioned structure with the specified version.

Jump to

Keyboard shortcuts

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