Move ResponseLength to OpenpgpCardError

This commit is contained in:
Heiko Schaefer 2021-08-21 15:51:15 +02:00
parent dac30e268e
commit 0e0602f3d5
3 changed files with 8 additions and 9 deletions

View file

@ -157,7 +157,7 @@ fn send_command_low_level(
log::debug!(" <- APDU chunk response: {:x?}", &resp); log::debug!(" <- APDU chunk response: {:x?}", &resp);
if resp.len() < 2 { if resp.len() < 2 {
return Err(OcErrorStatus::ResponseLength(resp.len()).into()); return Err(OpenpgpCardError::ResponseLength(resp.len()));
} }
if !last { if !last {

View file

@ -81,15 +81,15 @@ impl RawResponse {
} }
impl TryFrom<Vec<u8>> for RawResponse { impl TryFrom<Vec<u8>> for RawResponse {
type Error = OcErrorStatus; type Error = OpenpgpCardError;
fn try_from(mut data: Vec<u8>) -> Result<Self, OcErrorStatus> { fn try_from(mut data: Vec<u8>) -> Result<Self, Self::Error> {
let sw2 = data let sw2 = data
.pop() .pop()
.ok_or_else(|| OcErrorStatus::ResponseLength(data.len()))?; .ok_or_else(|| OpenpgpCardError::ResponseLength(data.len()))?;
let sw1 = data let sw1 = data
.pop() .pop()
.ok_or_else(|| OcErrorStatus::ResponseLength(data.len()))?; .ok_or_else(|| OpenpgpCardError::ResponseLength(data.len()))?;
Ok(RawResponse { data, sw1, sw2 }) Ok(RawResponse { data, sw1, sw2 })
} }

View file

@ -24,6 +24,9 @@ pub enum OpenpgpCardError {
#[error("Command too long ({0} bytes)")] #[error("Command too long ({0} bytes)")]
CommandTooLong(usize), CommandTooLong(usize),
#[error("Unexpected response length: {0}")]
ResponseLength(usize),
#[error("Internal error {0}")] #[error("Internal error {0}")]
InternalError(anyhow::Error), InternalError(anyhow::Error),
} }
@ -111,10 +114,6 @@ pub enum OcErrorStatus {
#[error("Unknown OpenPGP card status: [{0}, {1}]")] #[error("Unknown OpenPGP card status: [{0}, {1}]")]
UnknownStatus(u8, u8), 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 { impl From<(u8, u8)> for OcErrorStatus {