forked from pyauth/python-pkcs11
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
52 lines (38 loc) · 1.04 KB
/
__init__.py
File metadata and controls
52 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
:mod:`pkcs11` defines a high-level, "Pythonic" interface to PKCS#11.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from pkcs11.constants import * # noqa: F403
from pkcs11.exceptions import * # noqa: F403
from pkcs11.mechanisms import * # noqa: F403
from pkcs11.types import * # noqa: F403
from pkcs11.util import dh, dsa, ec, rsa, x509 # noqa: F401
if TYPE_CHECKING:
from pkcs11._pkcs11 import lib as _lib_type
_loaded: dict[str, Any] = {}
def lib(so: str) -> _lib_type:
"""
Wrap the main library call coming from Cython with a preemptive
dynamic loading.
"""
global _loaded
try:
_lib = _loaded[so]
if not _lib.initialized:
_lib.initialize()
return _lib
except KeyError:
pass
from . import _pkcs11
_lib = _pkcs11.lib(so)
_loaded[so] = _lib
return _lib
def unload(so: str) -> None:
global _loaded
try:
loaded_lib = _loaded[so]
except KeyError:
return
del _loaded[so]
loaded_lib.unload()