Skip to main content

Crate rfc9162_tiles

Crate rfc9162_tiles 

Source
Expand description

Tiled, indexed storage for an RFC 9162 log, laid out as C2SP tlog-tiles (https://c2sp.org/tlog-tiles): 256-hash tiles, 256-entry bundles, and the tree rfc9162 hashes. Any tlog-tiles client reads the tree. The index sidecars beside it are this crate’s addition and tlog clients ignore them.

The root over the tiles is rfc9162::root over the same leaves, and the proofs a reader assembles from tiles are the bytes rfc9162::inclusion_proof and rfc9162::consistency_proof give over the flat leaf slice. The head is a C2SP checkpoint, an Ed25519 signed note, with witness cosignatures checked as cosignature/v1.

use rfc9162_tiles::index::no_keys;
use rfc9162_tiles::{MemoryStore, Reader, Writer};

let store = MemoryStore::new();
let mut writer = Writer::open(store.clone(), no_keys())?;
let index = writer.append(b"first record")?;
drop(writer);

let reader = Reader::open(store, no_keys())?;
assert_eq!(reader.get(index)?, Some(b"first record".to_vec()));
let proof = reader.inclusion(index)?.unwrap();
assert!(rfc9162::verify_inclusion(
    &rfc9162::leaf_hash(b"first record"),
    index as usize,
    reader.size() as usize,
    &proof,
    &rfc9162::hex(&reader.root()),
));

Re-exports§

pub use bloom::Bloom;
pub use checkpoint::Checkpoint;
pub use checkpoint::Cosigner;
pub use checkpoint::Note;
pub use checkpoint::Signer;
pub use checkpoint::Verifier;
pub use error::Error;
pub use error::Result;
pub use index::KeyFn;
pub use index::Manifest;
pub use index::Sidecar;
pub use layout::Layout;
pub use layout::Tile;
pub use log::Reader;
pub use log::TreeState;
pub use log::Writer;
pub use pack::Compacted;
pub use pack::PackStore;
pub use pack::PACK_MAGIC;
pub use pack::PACK_MAGIC_V1;
pub use pack::SHARED_LOCK_WAIT;
pub use store::MemoryStore;
pub use store::PosixStore;
pub use store::TileStore;
pub use tree::Frontier;
pub use tree::Hash;
pub use tree::TileHashReader;

Modules§

base64
RFC 4648 base64 with padding, as notes and checkpoints carry hashes and signatures. Decoding accepts the canonical encoding only: the unused bits of the last symbol are zero and the padding is exactly what the length calls for.
bloom
A split-block Bloom filter: 256-bit blocks, one block per key, one bit in each of the block’s eight 32-bit words. A probe touches one cache line. At 10 bits per key the false-positive rate is about 1 percent.
bundle
Entry bundles, tile/entries/<N>[.p/<W>]: a sequence of big-endian uint16 length-prefixed entries, 256 to a full bundle. Entry i of bundle N hashes to hash i of level-0 tile N.
checkpoint
The C2SP checkpoint (https://c2sp.org/tlog-checkpoint) as a signed note (https://c2sp.org/signed-note), and the witness cosignature (https://c2sp.org/tlog-cosignature) over it.
error
The one error type of the crate.
index
The index beside each sealed bundle, tile/index/<N>, and the manifest over them. Both derive from the bundles: a rebuild from the entries gives the same bytes, so losing them loses nothing.
layout
Tile coordinates, store paths and the widths a tree size gives each level, as C2SP tlog-tiles (https://c2sp.org/tlog-tiles) fixes them.
log
The log on a store: one Writer appends entries, seals bundles, writes tiles and then the tree state; any number of Readers read entries and check them against the tree.
pack
One file for every store path: a packed TileStore, so a log costs a constant number of inodes however long its history.
store
Where tiles live: a trait over store paths, a POSIX directory behind it, and an in-memory store for tests and single-process use.
tree
Hash tiles: how the writer grows them, how a reader checks them, and the root both agree on.