aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-17 13:28:03 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-20 21:08:52 +0000
commit391cfd03edafd6e857d6cdbee1347f38e7a02b3f (patch)
tree23f16b1c6da4540144f0c8ffc6f4c8ccee1508d9 /src
parent27138c4b799248d2d39e9681337a620c89636557 (diff)
downloadnitrokey-rs-391cfd03edafd6e857d6cdbee1347f38e7a02b3f.tar.gz
nitrokey-rs-391cfd03edafd6e857d6cdbee1347f38e7a02b3f.tar.bz2
Remove CommandError::as_str method
AsStr is automatically implementeded if Display is implemented, so having a manual as_str() method is not necessary.
Diffstat (limited to 'src')
-rw-r--r--src/error.rs40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/error.rs b/src/error.rs
index a2b3848..1aaf21f 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,4 +1,3 @@
-use std::borrow;
use std::error;
use std::fmt;
use std::os::raw;
@@ -128,35 +127,28 @@ impl CommandError {
_ => None,
}
}
-
- fn as_str(&self) -> borrow::Cow<'static, str> {
- match *self {
- CommandError::WrongCrc => {
- "A packet with a wrong checksum has been sent or received".into()
- }
- CommandError::WrongSlot => "The given OTP slot does not exist".into(),
- CommandError::SlotNotProgrammed => "The given OTP slot is not programmed".into(),
- CommandError::WrongPassword => "The given password is wrong".into(),
- CommandError::NotAuthorized => {
- "You are not authorized for this command or provided a wrong temporary \
- password"
- .into()
- }
- CommandError::Timestamp => "An error occurred when getting or setting the time".into(),
- CommandError::NoName => "You did not provide a name for the OTP slot".into(),
- CommandError::NotSupported => "This command is not supported by this device".into(),
- CommandError::UnknownCommand => "This command is unknown".into(),
- CommandError::AesDecryptionFailed => "AES decryption failed".into(),
- CommandError::Undefined => "An unspecified error occurred".into(),
- }
- }
}
impl error::Error for CommandError {}
impl fmt::Display for CommandError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{}", self.as_str())
+ f.write_str(match *self {
+ CommandError::WrongCrc => "A packet with a wrong checksum has been sent or received",
+ CommandError::WrongSlot => "The given OTP slot does not exist",
+ CommandError::SlotNotProgrammed => "The given OTP slot is not programmed",
+ CommandError::WrongPassword => "The given password is wrong",
+ CommandError::NotAuthorized => {
+ "You are not authorized for this command or provided a wrong temporary \
+ password"
+ }
+ CommandError::Timestamp => "An error occurred when getting or setting the time",
+ CommandError::NoName => "You did not provide a name for the OTP slot",
+ CommandError::NotSupported => "This command is not supported by this device",
+ CommandError::UnknownCommand => "This command is unknown",
+ CommandError::AesDecryptionFailed => "AES decryption failed",
+ CommandError::Undefined => "An unspecified error occurred",
+ })
}
}