Skip to content

Commit a48e1d1

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

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`] specifies of a set of logs, a set of witnesses, and what quorum of
4+
//! witness cosignatures is required for a signed tree head to be considered valid.
5+
//!
6+
//! For more details about sigsum policies and the policy file syntax, see the
7+
//! [sigsum-go policy documentation](https://git.glasklar.is/sigsum/core/sigsum-go/-/blob/main/doc/policy.md).
8+
//!
9+
//! ## Creating a Policy
10+
//!
11+
//! This module offers three ways to create a [`Policy`]:
12+
//!
13+
//! ### Built-in Policies
14+
//!
15+
//! The crate includes several built-in policies that can be used directly. They are
16+
//! available as statics in this module, or can be looked up by name at runtime:
17+
//!
18+
//! ```
19+
//! use sigsum::policy::{Policy, SIGSUM_GENERIC_2025_1};
20+
//!
21+
//! // Use the static directly
22+
//! let policy = &SIGSUM_GENERIC_2025_1;
23+
//!
24+
//! // Or look up by name at runtime
25+
//! let policy = Policy::builtin("sigsum-generic-2025-1").unwrap();
26+
//! ```
27+
//!
28+
//! For more information about the built-in policies, see the
29+
//! [procedure for maintenance of Sigsum builtin named trust policies](https://git.glasklar.is/sigsum/project/documentation/-/blob/main/policy-maintenance.md).
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 https://log.example.org
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)