diff --git a/src/scard.rs b/src/scard.rs index 6260f1a..0c76201 100644 --- a/src/scard.rs +++ b/src/scard.rs @@ -27,13 +27,18 @@ pub fn chagne_admin_pin(pw3change: apdus::APDU) -> Result resp.unwrap(), - Err(value) => return Err(value), + Err(value) => { + talktosc::disconnect(card); + return Err(value); + } }; // Verify if the admin pin worked or not. if !resp.is_okay() { + talktosc::disconnect(card); return Err(errors::TalktoSCError::PinError); } + talktosc::disconnect(card); Ok(true) } @@ -86,10 +91,14 @@ pub fn internal_get_version() -> Result, errors::TalktoSCError> { let resp = talktosc::send_and_parse(&card, select_openpgp); let resp = match resp { Ok(_) => resp.unwrap(), - Err(value) => return Err(value), + Err(value) => { + talktosc::disconnect(card); + return Err(value); + } }; // Just make sure we can talk if !resp.is_okay() { + talktosc::disconnect(card); return Err(errors::TalktoSCError::PinError); } // Now let us ask about version @@ -120,10 +129,14 @@ pub fn is_smartcard_connected() -> Result { let resp = talktosc::send_and_parse(&card, select_openpgp); let resp = match resp { Ok(_) => resp.unwrap(), - Err(value) => return Err(value), + Err(value) => { + talktosc::disconnect(card); + return Err(value); + } }; // Verify if the admin pin worked or not. if !resp.is_okay() { + talktosc::disconnect(card); return Err(errors::TalktoSCError::PinError); }