1use core::fmt;
2use std::io;
3
4#[derive(Debug)]
7#[non_exhaustive]
8pub enum Error {
9 InvalidId,
11 WeakDigest,
13 UnknownDigest(String),
15 Material,
17 NotWaiting,
19 AlreadyAccepted,
21 NotAccepted,
23 NoSuccessor,
25 SuccessorTaken,
27 NotProven,
29 NotInvited,
31 Expired,
33 InvalidOptions,
36 InvalidCode,
38 Random,
40 Io(io::Error),
42}
43
44impl fmt::Display for Error {
45 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 Self::InvalidId => formatter.write_str("peer id is invalid"),
48 Self::WeakDigest => {
49 formatter.write_str("peer id is an MD5 digest, which is not supported")
50 }
51 Self::UnknownDigest(_) => {
52 formatter.write_str("unknown digest name; supported: sha256, sha384, sha512, sha1")
53 }
54 Self::Material => formatter.write_str("key material is invalid"),
55 Self::NotWaiting => formatter.write_str("peer is not waiting for acceptance"),
56 Self::AlreadyAccepted => formatter.write_str("peer is already accepted"),
57 Self::NotAccepted => formatter.write_str("peer is not accepted or is retiring"),
58 Self::NoSuccessor => formatter.write_str("key is not a pending successor"),
59 Self::NotProven => formatter.write_str("nobody proved the successor's key"),
60 Self::SuccessorTaken => {
61 formatter.write_str("key is the pending successor of another accepted key")
62 }
63 Self::NotInvited => formatter.write_str("no open invitation has this secret"),
64 Self::Expired => formatter.write_str("invitation or code expired"),
65 Self::InvalidOptions => formatter.write_str("an option has no meaning"),
66 Self::InvalidCode => formatter.write_str("code does not fit its alphabet"),
67 Self::Random => formatter.write_str("random source failed"),
68 Self::Io(_) => formatter.write_str("storage or stream operation failed"),
69 }
70 }
71}
72
73impl core::error::Error for Error {
74 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
75 match self {
76 Self::Io(error) => Some(error),
77 _ => None,
78 }
79 }
80}