1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// SPDX-License-Identifier: GPL-3.0-or-later
use std::fmt;

#[derive(Debug)]
pub enum FBError {
	/// Unable to decode the given data.
	DecodeError,
	/// The provided key is invalid w.r.t this False Bottom Object.
	InvalidKey,
	/// Keybase length (k) or Cipher length (n) out of bounds.  
	/// Valid bounds: (2 <= k <= n).
	InvalidParams,
}

impl fmt::Display for FBError {

	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		let message = match self {
			FBError::DecodeError => "Invalid input",
			FBError::InvalidKey => "Invalid Key used",
			FBError::InvalidParams => "Keybase len(k) or Cipher len(n) out of bounds. Valid bounds: (2 <= k <= n)",
		};

		f.write_fmt(format_args!("{message}"))
	}
}

impl std::error::Error for FBError {}