diff --git a/openpgp-card/src/apdu/mod.rs b/openpgp-card/src/apdu/mod.rs index d82723b..760ab87 100644 --- a/openpgp-card/src/apdu/mod.rs +++ b/openpgp-card/src/apdu/mod.rs @@ -183,6 +183,14 @@ fn send_command_low_level( } else { let serialized = cmd.serialize(ext)?; + // Can't send this command to the card, because it is too long and + // the card doesn't support command chaining. + if serialized.len() > max_cmd_bytes { + return Err(OpenpgpCardError::CommandTooLong(serialized.len())); + } + + log::debug!(" -> APDU command: {:x?}", &serialized); + let resp = card_client.transmit(&serialized, buf_size)?; log::debug!(" <- APDU response: {:x?}", resp); diff --git a/openpgp-card/src/errors.rs b/openpgp-card/src/errors.rs index 61b7ff4..cd1773b 100644 --- a/openpgp-card/src/errors.rs +++ b/openpgp-card/src/errors.rs @@ -11,6 +11,9 @@ pub enum OpenpgpCardError { #[error("OpenPGP card error status {0}")] OcStatus(OcErrorStatus), + #[error("Command too long ({0} bytes)")] + CommandTooLong(usize), + #[error("Internal error {0}")] InternalError(anyhow::Error), }