diff --git a/openpgp-card/src/apdu/mod.rs b/openpgp-card/src/apdu/mod.rs index 7bdfbe4..f7586e9 100644 --- a/openpgp-card/src/apdu/mod.rs +++ b/openpgp-card/src/apdu/mod.rs @@ -157,7 +157,7 @@ fn send_command_low_level( log::debug!(" <- APDU chunk response: {:x?}", &resp); if resp.len() < 2 { - return Err(OcErrorStatus::ResponseLength(resp.len()).into()); + return Err(OpenpgpCardError::ResponseLength(resp.len())); } if !last { diff --git a/openpgp-card/src/apdu/response.rs b/openpgp-card/src/apdu/response.rs index f85fb78..5de13f0 100644 --- a/openpgp-card/src/apdu/response.rs +++ b/openpgp-card/src/apdu/response.rs @@ -81,15 +81,15 @@ impl RawResponse { } impl TryFrom> for RawResponse { - type Error = OcErrorStatus; + type Error = OpenpgpCardError; - fn try_from(mut data: Vec) -> Result { + fn try_from(mut data: Vec) -> Result { let sw2 = data .pop() - .ok_or_else(|| OcErrorStatus::ResponseLength(data.len()))?; + .ok_or_else(|| OpenpgpCardError::ResponseLength(data.len()))?; let sw1 = data .pop() - .ok_or_else(|| OcErrorStatus::ResponseLength(data.len()))?; + .ok_or_else(|| OpenpgpCardError::ResponseLength(data.len()))?; Ok(RawResponse { data, sw1, sw2 }) } diff --git a/openpgp-card/src/errors.rs b/openpgp-card/src/errors.rs index e4313f4..5ed6141 100644 --- a/openpgp-card/src/errors.rs +++ b/openpgp-card/src/errors.rs @@ -24,6 +24,9 @@ pub enum OpenpgpCardError { #[error("Command too long ({0} bytes)")] CommandTooLong(usize), + #[error("Unexpected response length: {0}")] + ResponseLength(usize), + #[error("Internal error {0}")] InternalError(anyhow::Error), } @@ -111,10 +114,6 @@ pub enum OcErrorStatus { #[error("Unknown OpenPGP card status: [{0}, {1}]")] UnknownStatus(u8, u8), - - /// This code is not an OpenPGP card status value - #[error("Unexpected response length: {0}")] - ResponseLength(usize), } impl From<(u8, u8)> for OcErrorStatus {