cborwire

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cborwire provides bounded CBOR decoding and deterministic encoding.

Duplicate keys, indefinite-length items, and tags are rejected by default. Tags and indefinite lengths require explicit interoperability options. Encoding defaults to RFC 7049 canonical form, with explicit Core Deterministic and CTAP2 profiles available. Decoder nesting and collection limits remain bounded even when the byte limit is raised. CBOR is excluded from wire.DetectFormat because arbitrary binary data cannot be identified reliably.

Index

Constants

View Source
const DefaultMaxBytes int64 = 1 << 20

DefaultMaxBytes is the default maximum CBOR item size.

Variables

View Source
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")

ErrPayloadTooLarge identifies CBOR items over the configured byte limit.

Functions

func Decode

func Decode(payload []byte, target any, options DecodeOptions) error

Decode parses exactly one CBOR data item into target.

func DecodeReader

func DecodeReader(reader io.Reader, target any, options DecodeOptions) error

DecodeReader reads a bounded stream and parses exactly one CBOR data item.

func Encode

func Encode(value any, options EncodeOptions) ([]byte, error)

Encode serializes value using a defined deterministic CBOR profile.

func EncodeWriter

func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error

EncodeWriter serializes value and writes one complete CBOR data item.

Types

type DecodeOptions

type DecodeOptions struct {
	MaxBytes              int64
	MaxNestedLevels       int
	MaxArrayElements      int
	MaxMapPairs           int
	DisallowUnknownFields bool
	AllowTags             bool
	AllowIndefiniteLength bool
}

DecodeOptions controls CBOR interoperability and resource constraints. Zero resource limits use fxamacker/cbor's bounded defaults.

type DeterministicProfile

type DeterministicProfile uint8

DeterministicProfile identifies a defined deterministic CBOR encoding.

const (
	// Canonical uses the canonical encoding defined by RFC 7049 section 3.9.
	Canonical DeterministicProfile = iota
	// CoreDeterministic uses RFC 8949 core deterministic encoding.
	CoreDeterministic
	// CTAP2Deterministic uses the CTAP2 canonical CBOR profile.
	CTAP2Deterministic
)

type EncodeOptions

type EncodeOptions struct {
	MaxBytes  int64
	Profile   DeterministicProfile
	AllowTags bool
	TimeTag   bool
}

EncodeOptions controls the deterministic profile and tag behavior.

Jump to

Keyboard shortcuts

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