handle wrongpukerror

This commit is contained in:
Michele Balistreri 2021-10-22 12:57:53 +03:00
parent a7c15e6c91
commit 19d8b0b3a1
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
2 changed files with 6 additions and 4 deletions

View File

@ -173,7 +173,7 @@ func (f *KeycardFlow) unblockPIN(kc *keycardContext) error {
return nil
} else if isSCardError(err) {
return restartErr()
} else if leftRetries, ok := getPinRetries(err); ok {
} else if leftRetries, ok := getRetries(err); ok {
f.cardInfo.pukRetries = leftRetries
delete(f.params, PUK)
pukOK = false
@ -199,7 +199,7 @@ func (f *KeycardFlow) authenticate(kc *keycardContext) error {
if f.cardInfo.pukRetries == 0 {
return f.pauseAndRestart(SwapCard, PUKRetries)
} else if f.cardInfo.pinRetries == 0 {
// succesful PUK unblock leaves the card authenticated
// succesful unblock leaves the card authenticated
return f.unblockPIN(kc)
}
@ -213,7 +213,7 @@ func (f *KeycardFlow) authenticate(kc *keycardContext) error {
return nil
} else if isSCardError(err) {
return restartErr()
} else if leftRetries, ok := getPinRetries(err); ok {
} else if leftRetries, ok := getRetries(err); ok {
f.cardInfo.pinRetries = leftRetries
delete(f.params, PIN)
}

View File

@ -33,9 +33,11 @@ func isSCardError(err error) bool {
return ok
}
func getPinRetries(err error) (int, bool) {
func getRetries(err error) (int, bool) {
if wrongPIN, ok := err.(*keycard.WrongPINError); ok {
return wrongPIN.RemainingAttempts, ok
} else if wrongPUK, ok := err.(*keycard.WrongPUKError); ok {
return wrongPUK.RemainingAttempts, ok
} else {
return 0, false
}