Expand description
This module is an implementation of Deterministically Encoded CBOR (RFC 8949 Section 4.2.1) minus floating-point values, fully formally verified for functional correctness and absence of panics related to breach of abstraction, buffer overruns or arithmetic overflow/underflow. This module never allocates into the heap.
Structs§
- The read-only type of Deterministic CBOR arrays. Values of this type cannot be manually constructed by the user, they are meant to be obtained only via
cbor_det_destruct
below. The abstraction is justified by the use of a refinement type, as per the definition ofcbor_det_array
inpulse/CBOR.Pulse.Det.API.Rust.fst
- The type of iterators over Deterministic CBOR arrays. It is made abstract since it is meant to be used with an implementation of the
Iterator
trait only. - The read-only type of Deterministic CBOR maps. Values of this type cannot be manually constructed by the user, they are meant to be obtained only via
cbor_det_destruct
below. The abstraction is justified by the use of a refinement type, as per the definition ofcbor_det_map
inpulse/CBOR.Pulse.Det.API.Rust.fst
- The type of iterators over Deterministic CBOR maps. It is made abstract since it is meant to be used with an implementation of the
Iterator
trait only.
Enums§
- The kind of 64-bit integer: unsigned (to represent non-negative values), or negative (to represent negative values in two’s complement.)
- A read-only view of a Deterministic CBOR object, as obtained by peeling the first layer of nesting via
cbor_det_destruct
below.
Functions§
- Destructs a Deterministic CBOR object by peeling its first layer of nesting. This function does not recursively descend into array or map payloads, and only reads the header of a tagged payload. As such, it consumes constant stack space. This function respects the UTF-8 well-formedness invariants.
- Compares Deterministic CBOR objects for semantic equality. This function consumes stack space linear in the maximum nesting of its two arguments.
- Returns the
i
th element of the CBOR arrayx
. ReturnsNone
ifi
is equal to or larger than the number of array elements,Some(object)
otherwise. - Returns the number of elements in a Deterministic CBOR array.
- Returns the number of elements in a Deterministic CBOR map.
- Read the key of a map entry.
- Read the value of a map entry.
- Looks up a map
x
for an entry associated to the keyk
. If such an entry exists, returnsSome(object)
whereobject
is the value associated to that key. Otherwise, returnsNone
. - Constructs a Deterministic CBOR of “array” type. This function does not copy its input array. It returns
None
if the input array has more than $2^64 - 1$ elements,Some(object)
otherwise. - Constructs a Deterministic CBOR object of “byte string” type, with the contents of
s
as value. This function does not perform any copy of its inputs
. It returnsNone
if the byte size ofs
is larger than $2^64 - 1$,Some(object)
otherwise. - Constructs a Deterministic CBOR object of “integer” type, with kind
ty
and valuev
. - Constructs a map from a slice of map entries. This function does not copy its input array. If the input slice has more than $2^64 - 1$ entries, then this function returns
None
and does not change the input slice. Otherwise, this function tries to sort the input slice in-place with respect to the key order specified in Section 4.2.1 of RFC 8949 (without actually serializing the map entries.) If the sorting detects duplicate keys, then this function returnsNone
. Otherwise, it returnsSome(object)
. Due to the sorting, this function consumes stack space logarithmic in the size of the input slice, and linear in the maximum nesting of map entry keys, and the function may have changed the order of map entries in the input slice. - Constructs a map entry from a key
xk
and a valuexv
. - Constructs a Deterministic CBOR object of “simple value” type, with value
v
. ReturnsNone
if the valuev
lies in the reserved range (24..31
), as specified by Table 4 of RFC 8949 Section 3.3;Some(object)
otherwise. - Constructs a Deterministic CBOR object of Tagged type, with tag
tag
, and the contents ofr
as value. This function does not perform any copy of its inputr
. - Constructs a Deterministic CBOR object of “text string” type, with the contents of
s
as value. This function does not perform any copy of its inputs
. It returnsNone
if the byte size ofs
is larger than $2^64 - 1$,Some(object)
otherwise. This function respects the UTF-8 well-formedness invariants. - Tries to parse a Deterministic CBOR object from the first bytes of
input
, following RFC 8949 Section 4.2.1, minus floating-point values. ReturnsNone
in case of failure, orSome(object, rem)
in case of success, whererem
is the remainder of the input slice past those first bytes ofinput
that contain the valid binary representation ofinput
. This function does not perform a deep parse ofinput
, it only copies the object type, tag and/or size of the top-most object. As such, it uses constant stack space (including data validation.) “Destructor” functions are to be used on the returned object, to examine each level of nesting one at a time. NOTE: This implementation checks for the basic validity constraints of Section 5.3.1, i.e. the absence of duplicate map keys (which is a consequence of the deterministic encoding.), and the well-formedness of UTF-8 text strings. - Writes the binary representation of the Deterministic CBOR object
x
into the first bytes of theoutput
byte slice, following RFC 8949 Section 4.2.1. This function first checks the size ofx
and returnsNone
if it is larger than the size ofoutput
; otherwise it returnsSome(size)
, wheresize
is the byte size ofx
, the number of bytes written tooutput
. This function uses stack space in the order of the level of nesting of the use of “constructor” functions used to buildx
; the serialization of those “subobjects” ofx
obtained fromcbor_det_parse
uses only constant extra stack space for each such subobject (in the sense that the serialization does not recursively nest into such subobjects.) - Computes the byte size of the binary representation of the Deterministic CBOR object
x
following RFC 8949 Section 4.2.1, but without serializingx
. ReturnsNone
if that size is strictly larger thanbound
;Some(size)
otherwise. This function uses stack space in the order of the level of nesting of the use of “constructor” functions used to buildx
; the computation of the sizes of those “subobjects” ofx
obtained fromcbor_det_parse
uses only constant extra stack space for each such subobject (in the sense that the computation does not recursively nest into such subobjects.)
Type Aliases§
- An abstract type to represent a Deterministic CBOR object, which can be obtained either using “constructor” functions of this module, or by parsing from serialized data. Declared in
pulse/CBOR.Pulse.Det.API.Rust.fsti
. Its corresponding pure (“mathematical”) functional specification is thecbor
type inspec/CBOR.Spec.Type.fsti
. - The type of key-value map entries.