Skip to content

Commit

Permalink
Revert "Adjustments made by make fix"
Browse files Browse the repository at this point in the history
This reverts commit be92216.
  • Loading branch information
anotherbridge committed Apr 15, 2024
1 parent be92216 commit e242c6b
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 71 deletions.
3 changes: 2 additions & 1 deletion pynitrokey/cli/nethsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@


class EnumMeta(Protocol):
def __iter__(self) -> Iterator[Enum]: ...
def __iter__(self) -> Iterator[Enum]:
...


def make_enum_type(enum_cls: EnumMeta) -> click.Choice:
Expand Down
9 changes: 6 additions & 3 deletions pynitrokey/cli/trussed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ def __init__(

@property
@abstractmethod
def test_cases(self) -> Sequence[TestCase]: ...
def test_cases(self) -> Sequence[TestCase]:
...

@abstractmethod
def open(self, path: str) -> Optional[NitrokeyTrussedBase]: ...
def open(self, path: str) -> Optional[NitrokeyTrussedBase]:
...

@abstractmethod
def list_all(self) -> Sequence[NitrokeyTrussedBase]: ...
def list_all(self) -> Sequence[NitrokeyTrussedBase]:
...

def list(self) -> Sequence[NitrokeyTrussedBase]:
if self.path:
Expand Down
2 changes: 1 addition & 1 deletion pynitrokey/cli/trussed/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def run_tests(
description_len = max([len(test_case.description) for test_case in test_cases]) + 2
status_len = max([len(status.name) for status in TestStatus]) + 2

for i, test_case in enumerate(test_cases):
for (i, test_case) in enumerate(test_cases):
try:
result = test_case.fn(ctx, device)
except Exception:
Expand Down
1 change: 1 addition & 0 deletions pynitrokey/fido2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def make_credential(
output: bool = True,
fingerprint_only: bool = False,
) -> str:

"""
fingerprint_only bool Return sha256 digest of the certificate, in a hex string format. Useful for detecting
device's model and firmware.
Expand Down
8 changes: 3 additions & 5 deletions pynitrokey/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,9 @@ def local_critical(
f"- You can report issues at: {SUPPORT_URL}",
f"- Writing an e-mail to {SUPPORT_EMAIL} is also possible",
f"- Please attach the log: '{LOG_FN}' with any support/help request!",
(
f"- Please check if you have udev rules installed: {UDEV_URL}"
if linux
else "" "-" * 80
),
f"- Please check if you have udev rules installed: {UDEV_URL}"
if linux
else "" "-" * 80,
"",
)
sys.exit(ret_code)
Expand Down
61 changes: 23 additions & 38 deletions pynitrokey/nk3/secrets_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Used through CTAPHID transport, via the custom vendor command.
Can be used directly over CCID as well.
"""

import dataclasses
import hmac
import logging
Expand Down Expand Up @@ -82,21 +81,15 @@ class PasswordSafeEntry:

def tlv_encode(self) -> list[tlv8.Entry]:
entries = [
(
tlv8.Entry(Tag.PwsLogin.value, self.login)
if self.login is not None
else None
),
(
tlv8.Entry(Tag.PwsPassword.value, self.password)
if self.password is not None
else None
),
(
tlv8.Entry(Tag.PwsMetadata.value, self.metadata)
if self.metadata is not None
else None
),
tlv8.Entry(Tag.PwsLogin.value, self.login)
if self.login is not None
else None,
tlv8.Entry(Tag.PwsPassword.value, self.password)
if self.password is not None
else None,
tlv8.Entry(Tag.PwsMetadata.value, self.metadata)
if self.metadata is not None
else None,
]
# Filter out empty entries
entries = [r for r in entries if r is not None]
Expand Down Expand Up @@ -524,22 +517,16 @@ def update_credential(
structure = [
tlv8.Entry(Tag.CredentialId.value, cred_id),
tlv8.Entry(Tag.CredentialId.value, new_name) if new_name else None,
(
self.encode_properties_to_send(touch_button, False, tlv=True)
if touch_button is not None
else None
),
self.encode_properties_to_send(touch_button, False, tlv=True)
if touch_button is not None
else None,
tlv8.Entry(Tag.PwsLogin.value, login) if login is not None else None,
(
tlv8.Entry(Tag.PwsPassword.value, password)
if password is not None
else None
),
(
tlv8.Entry(Tag.PwsMetadata.value, metadata)
if metadata is not None
else None
),
tlv8.Entry(Tag.PwsPassword.value, password)
if password is not None
else None,
tlv8.Entry(Tag.PwsMetadata.value, metadata)
if metadata is not None
else None,
]
structure = list(filter(lambda x: x is not None, structure))
self._send_receive(Instruction.UpdateCredential, structure=structure)
Expand Down Expand Up @@ -615,13 +602,11 @@ def register(
Tag.Key.value, bytes([kind.value | algo.value, digits]) + secret
),
self.encode_properties_to_send(touch_button_required, pin_based_encryption),
(
tlv8.Entry(
Tag.InitialCounter.value, initial_counter_value.to_bytes(4, "big")
)
if kind in [Kind.Hotp, Kind.HotpReverse]
else None
),
tlv8.Entry(
Tag.InitialCounter.value, initial_counter_value.to_bytes(4, "big")
)
if kind in [Kind.Hotp, Kind.HotpReverse]
else None,
*PasswordSafeEntry(
name=credid, login=login, password=password, metadata=metadata
).tlv_encode(),
Expand Down
1 change: 1 addition & 0 deletions pynitrokey/start/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@


3 changes: 1 addition & 2 deletions pynitrokey/start/gnuk_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import binascii
import logging
import time
Expand Down Expand Up @@ -743,7 +742,7 @@ def get_gnuk_device(verbose=True, logger: Optional[logging.Logger] = None):

candidates = []
icc = None
for dev, config, intf in gnuk_devices():
for (dev, config, intf) in gnuk_devices():
try:
icc = gnuk_token(dev, config, intf)
if logger:
Expand Down
18 changes: 12 additions & 6 deletions pynitrokey/trussed/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,27 @@ def vid(self) -> int:

@property
@abstractmethod
def pid(self) -> int: ...
def pid(self) -> int:
...

@property
@abstractmethod
def path(self) -> str: ...
def path(self) -> str:
...

@property
@abstractmethod
def name(self) -> str: ...
def name(self) -> str:
...

@abstractmethod
def close(self) -> None: ...
def close(self) -> None:
...

@abstractmethod
def reboot(self) -> bool: ...
def reboot(self) -> bool:
...

@abstractmethod
def uuid(self) -> Optional[Uuid]: ...
def uuid(self) -> Optional[Uuid]:
...
6 changes: 4 additions & 2 deletions pynitrokey/trussed/bootloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ def update(
self,
image: bytes,
callback: Optional[ProgressCallback] = None,
) -> None: ...
) -> None:
...

@property
@abstractmethod
def variant(self) -> Variant: ...
def variant(self) -> Variant:
...


def get_firmware_filename_pattern(variant: Variant) -> Pattern[str]:
Expand Down
3 changes: 2 additions & 1 deletion pynitrokey/trussed/bootloader/nrf52.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def path(self) -> str:

@property
@abstractmethod
def signature_keys(self) -> Sequence[SignatureKey]: ...
def signature_keys(self) -> Sequence[SignatureKey]:
...

def close(self) -> None:
pass
Expand Down
14 changes: 7 additions & 7 deletions pynitrokey/trussed/bootloader/nrf52_upload/dfu/dfu_cc_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pynitrokey/trussed/bootloader/nrf52_upload/dfu/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def __init__(
zigbee_ota_min_hw_version=None,
zigbee_ota_max_hw_version=None,
):

"""
Constructor that requires values used for generating a Nordic DFU package.
Expand Down Expand Up @@ -474,10 +475,10 @@ def generate_package(self, filename, preserve_work_dir=False):
for key, firmware_data in self.firmwares_data.items():

# Normalize the firmware file and store it in the work directory
firmware_data[FirmwareKeys.BIN_FILENAME] = (
Package.normalize_firmware_to_bin(
self.work_dir, firmware_data[FirmwareKeys.FIRMWARE_FILENAME]
)
firmware_data[
FirmwareKeys.BIN_FILENAME
] = Package.normalize_firmware_to_bin(
self.work_dir, firmware_data[FirmwareKeys.FIRMWARE_FILENAME]
)

# Calculate the hash for the .bin file located in the work directory
Expand Down
3 changes: 2 additions & 1 deletion pynitrokey/trussed/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def _call_app(

@classmethod
@abstractmethod
def from_device(cls: type[T], device: CtapHidDevice) -> T: ...
def from_device(cls: type[T], device: CtapHidDevice) -> T:
...

@classmethod
def open(cls: type[T], path: str) -> Optional[T]:
Expand Down

0 comments on commit e242c6b

Please sign in to comment.