Skip to content

Commit

Permalink
Adds better card disconnection on error
Browse files Browse the repository at this point in the history
  • Loading branch information
kushaldas committed Nov 8, 2022
1 parent 2c97369 commit 521fe6f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/scard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ pub fn chagne_admin_pin(pw3change: apdus::APDU) -> Result<bool, errors::TalktoSC
let resp = talktosc::send_and_parse(&card, pw3change);
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);
}
talktosc::disconnect(card);
Ok(true)
}

Expand Down Expand Up @@ -86,10 +91,14 @@ pub fn internal_get_version() -> Result<Vec<u8>, 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
Expand Down Expand Up @@ -120,10 +129,14 @@ pub fn is_smartcard_connected() -> Result<bool, 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);
}
};
// Verify if the admin pin worked or not.
if !resp.is_okay() {
talktosc::disconnect(card);
return Err(errors::TalktoSCError::PinError);
}

Expand Down

0 comments on commit 521fe6f

Please sign in to comment.