Skip to content

Commit 3a4d82a

Browse files
Move should_default_ccid to the trussed module
1 parent 2436e61 commit 3a4d82a

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/nitrokey/should_use_ccid.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/nitrokey/trussed/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# http://opensource.org/licenses/MIT>, at your option. This file may not be
66
# copied, modified, or distributed except according to those terms.
77

8+
import ctypes
9+
import sys
10+
from importlib.util import find_spec
811
from typing import List, Optional
912

1013
from ._base import Model as Model # noqa: F401
@@ -23,7 +26,26 @@
2326
from ._utils import Version as Version # noqa: F401
2427

2528

26-
def list(use_ccid: bool = False, *, model: Optional[Model] = None) -> List[TrussedBase]:
29+
def should_default_ccid() -> bool:
30+
if find_spec("smartcard") is None:
31+
return False
32+
33+
if sys.platform != "win32" and sys.platform != "cygwin":
34+
# Linux or MacOS don't need admin to access with CTAPHID
35+
return False
36+
37+
try:
38+
if ctypes.windll.shell32.IsUserAnAdmin():
39+
return False
40+
else:
41+
return True
42+
except Exception:
43+
return False
44+
45+
46+
def list(
47+
use_ccid: bool = should_default_ccid(), *, model: Optional[Model] = None
48+
) -> List[TrussedBase]:
2749
devices: List[TrussedBase] = []
2850

2951
if model is None or model == Model.NK3:

0 commit comments

Comments
 (0)