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 b0ddc46
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pynitrokey/nk3/admin_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import enum
import sys
from dataclasses import dataclass
from enum import Enum, IntFlag
from typing import Optional

from fido2 import cbor
from fido2.ctap import CtapError

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

from .device import VERSION_LEN
Expand Down Expand Up @@ -178,8 +180,15 @@ 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
)
return
except OSError as e:
if e.errno == 5:
self.device.logger.debug("ignoring OSError after reboot", exc_info=e)
Expand All @@ -189,10 +198,16 @@ 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,
)
return
FactoryResetStatus.check(reply[0], "Failed to factory reset the device")

0 comments on commit b0ddc46

Please sign in to comment.