cbor

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: AGPL-3.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDecMode, _ = cbor.DecOptions{ExtraReturnErrors: cbor.ExtraDecErrorUnknownField}.DecMode()

DefaultDecMode is the DecMode used for decoding messages over the network. It returns an error if the message contains any extra field not present in the target (struct we are unmarshalling into), which prevents some classes of resource exhaustion attacks.

View Source
var EncMode = func() cbor.EncMode {

	options := cbor.CoreDetEncOptions()

	options.Time = cbor.TimeRFC3339Nano
	encMode, err := options.EncMode()
	if err != nil {
		panic(fmt.Errorf("could not extract encoding mode: %w", err))
	}
	return encMode
}()

EncMode is the default EncMode to use when creating a new cbor Encoder

View Source
var UnsafeDecMode, _ = cbor.DecOptions{}.DecMode()

UnsafeDecMode is a permissive mode for creating a new cbor Decoder.

CAUTION: this encoding should only be used for encoding/decoding data within a node. If used for decoding data that is shared between nodes, it makes the recipient VULNERABLE to RESOURCE EXHAUSTION ATTACKS, where a byzantine sender could include garbage data in the encoding, which would not be noticed by the recipient because the garbage data is dropped at the decoding step - yet, it consumes the recipient's networking bandwidth.

Functions

This section is empty.

Types

type Codec added in v0.23.2

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

func NewCodec added in v0.26.13

func NewCodec(opts ...Option) *Codec

NewCodec returns a new cbor Codec with the provided EncMode and DecMode. If either is nil, the default cbor EncMode/DecMode will be used.

func (*Codec) NewDecoder added in v0.23.2

func (c *Codec) NewDecoder(r io.Reader) encoding.Decoder

func (*Codec) NewEncoder added in v0.23.2

func (c *Codec) NewEncoder(w io.Writer) encoding.Encoder

type Marshaler added in v0.23.2

type Marshaler struct{}

func NewMarshaler added in v0.23.2

func NewMarshaler() *Marshaler

func (*Marshaler) Marshal added in v0.23.2

func (m *Marshaler) Marshal(val interface{}) ([]byte, error)

func (*Marshaler) MustMarshal added in v0.23.2

func (m *Marshaler) MustMarshal(val interface{}) []byte

func (*Marshaler) MustUnmarshal added in v0.23.2

func (m *Marshaler) MustUnmarshal(b []byte, val interface{})

func (*Marshaler) Unmarshal added in v0.23.2

func (m *Marshaler) Unmarshal(b []byte, val interface{}) error

type Option added in v0.26.13

type Option func(*Codec)

func WithDecMode added in v0.26.13

func WithDecMode(decMode cbor.DecMode) Option

WithDecMode sets the DecMode to use when creating a new cbor Decoder.

func WithEncMode added in v0.26.13

func WithEncMode(encMode cbor.EncMode) Option

WithEncMode sets the EncMode to use when creating a new cbor Encoder.

Jump to

Keyboard shortcuts

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