Skip to content

Commit

Permalink
Improve UX
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Nov 16, 2023
1 parent 2e74d44 commit 072d20b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pynitrokey/nk3/admin_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import sys
from dataclasses import dataclass
from enum import Enum, IntFlag
from typing import Optional
Expand All @@ -7,6 +8,7 @@
from fido2.ctap import CtapError

from pynitrokey.nk3.device import Command, Nitrokey3Device
from pynitrokey.helpers import local_critical, local_print

from .device import VERSION_LEN
from .utils import Version
Expand Down Expand Up @@ -178,8 +180,10 @@ def set_config(self, key: str, value: str) -> None:

def factory_reset(self) -> None:
try:
local_print("Please touch the device to confirm the operation", file=sys.stderr)
reply = self._call(AdminCommand.FACTORY_RESET, response_len=1)
assert reply
if reply is None:
local_critical("Factory reset is not supported by the device", support_hint=False)
except OSError as e:
if e.errno == 5:
self.device.logger.debug("ignoring OSError after reboot", exc_info=e)
Expand All @@ -189,10 +193,12 @@ def factory_reset(self) -> None:
FactoryResetStatus.check(reply[0], "Failed to factory reset the device")

def factory_reset_app(self, application: str) -> None:
local_print("Please touch the device to confirm the operation", file=sys.stderr)
reply = self._call(
AdminCommand.FACTORY_RESET_APP,
data=application.encode("ascii"),
response_len=1,
)
assert reply
if reply is None:
local_critical("Application Factory reset is not supported by the device", support_hint=False)
FactoryResetStatus.check(reply[0], "Failed to factory reset the device")

0 comments on commit 072d20b

Please sign in to comment.