Skip to content

Commit 2a8724c

Browse files
Draft some documentation in the policy module
1 parent 99881e4 commit 2a8724c

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

src/policy/mod.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,76 @@
1+
//! Trust policies for tree-head verification.
2+
//!
3+
//! A [`Policy`] defines which logs and witnesses are trusted, and what quorum of
4+
//! witness cosignatures is required for a signed tree head to be considered valid.
5+
//!
6+
//! For details about the policy file syntax and semantics, see the
7+
//! [sigsum-go policy documentation](https://git.glasklar.is/sigsum/core/sigsum-go/-/blob/main/doc/policy.md).
8+
//!
9+
//! For information about the built-in policies, see the
10+
//! [procedure for maintenance of Sigsum builtin named trust policies](https://git.glasklar.is/sigsum/project/documentation/-/blob/main/policy-maintenance.md).
11+
//!
12+
//! # Creating a Policy
13+
//!
14+
//! This module offers three ways to create a [`Policy`]:
15+
//!
16+
//! ## Built-in Policies
17+
//!
18+
//! This crate includes several built-in policies that can be used directly. They are
19+
//! available as statics in this module, or can be looked up by name at runtime:
20+
//!
21+
//! ```
22+
//! use sigsum::policy::{Policy, SIGSUM_GENERIC_2025_1};
23+
//!
24+
//! // Use the static directly
25+
//! let policy = SIGSUM_GENERIC_2025_1;
26+
//!
27+
//! // Or look up by name at runtime
28+
//! let policy = Policy::builtin("sigsum-generic-2025-1").unwrap();
29+
//! ```
30+
//!
31+
//! ## Parsing a Policy File
32+
//!
33+
//! Policies can be parsed from their text representation using [`Policy::parse`]:
34+
//!
35+
//! ```
36+
//! use sigsum::policy::Policy;
37+
//!
38+
//! let policy_text = "\
39+
//! log 4644af2abd40f4895a003bca350f9d5912ab301a49c77f13e5b6d905c20a5fe6
40+
//! witness mywitness 4a921b7caef58ae670cdc11ef4184f1c058f7b9259a9107a969f69fa54aa496f
41+
//! quorum mywitness
42+
//! ";
43+
//!
44+
//! let policy = Policy::parse(policy_text).unwrap();
45+
//! ```
46+
//!
47+
//! ## Using PolicyBuilder
48+
//!
49+
//! For programmatic construction, use [`PolicyBuilder`]:
50+
//!
51+
//! ```
52+
//! use sigsum::policy::PolicyBuilder;
53+
//! use hex_literal::hex;
54+
//!
55+
//! let mut builder = PolicyBuilder::new();
56+
//! builder
57+
//! .add_log(
58+
//! hex!("4644af2abd40f4895a003bca350f9d5912ab301a49c77f13e5b6d905c20a5fe6").into(),
59+
//! Some("https://log.example.org".into()),
60+
//! )
61+
//! .unwrap()
62+
//! .add_witness(
63+
//! "mywitness".into(),
64+
//! hex!("4a921b7caef58ae670cdc11ef4184f1c058f7b9259a9107a969f69fa54aa496f").into(),
65+
//! None,
66+
//! )
67+
//! .unwrap()
68+
//! .set_quorum("mywitness".into())
69+
//! .unwrap();
70+
//!
71+
//! let policy = builder.build();
72+
//! ```
73+
174
use std::collections::HashMap;
275

376
use crate::crypto::{Hash, PublicKey};

0 commit comments

Comments
 (0)