Skip to main content

ledvar_core/
lib.rs

1//! `ledvar-core` — the reference implementation of the **Ledvar protocol** core:
2//! the data model, the canonical content-addressed hashing, and well-formedness.
3//!
4//! The crate is deliberately **domain-blind** (it knows nothing about security,
5//! cloud, or any domain) and **dependency-light** (`serde` for the wire model,
6//! `sha2` for hashing — nothing else). Hashing streams the canonical bytes
7//! straight into SHA-256 with no intermediate allocation; see the design note in
8//! `docs/canonical-hashing.md`.
9//!
10//! ```
11//! use ledvar_core::Node;
12//! use std::collections::{BTreeMap, BTreeSet};
13//!
14//! let mut content = BTreeMap::new();
15//! content.insert("grants".to_string(), BTreeSet::from(["SELECT".into(), "INSERT".into()]));
16//! content.insert("risk".to_string(), BTreeSet::from(["Medium".into()]));
17//! let node = Node {
18//!     path: vec!["mydb".into(), "user:app".into()],
19//!     content,
20//!     labels: BTreeMap::new(),
21//!     refs: Vec::new(),
22//! };
23//! assert_eq!(node.identity_key().unwrap(), "8e303e0e8139ff7d377e0eaf9097e2790071f9914bc7cf8b28020bb98a3cca95");
24//! assert_eq!(node.content_hash().unwrap(), "296190489d577d410f0f7fa09dfa24660722227fe405daaf621f4e2666bf370f");
25//! ```
26
27#![forbid(unsafe_code)]
28#![warn(missing_docs)]
29
30mod canon;
31mod error;
32mod model;
33mod version;
34mod wellformed;
35
36pub use canon::canonical_json_string;
37pub use error::Error;
38pub use model::{Node, Ref, SUPPORTED_PROTOCOL_MAJOR, SUPPORTED_PROTOCOL_MINOR, Snapshot};
39pub use version::{parse, parse_major};
40pub use wellformed::{validate, validate_node};