workflow_encryption/
error.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum Error {
5 #[error("{0}")]
6 Custom(String),
7
8 #[error(transparent)]
9 Io(#[from] std::io::Error),
10
11 #[error(transparent)]
17 Utf8Error(#[from] std::str::Utf8Error),
18
19 #[error("Unable to decrypt")]
22 Chacha20poly1305(chacha20poly1305::Error),
23
24 #[error("(Argon2) {0}")]
25 Argon2(argon2::Error),
26
27 #[error("(Argon2::password_hash) {0}")]
28 Argon2ph(argon2::password_hash::Error),
29
30 #[error("Decryption failed (invalid data length)")]
31 DecryptionDataLength,
32}
33
34impl From<String> for Error {
35 fn from(s: String) -> Self {
36 Error::Custom(s)
37 }
38}
39
40impl From<&str> for Error {
41 fn from(s: &str) -> Self {
42 Error::Custom(s.to_string())
43 }
44}
45
46impl Error {
47 pub fn custom<T: std::fmt::Display>(msg: T) -> Self {
48 Error::Custom(msg.to_string())
49 }
50}
51
52impl From<argon2::Error> for Error {
53 fn from(err: argon2::Error) -> Self {
54 Self::Argon2(err)
55 }
56}
57
58impl From<argon2::password_hash::Error> for Error {
59 fn from(err: argon2::password_hash::Error) -> Self {
60 Self::Argon2ph(err)
61 }
62}
63
64impl From<chacha20poly1305::Error> for Error {
65 fn from(err: chacha20poly1305::Error) -> Self {
66 Self::Chacha20poly1305(err)
67 }
68}