Skip to content

Commit

Permalink
Merge pull request #321 from Nitrokey/release-v0.4.33
Browse files Browse the repository at this point in the history
Mypy lint corrections for otp_app
  • Loading branch information
szszszsz authored Feb 3, 2023
2 parents 4b06381 + 18250d3 commit 26386cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ lint:
$(VENV)/bin/python3 -m mypy $(PACKAGE_NAME)

semi-clean:
rm -rf **/__pycache__
rm -rf ./**/__pycache__

clean: semi-clean
rm -rf $(VENV)
rm -rf dist
rm -rf ./$(VENV)
rm -rf ./dist


# Package management
Expand Down
6 changes: 4 additions & 2 deletions pynitrokey/nk3/otp_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def delete(self, cred_id: bytes) -> None:
Delete credential with the given id. Does not fail, if the given credential does not exist.
:param credid: Credential ID
"""
self.logfn(f"Sending delete request for {cred_id}")
self.logfn(f"Sending delete request for {cred_id!r}")
structure = [
tlv8.Entry(Tag.CredentialId.value, cred_id),
]
Expand Down Expand Up @@ -304,7 +304,9 @@ def calculate(self, cred_id: bytes, challenge: int) -> bytes:
Should be equal to: timestamp/period. The commonly used period value is 30.
:return: OTP code as a byte string
"""
self.logfn(f"Sending calculate request for {cred_id} and challenge {challenge}")
self.logfn(
f"Sending calculate request for {cred_id!r} and challenge {challenge!r}"
)
structure = [
tlv8.Entry(Tag.CredentialId.value, cred_id),
tlv8.Entry(Tag.Challenge.value, pack(">Q", challenge)),
Expand Down
15 changes: 8 additions & 7 deletions pynitrokey/test_otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import time
from datetime import timedelta
from sys import stderr
from typing import Any, Callable, List

import fido2
import pytest
Expand Down Expand Up @@ -373,10 +374,10 @@ def test_load(otpApp, kind: Kind, long_labels: bool):
secretb = binascii.a2b_hex(secret)
otpApp.reset()

credentials_registered = 0
names_registered = []
credentials_registered: int = 0
names_registered: List[bytes] = []

name_gen = lambda x: f"LOAD{x:02}"
name_gen: Callable[[int], str] = lambda x: f"LOAD{x:02}"
if long_labels:
name_gen = lambda x: (f"LOAD{x:02}" * 100)[:CREDENTIAL_LABEL_MAX_SIZE]

Expand Down Expand Up @@ -406,8 +407,8 @@ def test_load(otpApp, kind: Kind, long_labels: bool):

# Make some space for the counter updates - delete the last 3 credentials
CRED_TO_REMOVE = 3
for name in names_registered[-CRED_TO_REMOVE:]:
otpApp.delete(name)
for name_c in names_registered[-CRED_TO_REMOVE:]:
otpApp.delete(name_c)
credentials_registered -= CRED_TO_REMOVE

l = otpApp.list()
Expand All @@ -420,8 +421,8 @@ def test_load(otpApp, kind: Kind, long_labels: bool):
for i in range(credentials_registered):
# At this point device should respond to our calls, despite being full, fail otherwise
# Iterate over credentials and check code at given challenge
name = name_gen(i)
assert otpApp.calculate(name, i) == lib_at(i)
nameb = name_gen(i).encode()
assert otpApp.calculate(nameb, i) == lib_at(i)

l = otpApp.list()
assert len(l) == credentials_registered
Expand Down

0 comments on commit 26386cf

Please sign in to comment.