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§
- Cbor
DetArray - 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_destructbelow. The abstraction is justified by the use of a refinement type, as per the definition ofcbor_det_arrayinpulse/CBOR.Pulse.Det.API.Rust.fst - Cbor
DetArray Iterator - The type of iterators over Deterministic CBOR arrays. It is made
abstract since it is meant to be used with an implementation of
the
Iteratortrait only. - Cbor
DetMap - 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_destructbelow. The abstraction is justified by the use of a refinement type, as per the definition ofcbor_det_mapinpulse/CBOR.Pulse.Det.API.Rust.fst - Cbor
DetMap Iterator - The type of iterators over Deterministic CBOR maps. It is made
abstract since it is meant to be used with an implementation of
the
Iteratortrait only.
Enums§
- Cbor
DetInt Kind - The kind of 64-bit integer: unsigned (to represent non-negative values), or negative (to represent negative values in two’s complement.)
- Cbor
DetView - A read-only view of a Deterministic CBOR object, as obtained by
peeling the first layer of nesting via
cbor_det_destructbelow.
Functions§
- cbor_
det_ destruct - 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.
- cbor_
det_ equal - Compares Deterministic CBOR objects for semantic equality. This function consumes stack space linear in the maximum nesting of its two arguments.
- cbor_
det_ get_ array_ item - Returns the
ith element of the CBOR arrayx. ReturnsNoneifiis equal to or larger than the number of array elements,Some(object)otherwise. - cbor_
det_ get_ array_ length - Returns the number of elements in a Deterministic CBOR array.
- cbor_
det_ get_ map_ length - Returns the number of elements in a Deterministic CBOR map.
- cbor_
det_ map_ entry_ key - Read the key of a map entry.
- cbor_
det_ map_ entry_ value - Read the value of a map entry.
- cbor_
det_ map_ get - Looks up a map
xfor an entry associated to the keyk. If such an entry exists, returnsSome(object)whereobjectis the value associated to that key. Otherwise, returnsNone. - cbor_
det_ mk_ array - Constructs a Deterministic CBOR of “array” type. This function
does not copy its input array. It returns
Noneif the input array has more than $2^64 - 1$ elements,Some(object)otherwise. - cbor_
det_ mk_ byte_ string - Constructs a Deterministic CBOR object of “byte string” type, with
the contents of
sas value. This function does not perform any copy of its inputs. It returnsNoneif the byte size ofsis larger than $2^64 - 1$,Some(object)otherwise. - cbor_
det_ mk_ int64 - Constructs a Deterministic CBOR object of “integer” type, with
kind
tyand valuev. - cbor_
det_ mk_ map - 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
Noneand 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. - cbor_
det_ mk_ map_ entry - Constructs a map entry from a key
xkand a valuexv. - cbor_
det_ mk_ simple_ value - Constructs a Deterministic CBOR object of “simple value” type,
with value
v. ReturnsNoneif the valuevlies in the reserved range (24..31), as specified by Table 4 of RFC 8949 Section 3.3;Some(object)otherwise. - cbor_
det_ mk_ tagged - Constructs a Deterministic CBOR object of Tagged type, with tag
tag, and the contents ofras value. This function does not perform any copy of its inputr. - cbor_
det_ mk_ text_ string - Constructs a Deterministic CBOR object of “text string” type, with
the contents of
sas value. This function does not perform any copy of its inputs. It returnsNoneif the byte size ofsis larger than $2^64 - 1$,Some(object)otherwise. This function respects the UTF-8 well-formedness invariants. - cbor_
det_ parse - Tries to parse a Deterministic CBOR object from the first bytes of
input, following RFC 8949 Section 4.2.1, minus floating-point values. ReturnsNonein case of failure, orSome(object, rem)in case of success, whereremis the remainder of the input slice past those first bytes ofinputthat 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. - cbor_
det_ serialize - Writes the binary representation of the Deterministic CBOR object
xinto the first bytes of theoutputbyte slice, following RFC 8949 Section 4.2.1. This function first checks the size ofxand returnsNoneif it is larger than the size ofoutput; otherwise it returnsSome(size), wheresizeis 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” ofxobtained fromcbor_det_parseuses only constant extra stack space for each such subobject (in the sense that the serialization does not recursively nest into such subobjects.) - cbor_
det_ size - Computes the byte size of the binary representation of the
Deterministic CBOR object
xfollowing RFC 8949 Section 4.2.1, but without serializingx. ReturnsNoneif 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” ofxobtained fromcbor_det_parseuses only constant extra stack space for each such subobject (in the sense that the computation does not recursively nest into such subobjects.)
Type Aliases§
- CborDet
- 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 thecbortype inspec/CBOR.Spec.Type.fsti. - Cbor
DetMap Entry - The type of key-value map entries.