holochain_integrity_types/countersigning/
error.rs

1use crate::Role;
2
3/// Errors related to the secure primitive macro.
4#[derive(Debug, PartialEq, Eq)]
5pub enum CounterSigningError {
6    /// Agent index is out of bounds for the signing session.
7    AgentIndexOutOfBounds,
8    /// An empty vector was used to build session data.
9    MissingResponse,
10    /// Session responses needs to be same length as the signing agents.
11    CounterSigningSessionResponsesLength(usize, usize),
12    /// Session response agents all need to be in the correct positions.
13    CounterSigningSessionResponsesOrder(u8, usize),
14    /// Enzyme must match for required and optional signers if set.
15    EnzymeMismatch(
16        Option<(holo_hash::AgentPubKey, Vec<Role>)>,
17        Option<(holo_hash::AgentPubKey, Vec<Role>)>,
18    ),
19    /// If there are optional signers the session MUST be enzymatic.
20    NonEnzymaticOptionalSigners,
21    /// Agents length cannot be longer than max or less than min.
22    AgentsLength(usize),
23    /// Optional agents length cannot be shorter then minimum.
24    OptionalAgentsLength(u8, usize),
25    /// Optional agents length must be majority of the signers list.
26    MinOptionalAgents(u8, usize),
27    /// There cannot be duplicates in the agents list.
28    AgentsDupes(Vec<holo_hash::AgentPubKey>),
29    /// The session times must validate.
30    CounterSigningSessionTimes(crate::CounterSigningSessionTimes),
31}
32
33impl std::error::Error for CounterSigningError {}
34
35impl core::fmt::Display for CounterSigningError {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        match self {
38            CounterSigningError::AgentIndexOutOfBounds => {
39                write!(f, "Agent index is out of bounds for the signing session.")
40            }
41            CounterSigningError::MissingResponse => write!(
42                f,
43                "Attempted to build CounterSigningSessionData with an empty response vector."
44            ),
45            CounterSigningError::CounterSigningSessionResponsesLength(resp, num_agents) => {
46                write!(f,
47                    "The countersigning session responses ({}) did not match the number of signing agents ({})",
48                    resp,
49                    num_agents
50                )
51            }
52            CounterSigningError::CounterSigningSessionResponsesOrder(index, pos) => write!(f,
53                    "The countersigning session response with agent index {} was found in index position {}",
54                    index, pos
55            ),
56            CounterSigningError::EnzymeMismatch(required_signer, optional_signer) => write!(f,
57                "The enzyme is mismatche for required signer {:?} and optional signer {:?}",
58                required_signer, optional_signer
59
60            ),
61            CounterSigningError::NonEnzymaticOptionalSigners => write!(f, "There are optional signers without an enzyme."),
62            CounterSigningError::AgentsLength(len) => {
63                write!(f, "The signing agents list is too long or short {}", len)
64            },
65            CounterSigningError::OptionalAgentsLength(min, len) => {
66                write!(f, "The optional signing agents list length is {} which is less than the minimum {} required to sign", len, min)
67            },
68            CounterSigningError::MinOptionalAgents(min, len) => {
69                write!(f, "The minimum optional agents {} is not a majority of {}", min, len)
70            },
71            CounterSigningError::AgentsDupes(agents) => write!(
72                f,
73                "The signing agents list contains duplicates {:?}",
74                agents
75            ),
76            CounterSigningError::CounterSigningSessionTimes(times) => write!(
77                f,
78                "The countersigning session times were not valid {:?}",
79                times
80            ),
81        }
82    }
83}