assigned exit codes to error cases

This commit is contained in:
shimun 2019-10-12 22:46:20 +02:00
parent 9a8ea993b5
commit 2bac911b32
Signed by: shimun
GPG Key ID: E81D8382DC2F971B
2 changed files with 24 additions and 1 deletions

View File

@ -23,6 +23,19 @@ pub enum Fido2LuksError {
StringEncodingError { cause: FromUtf8Error }, StringEncodingError { cause: FromUtf8Error },
} }
impl Fido2LuksError {
pub fn exit_code(&self) -> i32 {
use Fido2LuksError::*;
match self {
AskPassError { .. } | KeyfileError { .. } => 2,
AuthenticatorError { .. } => 3,
NoAuthenticatorError => 4,
WrongSecret => 5,
_ => 1,
}
}
}
#[derive(Debug, Fail)] #[derive(Debug, Fail)]
pub enum AskPassError { pub enum AskPassError {
#[fail(display = "unable to retrieve password: {}", _0)] #[fail(display = "unable to retrieve password: {}", _0)]

View File

@ -11,6 +11,7 @@ use ring::digest;
use std::io::{self}; use std::io::{self};
use std::path::PathBuf; use std::path::PathBuf;
use std::process::exit;
mod cli; mod cli;
mod config; mod config;
@ -34,7 +35,16 @@ fn assemble_secret(hmac_result: &[u8], salt: &[u8]) -> [u8; 32] {
} }
fn main() -> Fido2LuksResult<()> { fn main() -> Fido2LuksResult<()> {
run_cli() match run_cli() {
Err(e) => {
#[cfg(debug_assertions)]
eprintln!("{:?}", e);
#[cfg(not(debug_assertions))]
eprintln!("{}", e);
exit(e.exit_code())
}
_ => exit(0),
}
} }
#[cfg(test)] #[cfg(test)]