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
- Variables
- func Decode(payload []byte, target any, options DecodeOptions) error
- func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
- func Encode(value any, options EncodeOptions) ([]byte, error)
- func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
- type DecodeOptions
- type DeterministicProfile
- type EncodeOptions
Constants ¶
const DefaultMaxBytes int64 = 1 << 20
DefaultMaxBytes is the default maximum CBOR item size.
Variables ¶
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.