wot_network/
lib.rs

1//! Data structures for OpenPGP Web of Trust calculations.
2//!
3//! These data structures model the bare minimum level of detail for Web of Trust calculations.
4//!
5//! A [Network] (the top level WoT object) models a set of [Certification] and [Delegation] edges, which
6//! represent relationships between certificates and their claimed identities.
7//!
8//! The goal of the representation in this crate is to model an absolutely minimal view of a WoT
9//! network. This minimalism keeps the task of correctly *forming* a WoT [Network] graph cleanly
10//! separated from the WoT algorithm that performs searches in the graph:
11//!
12//! All OpenPGP semantics considerations (such as validity, e.g. regarding expiration and
13//! revocation) are normalized out of the `wot-network` representation.
14//! Invalid objects (Certificates, User IDs or Certifications) are simply not rendered in a [Network] view.
15//!
16//! It is the task of a separate "OpenPGP certificate -> [Network]" transformation subsystem to
17//! handle the semantics of OpenPGP artifacts.
18//!
19//! In particular, there is no notion of the passage of time in this WoT [Network] graph
20//! representation. A [Network] represents a snapshot of the Web of Trust relations within a set
21//! of Certificates at a given reference time.
22//!
23//! Searches in a Network are modeled with the [search::WotSearch] trait.
24
25mod edge;
26pub mod id;
27mod network;
28pub mod search;
29mod trust_depth;
30pub mod util;
31
32pub use edge::{Certification, Delegation, Edge};
33pub use id::{CertId, UserId};
34pub use network::Network;
35pub use trust_depth::TrustDepth;
36
37#[derive(Debug, Eq, Hash, PartialEq)]
38pub struct Binding {
39    pub cert: CertId,
40    pub identity: UserId,
41}
42
43/// A regular expression that limits delegation of trust decisions.
44///
45/// See <https://www.rfc-editor.org/rfc/rfc9580.html#section-5.2.3.22> for the regex syntax that
46/// applies and what it applies to.
47///
48/// TODO: Check whether the regex crate supports the same feature set as Henry Spencer's packages.
49#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub struct Regex(String);
51
52impl Regex {
53    pub fn new(regex: String) -> Self {
54        Self(regex)
55    }
56
57    /// Check whether the given [UserId] matches this regular expression.
58    pub fn matches(&self, target_user_id: &UserId) -> bool {
59        let r = regex::RegexBuilder::new(&self.0).build().expect("FIXME");
60        r.is_match(&target_user_id.0)
61    }
62}