cbor

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cbor encodes and decodes the CBOR subset used by Managed Device Attestation objects.

Design

The decoder accepts definite-length values with text map keys and bounds size and nesting. Tags, floating-point values, indefinite lengths, duplicate keys and trailing data are rejected. Attestation parsing selects the required format and certificate-chain members from the decoded map.

Marshal emits the same subset with deterministic map ordering from RFC 8949. This bounded format supports the attestation parser, simulator and tests; it is not a general CBOR implementation or a WebAuthn ceremony implementation.

References

Index

Constants

View Source
const (
	// MaxBytes is the largest input Unmarshal and Wellformed accept.
	MaxBytes = 1 << 20
	// MaxDepth is the deepest nesting of arrays and maps accepted.
	MaxDepth = 16
)

Limits applied to every decode.

Variables

View Source
var (
	ErrTooLarge    = errors.New("cbor: input too large")
	ErrSyntax      = errors.New("cbor: malformed input")
	ErrUnsupported = errors.New("cbor: item outside the supported subset")
	ErrTrailing    = errors.New("cbor: trailing data")
	ErrType        = errors.New("cbor: cannot decode into target")
	ErrDuplicate   = errors.New("cbor: duplicate map key")
	ErrDepth       = errors.New("cbor: nesting too deep")
	ErrTarget      = errors.New("cbor: target must be a non-nil pointer")
)

Decoding and encoding errors.

Functions

func Marshal

func Marshal(v any) ([]byte, error)

Marshal encodes v into the supported subset. Map and struct keys are written in the deterministic order of RFC 8949 section 4.2.1: by the bytes of the encoded key, which for text keys sorts shorter before longer and then bytewise. A RawMessage is copied verbatim after a well-formedness check, so a value that came from Unmarshal round-trips unchanged.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal decodes exactly one item from data into v, which must be a non-nil pointer. Input larger than MaxBytes, anything outside the subset described on the package, and any bytes after the item are errors.

func Wellformed

func Wellformed(data []byte) error

Wellformed reports whether data is exactly one item of the supported subset with nothing after it. It walks the whole input without decoding into a target, so a caller can reject a hostile body before spending anything on it.

Types

type RawMessage

type RawMessage []byte

RawMessage is an encoded item kept verbatim. Decoding into one copies the bytes of exactly one item, which lets a caller defer interpretation (an attestation statement is read only once its format name is known) and lets a server persist what it received byte for byte.

Jump to

Keyboard shortcuts

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