From 0f157082bb75d08ad4fd9bfd1cdf6646fb374c3f Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Tue, 8 Jan 2019 19:45:45 -0800 Subject: Make three more error codes known Three more error codes are defined in libnitrokey but currently reported as the CommandError::Unknown variant: 200: representing a string that exceeds a limit 202: indicating a string that is not in hexadecimal format when it should be 203: suggesting that the target buffer is smaller than the source buffer and, hence, too small This change introduces the CommandError variants StringTooLong, InvalidHexString and TargetBufferTooSmall, respectively, representing those errors. --- CHANGELOG.md | 4 ++++ src/util.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f79111e..9f096b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Unreleased +- Make three additional error codes known: `CommandError::StringTooLong`, + `CommandError::InvalidHexString` and `CommandError::TargetBufferTooSmall`. + # v0.3.1 (2019-01-07) - Use `nitrokey-test` to select and execute the unit tests. - Add support for the hidden volumes on a Nitrokey Storage diff --git a/src/util.rs b/src/util.rs index 1ecc0b7..cb109d0 100644 --- a/src/util.rs +++ b/src/util.rs @@ -36,8 +36,14 @@ pub enum CommandError { Undefined, /// You passed a string containing a null byte. InvalidString, + /// A supplied string exceeded a length limit. + StringTooLong, /// You passed an invalid slot. InvalidSlot, + /// The supplied string was not in hexadecimal format. + InvalidHexString, + /// The target buffer was smaller than the source. + TargetBufferTooSmall, } /// Log level for libnitrokey. @@ -134,7 +140,12 @@ impl CommandError { } CommandError::Undefined => "An unspecified error occurred".into(), CommandError::InvalidString => "You passed a string containing a null byte".into(), + CommandError::StringTooLong => "The supplied string is too long".into(), CommandError::InvalidSlot => "The given slot is invalid".into(), + CommandError::InvalidHexString => { + "The supplied string is not in hexadecimal format".into() + } + CommandError::TargetBufferTooSmall => "The target buffer is too small".into(), } } } @@ -158,7 +169,10 @@ impl From for CommandError { 8 => CommandError::NotSupported, 9 => CommandError::UnknownCommand, 10 => CommandError::AesDecryptionFailed, + 200 => CommandError::StringTooLong, 201 => CommandError::InvalidSlot, + 202 => CommandError::InvalidHexString, + 203 => CommandError::TargetBufferTooSmall, x => CommandError::Unknown(x.into()), } } -- cgit v1.2.1