diff --git a/openpgp-card/src/apdu.rs b/openpgp-card/src/apdu.rs index 569481c..7f9dec0 100644 --- a/openpgp-card/src/apdu.rs +++ b/openpgp-card/src/apdu.rs @@ -101,7 +101,7 @@ fn send_command_low_level( where C: CardTransaction + ?Sized, { - let (ext_support, chaining_support, mut max_cmd_bytes, max_rsp_bytes) = + let (ext_support, chaining_support, max_cmd_bytes, max_rsp_bytes) = if let Some(caps) = card_caps { log::trace!("found card caps data!"); @@ -118,15 +118,6 @@ where (false, false, 255, 255) }; - // If the CardTransaction implementation has an inherent limit for the cmd - // size, take that limit into account. - // (E.g. when using scdaemon as a CardTransaction backend, there is a - // limitation to 1000 bytes length for Assuan commands, which - // translates to maximum command length of a bit under 500 bytes) - if let Some(max_card_cmd_bytes) = card_tx.max_cmd_len() { - max_cmd_bytes = usize::min(max_cmd_bytes, max_card_cmd_bytes); - } - log::trace!( "ext le/lc {}, chaining {}, max cmd {}, max rsp {}", ext_support, diff --git a/openpgp-card/src/lib.rs b/openpgp-card/src/lib.rs index 77a0607..807fb0c 100644 --- a/openpgp-card/src/lib.rs +++ b/openpgp-card/src/lib.rs @@ -180,6 +180,21 @@ impl Card { let pw1_max = pw_status.pw1_max_len(); let pw3_max = pw_status.pw3_max_len(); + // If the CardTransaction implementation has an inherent limit for the cmd + // size, take that limit into account. + // (E.g. when using scdaemon as a CardTransaction backend, there is a + // limitation to 1000 bytes length for Assuan commands, which + // translates to maximum command length of a bit under 500 bytes) + if let Some(max_card_cmd_bytes) = tx.tx.max_cmd_len() { + max_cmd_bytes = u16::min(max_cmd_bytes, max_card_cmd_bytes as u16); + } + + // FIXME: add a more general mechanism to ask the backend for + // amendments to the CardCaps (e.g. to change support for + // "extended length") + // + // Also see https://blog.apdu.fr/posts/2011/05/extended-apdu-status-per-reader/ + let caps = CardCaps::new( ext_support, chaining_support,