|
1 | 1 | import enum |
2 | | -import sys |
3 | 2 | from dataclasses import dataclass |
4 | 3 | from enum import Enum, IntFlag |
5 | 4 | from typing import Optional |
6 | 5 |
|
7 | 6 | from fido2 import cbor |
8 | 7 | from fido2.ctap import CtapError |
9 | 8 |
|
10 | | -from nitrokey.helpers import local_critical, local_print |
11 | | - |
12 | 9 | from .device import App, NitrokeyTrussedDevice |
13 | 10 | from .exceptions import TimeoutException |
14 | 11 | from .utils import Uuid, Version |
@@ -121,7 +118,7 @@ def check(cls, i: int, msg: str) -> None: |
121 | 118 | error = "The application does not support factory reset through nitropy" |
122 | 119 | elif status == FactoryResetStatus.APP_FAILED_PARSE: |
123 | 120 | error = "The application name must be utf-8" |
124 | | - local_critical(f"{msg}: {error}", support_hint=False) |
| 121 | + raise Exception(f"{msg}: {error}") |
125 | 122 |
|
126 | 123 |
|
127 | 124 | @enum.unique |
@@ -269,37 +266,27 @@ def set_config(self, key: str, value: str) -> None: |
269 | 266 | assert reply |
270 | 267 | ConfigStatus.check(reply[0], "Failed to set config value") |
271 | 268 |
|
272 | | - def factory_reset(self) -> None: |
| 269 | + def factory_reset(self) -> bool: |
273 | 270 | try: |
274 | | - local_print( |
275 | | - "Please touch the device to confirm the operation", file=sys.stderr |
276 | | - ) |
277 | 271 | reply = self._call(AdminCommand.FACTORY_RESET, response_len=1) |
278 | | - if reply is None: |
279 | | - local_critical( |
280 | | - "Factory reset is not supported by the firmware version on the device", |
281 | | - support_hint=False, |
282 | | - ) |
283 | | - return |
284 | 272 | except OSError as e: |
285 | 273 | if e.errno == 5: |
286 | 274 | self.device.logger.debug("ignoring OSError after reboot", exc_info=e) |
287 | | - return |
| 275 | + return True |
288 | 276 | else: |
289 | 277 | raise e |
290 | | - FactoryResetStatus.check(reply[0], "Failed to factory reset the device") |
| 278 | + if reply: |
| 279 | + FactoryResetStatus.check(reply[0], "Failed to factory reset the device") |
| 280 | + return reply is not None |
291 | 281 |
|
292 | | - def factory_reset_app(self, application: str) -> None: |
293 | | - local_print("Please touch the device to confirm the operation", file=sys.stderr) |
| 282 | + def factory_reset_app(self, application: str) -> bool: |
294 | 283 | reply = self._call( |
295 | 284 | AdminCommand.FACTORY_RESET_APP, |
296 | 285 | data=application.encode("ascii"), |
297 | 286 | response_len=1, |
298 | 287 | ) |
299 | | - if reply is None: |
300 | | - local_critical( |
301 | | - "Application Factory reset is not supported by the firmware version on the device", |
302 | | - support_hint=False, |
| 288 | + if reply: |
| 289 | + FactoryResetStatus.check( |
| 290 | + reply[0], "Failed to factory reset the application" |
303 | 291 | ) |
304 | | - return |
305 | | - FactoryResetStatus.check(reply[0], "Failed to factory reset the device") |
| 292 | + return reply is not None |
0 commit comments