• Stars
    star
    241
  • Rank 167,643 (Top 4 %)
  • Language
    Rust
  • License
    Other
  • Created about 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CBOR utilities

Workflow Status Average time to resolve an issue Percentage of issues still open Maintenance

ciborium

Welcome to Ciborium!

Ciborium contains CBOR serialization and deserialization implementations for serde.

Quick Start

You're probably looking for from_reader() and into_writer(), which are the main functions. Note that byte slices are also readers and writers and can be passed to these functions just as streams can.

For dynamic CBOR value creation/inspection, see Value.

Design Decisions

Always Serialize Numeric Values to the Smallest Size

Although the CBOR specification has differing numeric widths, this is only a form of compression on the wire and is not intended to directly represent an "integer width" or "float width." Therefore, ciborium always serializes numbers to the smallest possible lossless encoding. For example, we serialize 1u128 as a single byte (01). Likewise, we will also freely decode that single byte into a u128.

While there is some minor performance cost for this, there are several reasons for this choice. First, the specification seems to imply it by using a separate bit for the sign. Second, the specification requires that implementations handle leading zeroes; a liberal reading of which implies a requirement for lossless coercion. Third, dynamic languages like Python have no notion of "integer width," making this is a practical choice for maximizing wire compatibility with those languages.

This coercion is always lossless. For floats, this implies that we only coerce to a smaller size if coercion back to the original size has the same raw bits as the original.

Compatibility with Other Implementations

The ciborium project follows the Robustness Principle. Therefore, we aim to be liberal in what we accept. This implies that we aim to be wire-compatible with other implementations in decoding, but not necessarily encoding.

One notable example of this is that serde_cbor uses fixed-width encoding of numbers and doesn't losslessly coerce. This implies that ciborium will successfully decode serde_cbor encodings, but the opposite may not be the case.

Representing Map as a Sequence of Values

Other serde parsers have generally taken the route of using BTreeMap or HashMap to implement their encoding's underlying Map type. This crate chooses to represent the Map type using Vec<(Value, Value)> instead.

This decision was made because this type preserves the order of the pairs on the wire. Further, for those that need the properties of BTreeMap or HashMap, you can simply collect() the values into the respective type. This provides maximum flexibility.

Low-level Library

The ciborium crate has the beginnings of a low-level library in the (private) basic module. We may extend this to be more robust and expose it for application consumption once we have it in a good state. If you'd like to collaborate with us on that, please contact us. Alternatively, we might fork this code into a separate crate with no serde dependency.

Internal Types

The ciborium crate contains a number of internal types that implement useful serde traits. While these are not currently exposed, we might choose to expose them in the future if there is demand. Generally, this crate takes a conservative approach to exposing APIs to avoid breakage.

Packed Encoding?

Packed encoding uses numerical offsets to represent structure field names and enum variant names. This can save significant space on the wire.

While the authors of this crate like packed encoding, it should generally be avoided because it can be fragile as it exposes invariants of your Rust code to remote actors. We might consider adding this in the future. If you are interested in this, please contact us.

License: Apache-2.0

More Repositories

1

enarx

Enarx: Confidential Computing with WebAssembly
Rust
1,281
star
2

flagset

Rust data types and a macro for generating enumeration-based bit flags
Rust
42
star
3

codex

Code examples that can be compiled to WebAssembly for use with Enarx
Nix
22
star
4

sgx

Library for Intel SGX
Rust
14
star
5

mmarinus

A safe mmap implementation
Rust
11
star
6

steward

A Confidential Computing-Aware Certificate Authority
Rust
9
star
7

iocuddle

Safely call ioctls from Rust
Rust
8
star
8

outreachy

Repo to receive contributions from Outreachy applicants
JavaScript
8
star
9

drawbridge

A Confidential Computing-Aware Workload Repository
Rust
8
star
10

crt0stack

Tools for reading and creating Linux crt0 stack data
Rust
6
star
11

cryptle

Secure multi-party clone of Wordle with Enarx
Rust
6
star
12

primordial

Low-level CPU primitives
Rust
6
star
13

website

Enarx Website
JavaScript
5
star
14

vfs

Rust
5
star
15

vdso

Rust crate for resolving Linux vDSO symbols
Rust
4
star
16

xsave

An implementation of x86 XSave semantics
Rust
4
star
17

vscode-enarx

An extension for VS Code which provides support for Enarx & WebAssembly
TypeScript
3
star
18

rcrt1

Rust
3
star
19

outreach

Outreach efforts for the Enarx project
2
star
20

nbytes

Rust compile-time evaluation of byte unit conversions
Rust
2
star
21

mmledger

A ledger for confidential computing (CC) shims for tracking memory management system calls
Rust
2
star
22

noted

Library for creating ELF notes
Rust
2
star
23

testaso

Rust
1
star
24

snp

Library for AMD SEV-SNP
Rust
1
star
25

.github

Github-specific repository to hold organisation-wide community files.
Shell
1
star
26

gha-runner

container for running tests on our dedicated hardware
Shell
1
star
27

spdx

GitHub Action that tests source code for SPDX license headers
Python
1
star
28

try.enarx.dev

Try Enarx
HTML
1
star
29

ConfidentialTrading

.NET Algo Trading demo for Enarx
C#
1
star