1use std::path::PathBuf;
3
4#[derive(Debug, thiserror::Error)]
5pub enum KeysError {
6 #[error("crypto error: {0}")]
7 Crypto(String),
8 #[error("could not unlock: {0}")]
10 Unlock(String),
11 #[error("invalid {what}: {msg}")]
12 Invalid { what: &'static str, msg: String },
13 #[error("keys are not initialized in {0}")]
15 NotInitialized(PathBuf),
16 #[error(transparent)]
17 Io(#[from] std::io::Error),
18 #[error("toml: {0}")]
19 TomlDe(#[from] toml::de::Error),
20 #[error("toml: {0}")]
21 TomlSer(#[from] toml::ser::Error),
22 #[error(transparent)]
23 Json(#[from] serde_json::Error),
24}
25
26impl KeysError {
27 pub fn invalid(what: &'static str, msg: impl Into<String>) -> Self {
28 KeysError::Invalid { what, msg: msg.into() }
29 }
30 pub(crate) fn crypto(msg: impl Into<String>) -> Self {
31 KeysError::Crypto(msg.into())
32 }
33}
34
35pub type Result<T> = std::result::Result<T, KeysError>;