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
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#[derive(Debug, snafu::Snafu)]
#[snafu(visibility = "pub")]
pub enum Error {
    #[snafu(display("failed to create block mode decryptor: {}", source))]
    CreateBlockMode {
        source: block_modes::InvalidKeyIvLength,
    },

    #[snafu(display("failed to create directory: {}", source))]
    CreateDirectory { source: std::io::Error },

    #[snafu(display("failed to decrypt: {}", source))]
    Decrypt { source: block_modes::BlockModeError },

    #[snafu(display("failed to parse pinentry output ({:?})", out))]
    FailedToParsePinentry { out: String },

    #[snafu(display(
        "failed to run editor {}: {:?}",
        editor.to_string_lossy(),
        res
    ))]
    FailedToRunEditor {
        editor: std::path::PathBuf,
        res: std::process::ExitStatus,
    },

    #[snafu(display("failed to expand with hkdf"))]
    HkdfExpand,

    #[snafu(display("username or password incorrect"))]
    IncorrectPassword,

    #[snafu(display("invalid base64: {}", source))]
    InvalidBase64 { source: base64::DecodeError },

    #[snafu(display("invalid cipherstring"))]
    InvalidCipherString,

    #[snafu(display("invalid value for $EDITOR: {}", editor.to_string_lossy()))]
    InvalidEditor { editor: std::ffi::OsString },

    #[snafu(display("invalid mac"))]
    InvalidMac,

    #[snafu(display("failed to load config: {}", source))]
    LoadConfig { source: std::io::Error },

    #[snafu(display("failed to load config: {}", source))]
    LoadConfigAsync { source: tokio::io::Error },

    #[snafu(display("failed to load config: {}", source))]
    LoadConfigJson { source: serde_json::Error },

    #[snafu(display("failed to load db: {}", source))]
    LoadDb { source: std::io::Error },

    #[snafu(display("failed to load db: {}", source))]
    LoadDbAsync { source: tokio::io::Error },

    #[snafu(display("failed to load db: {}", source))]
    LoadDbJson { source: serde_json::Error },

    #[snafu(display("openssl error: {}", source))]
    OpenSSL { source: openssl::error::ErrorStack },

    #[snafu(display("pbkdf2 requires at least 1 iteration (got 0)"))]
    Pbkdf2ZeroIterations,

    #[snafu(display("pinentry cancelled"))]
    PinentryCancelled,

    #[snafu(display("pinentry error: {}", error))]
    PinentryErrorMessage { error: String },

    #[snafu(display("error reading pinentry output: {}", source))]
    PinentryReadOutput { source: tokio::io::Error },

    #[snafu(display("error waiting for pinentry to exit: {}", source))]
    PinentryWait { source: tokio::io::Error },

    #[snafu(display("failed to remove db: {}", source))]
    RemoveDb { source: std::io::Error },

    #[snafu(display("api request returned error: {}", status))]
    RequestFailed { status: u16 },

    #[snafu(display("api request unauthorized"))]
    RequestUnauthorized,

    #[snafu(display("error making api request: {}", source))]
    Reqwest { source: reqwest::Error },

    #[snafu(display("failed to save config: {}", source))]
    SaveConfig { source: std::io::Error },

    #[snafu(display("failed to save config: {}", source))]
    SaveConfigJson { source: serde_json::Error },

    #[snafu(display("failed to save db: {}", source))]
    SaveDb { source: std::io::Error },

    #[snafu(display("failed to save db: {}", source))]
    SaveDbAsync { source: tokio::io::Error },

    #[snafu(display("failed to save db: {}", source))]
    SaveDbJson { source: serde_json::Error },

    #[snafu(display("error spawning pinentry: {}", source))]
    Spawn { source: tokio::io::Error },

    #[snafu(display("error writing to pinentry stdin: {}", source))]
    WriteStdin { source: tokio::io::Error },
}

pub type Result<T> = std::result::Result<T, Error>;