use crypto::symmetriccipher;
use dbus;
use std::error;
use std::fmt;
pub type Result<T> = ::std::result::Result<T, SsError>;
#[derive(Debug)]
pub enum SsError {
Crypto(symmetriccipher::SymmetricCipherError),
Dbus(dbus::Error),
Locked,
NoResult,
Parse,
Prompt,
}
impl fmt::Display for SsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt:: Result {
match *self {
SsError::Crypto(_) => write!(f, "Crypto error: Invalid Length or Padding"),
SsError::Dbus(ref err) => write!(f, "Dbus error: {}", err),
SsError::Locked => write!(f, "SS Error: object locked"),
SsError::NoResult => write!(f, "SS error: result not returned from SS API"),
SsError::Parse => write!(f, "SS error: could not parse Dbus output"),
SsError::Prompt => write!(f, "SS error: prompt dismissed"),
}
}
}
impl error::Error for SsError {
fn description(&self) -> &str {
match *self {
SsError::Crypto(_) => "crypto: Invalid Length or Padding",
SsError::Dbus(ref err) => err.description(),
SsError::Locked => "Object locked",
SsError::NoResult => "Result not returned from SS API",
SsError::Parse => "Error parsing Dbus output",
SsError::Prompt => "Prompt Dismissed",
}
}
fn cause(&self) -> Option<&error::Error> {
match *self {
SsError::Dbus(ref err) => Some(err),
_ => None,
}
}
}
impl From<symmetriccipher::SymmetricCipherError> for SsError {
fn from(err: symmetriccipher::SymmetricCipherError) -> SsError {
SsError::Crypto(err)
}
}
impl From<dbus::Error> for SsError {
fn from(err: dbus::Error) -> SsError {
SsError::Dbus(err)
}
}