Skip to content

Commit e2d0e89

Browse files
committed
cbor: fix up package docs
1 parent 3a7fdb5 commit e2d0e89

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

src/cbor/mod.rs

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,72 @@
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7-
//! Tiny CBOR encoder and decoder.
7+
//! Tiny, security-focused CBOR encoder/decoder.
88
//!
9-
//! https://datatracker.ietf.org/doc/html/rfc8949
9+
//! <https://datatracker.ietf.org/doc/html/rfc8949>
1010
//!
11-
//! This is an implementation of the CBOR spec with an extremely reduced type
12-
//! system, focusing on security rather than flexibility or completeness. The
13-
//! following types are supported:
14-
//! - Booleans: bool
15-
//! - Null: Option<T>::None, cbor::Null
16-
//! - 64bit positive integers: u64
17-
//! - 64bit signed integers: i64
18-
//! - UTF-8 text strings: String, &str
19-
//! - Byte strings: Vec<u8>, &[u8], [u8; N]
20-
//! - Arrays: (), (X,), (X,Y), ... tuples, or structs with #[cbor(array)]
21-
//! - Maps: structs with #[cbor(key = N)] fields, Option<T>::None omitted
11+
//! # Type system
12+
//!
13+
//! Only a minimal subset of CBOR is supported:
14+
//!
15+
//! - **Booleans:** `bool`
16+
//! - **Integers:** `u64`, `i64`
17+
//! - **Text:** `String`, `&str`
18+
//! - **Bytes:** `Vec<u8>`, `&[u8]`, `[u8; N]`
19+
//! - **Null:** `Option<T>::None`, `cbor::Null`
20+
//! - **Arrays:** `()`, `(X,)`, `(X, Y)`, ... tuples, or structs with `#[cbor(array)]`
21+
//! - **Maps:** structs with `#[cbor(key = N)]` fields (integer keys, deterministic order)
22+
//! - **Raw:** `cbor::Raw` (opaque CBOR bytes, passed through without parsing)
23+
//!
24+
//! # Derive macros
25+
//!
26+
//! Array mode — fields encode positionally:
27+
//!
28+
//! ```ignore
29+
//! #[derive(Cbor)]
30+
//! #[cbor(array)]
31+
//! struct Foo {
32+
//! a: u64,
33+
//! b: String,
34+
//! }
35+
//! ```
36+
//!
37+
//! Map mode — fields encode as key-value pairs sorted by CBOR key bytes:
38+
//!
39+
//! ```ignore
40+
//! #[derive(Cbor)]
41+
//! struct Bar {
42+
//! #[cbor(key = 1)]
43+
//! x: u64, // required
44+
//! #[cbor(key = 2)]
45+
//! y: Option<Vec<u8>>, // optional: omitted when None
46+
//! #[cbor(key = 3)]
47+
//! z: Option<Option<u64>>, // nullable: always present, value or null
48+
//! }
49+
//! ```
50+
//!
51+
//! # Embedding
52+
//!
53+
//! Fields marked `#[cbor(embed)]` are flattened into the parent map. The embedded
54+
//! type must itself be a map-mode struct. Keys across all embeds and direct fields
55+
//! must not overlap.
56+
//!
57+
//! ```ignore
58+
//! #[derive(Cbor)]
59+
//! struct Token {
60+
//! #[cbor(embed)]
61+
//! identity: Identity, // keys from Identity merge into Token
62+
//! #[cbor(key = 3)]
63+
//! aud: String,
64+
//! }
65+
//! ```
66+
//!
67+
//! # Encoding rules
68+
//!
69+
//! All output is deterministic (RFC 8949 Section 4.2.1): canonical shortest-form
70+
//! integers, map keys sorted by encoded bytes, no indefinite lengths, no floats,
71+
//! no tags. Decoders reject non-canonical input, duplicate keys, and out-of-order
72+
//! keys.
2273
2374
pub use darkbio_crypto_cbor_derive::Cbor;
2475

src/cose/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod types;
1313

1414
pub use types::{
1515
CoseEncrypt0, CoseSign1, CritHeader, EmptyHeader, EncProtectedHeader, EncStructure,
16-
EncapKeyHeader, SigProtectedHeader, SigStructure, HEADER_TIMESTAMP,
16+
EncapKeyHeader, HEADER_TIMESTAMP, SigProtectedHeader, SigStructure,
1717
};
1818

1919
// Use an indirect time package that mostly defers to sts::time on most platforms,

0 commit comments

Comments
 (0)