pamoja_session/error.rs
1//! The error type for secured sessions.
2
3/// What can go wrong opening a sealed message on a session.
4///
5/// Sealing never fails, so this only describes the receive side. The two cases are
6/// kept distinct on purpose: a forged or corrupted message is an attack or a wire
7/// fault, while a replayed message is a captured-and-resent valid message, and an
8/// operator may want to react to them differently.
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum SessionError {
11 /// The message did not authenticate: its tag does not match, so it was altered
12 /// in flight, was sealed under a different key, or is an outright forgery. The
13 /// plaintext is never revealed in this case.
14 Inauthentic,
15 /// The message's counter has already been seen, or is older than the replay
16 /// window still tracks, so it is a replay of a message already accepted (or one
17 /// too old to prove is not). It is rejected without revealing the plaintext.
18 Replayed,
19}
20
21impl core::fmt::Display for SessionError {
22 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23 match self {
24 SessionError::Inauthentic => f.write_str("session message failed authentication"),
25 SessionError::Replayed => f.write_str("session message is a replay"),
26 }
27 }
28}
29
30// `core::error::Error` rather than `std::error::Error`, so a caller on a
31// microcontroller gets the same trait a caller on a gateway does.
32impl core::error::Error for SessionError {}