Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
This patch removes dead code: modules that are no longer imported,
functions that are no longer called, code that has been commented out
for several years and is not needed anymore.
  • Loading branch information
robin-nitrokey committed Dec 10, 2024
1 parent 0235106 commit 7d56c10
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 469 deletions.
2 changes: 0 additions & 2 deletions pynitrokey/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
from pynitrokey.confconsts import LOG_FN, LOG_FORMAT
from pynitrokey.helpers import filter_sensitive_parameters, local_critical

# from . import _patches # noqa (since otherwise "unused")

logger = logging.getLogger(__name__)


Expand Down
125 changes: 0 additions & 125 deletions pynitrokey/cli/_patches.py

This file was deleted.

24 changes: 0 additions & 24 deletions pynitrokey/fido2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,9 @@
from fido2.hid import CtapHidDevice

from pynitrokey.exceptions import NoSoloFoundError

# from pynitrokey.fido2 import hmac_secret
from pynitrokey.fido2.client import NKFido2Client


def hot_patch_windows_libusb() -> None:
# hot patch for windows libusb backend
olddel = usb._objfinalizer._AutoFinalizedObjectBase.__del__

def newdel(self): # type: ignore
try:
olddel(self)
except OSError:
pass

usb._objfinalizer._AutoFinalizedObjectBase.__del__ = newdel


# @todo: remove this, HidOverUDP is not available anymore!
def _UDP_InternalPlatformSwitch(
funcname: str, *args: tuple[Any, Any], **kwargs: dict[Any, Any]
) -> None:
if funcname == "__init__":
return HidOverUDP(*args, **kwargs) # type: ignore
return getattr(HidOverUDP, funcname)(*args, **kwargs) # type: ignore


def find(
solo_serial: Optional[str] = None,
retries: int = 5,
Expand Down
14 changes: 0 additions & 14 deletions pynitrokey/fido2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,6 @@ def is_bootloader(self) -> bool:
pass
return False

def enter_st_dfu(self) -> None:
"""
If Nitrokey is configured as Nitrokey hacker or something similar,
this command will tell the token to boot directly to the st DFU
so it can be reprogrammed. Warning, you could brick your device.
"""
boot = self.is_bootloader()

if boot or self.exchange == self.exchange_u2f:
req = NKFido2Client.format_request(SoloBootloader.st_dfu)
self.send_only_hid(SoloBootloader.HIDCommandBoot, req)
else:
self.send_only_hid(SoloBootloader.HIDCommandEnterSTBoot, b"")

def program_file(self, name: str) -> bytes:
def parseField(f: str) -> bytes:
return base64.b64decode(helpers.from_websafe(f).encode())
Expand Down
41 changes: 0 additions & 41 deletions pynitrokey/fido2/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
# copied, modified, or distributed except according to those terms.


class STM32L4:
class options:
nBOOT0 = 1 << 27
nSWBOOT0 = 1 << 26


class SoloExtension:
version = 0x14
rng = 0x15
Expand All @@ -38,38 +32,3 @@ class SoloBootloader:
HIDCommandStatus = 0x71

TAG = b"\x8C\x27\x90\xf6"


class DFU:
class type:
SEND = 0x21
RECEIVE = 0xA1

class bmReq:
DETACH = 0x00
DNLOAD = 0x01
UPLOAD = 0x02
GETSTATUS = 0x03
CLRSTATUS = 0x04
GETSTATE = 0x05
ABORT = 0x06

class state:
APP_IDLE = 0x00
APP_DETACH = 0x01
IDLE = 0x02
DOWNLOAD_SYNC = 0x03
DOWNLOAD_BUSY = 0x04
DOWNLOAD_IDLE = 0x05
MANIFEST_SYNC = 0x06
MANIFEST = 0x07
MANIFEST_WAIT_RESET = 0x08
UPLOAD_IDLE = 0x09
ERROR = 0x0A

class status:
def __init__(self, s: bytes):
self.status = s[0]
self.timeout = s[1] + (s[2] << 8) + (s[3] << 16)
self.state = s[4]
self.istring = s[5]
Loading

0 comments on commit 7d56c10

Please sign in to comment.