Skip to content

Commit 242f091

Browse files
Add some documentation in the policy module
1 parent 99881e4 commit 242f091

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

src/policy/mod.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
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 built-in policies, see
29+
//! [named policies for Sigsum](https://www.glasklarteknik.se/post/named-policies-for-sigsum/)
30+
//! and [procedure for maintenance of Sigsum builtin named trust policies](https://git.glasklar.is/sigsum/project/documentation/-/blob/main/policy-maintenance.md).
31+
//!
32+
//! ### Parsing a Policy File
33+
//!
34+
//! Policies can be parsed from their text representation using [`Policy::parse`]:
35+
//!
36+
//! ```
37+
//! use sigsum::policy::Policy;
38+
//!
39+
//! let policy_text = "\
40+
//! log 4644af2abd40f4895a003bca350f9d5912ab301a49c77f13e5b6d905c20a5fe6 https://log.example.org
41+
//! witness mywitness 4a921b7caef58ae670cdc11ef4184f1c058f7b9259a9107a969f69fa54aa496f
42+
//! quorum mywitness
43+
//! ";
44+
//!
45+
//! let policy = Policy::parse(policy_text).unwrap();
46+
//! ```
47+
//!
48+
//! ### Using PolicyBuilder
49+
//!
50+
//! For programmatic construction, use [`PolicyBuilder`]:
51+
//!
52+
//! ```
53+
//! use sigsum::policy::PolicyBuilder;
54+
//! use hex_literal::hex;
55+
//!
56+
//! let mut builder = PolicyBuilder::new();
57+
//! builder
58+
//! .add_log(
59+
//! hex!("4644af2abd40f4895a003bca350f9d5912ab301a49c77f13e5b6d905c20a5fe6").into(),
60+
//! Some("https://log.example.org".into()),
61+
//! )
62+
//! .unwrap()
63+
//! .add_witness(
64+
//! "mywitness".into(),
65+
//! hex!("4a921b7caef58ae670cdc11ef4184f1c058f7b9259a9107a969f69fa54aa496f").into(),
66+
//! None,
67+
//! )
68+
//! .unwrap()
69+
//! .set_quorum("mywitness".into())
70+
//! .unwrap();
71+
//!
72+
//! let policy = builder.build();
73+
//! ```
74+
175
use std::collections::HashMap;
276

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

0 commit comments

Comments
 (0)