false_bottom/
fberror.rs

1// SPDX-License-Identifier: GPL-3.0-or-later
2use std::fmt;
3
4/// Enum representing all the possible errors in this crate.
5#[derive(Debug)]
6pub enum FbError {
7	/// Unable to decode the given data.
8	DecodeError,
9	
10	/// The provided key is invalid w.r.t this False Bottom Object.
11	InvalidKey,
12	
13	/// One or more of the parameters are invalid.  
14	/// Valid bounds: (2 <= keybase_len <= cipher_len).
15	InvalidParams,
16}
17
18impl fmt::Display for FbError {
19
20	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21		let message = match self {
22			FbError::DecodeError => "Invalid input",
23			FbError::InvalidKey => "Invalid Key used",
24			FbError::InvalidParams => "One or more of the parameters are invalid or out of bounds.   Valid bounds: (2 <= keybase_len <= cipher_len)",
25		};
26
27		f.write_fmt(format_args!("{message}"))
28	}
29}
30
31impl std::error::Error for FbError {}