Skip to content

Commit 2f9f708

Browse files
committed
fix(otp): Handle case when last slot is deleted
Fixes #182
1 parent 420b079 commit 2f9f708

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Yubico.YubiKey/src/Yubico/YubiKey/Pipelines/OtpErrorTransform.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,20 @@ public ResponseApdu Invoke(CommandApdu command, Type commandType, Type responseT
6262

6363
// If we see the sequence number change, we can assume that the configuration was applied successfully. Otherwise
6464
// we just invent an error in the response.
65-
return afterSequence != expectedSequence
66-
? new ResponseApdu(responseApdu.Data.ToArray(), SWConstants.WarningNvmUnchanged)
67-
: responseApdu;
65+
// Note that when deleting the "last" slot so no slots are valid, the programming sequence
66+
// is set to 0, which is also valid.
67+
return afterSequence == expectedSequence || afterSequence == 0
68+
? responseApdu
69+
: FailedApdu(responseApdu.Data.ToArray());
6870
}
6971
catch (KeyboardConnectionException e)
7072
{
7173
_logger.LogWarning(e, "Handling keyboard connection exception. Translating to APDU response.");
7274

73-
return new ResponseApdu(Array.Empty<byte>(), SWConstants.WarningNvmUnchanged);
75+
return FailedApdu([]);
7476
}
77+
78+
static ResponseApdu FailedApdu(byte[] data) => new(data, SWConstants.WarningNvmUnchanged);
7579
}
7680

7781
public void Setup() => _nextTransform.Setup();

0 commit comments

Comments
 (0)