File: __init__.py

package info (click to toggle)
python-pkcs11 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 932 kB
  • sloc: python: 4,067; ansic: 2,764; makefile: 24
file content (44 lines) | stat: -rw-r--r-- 878 bytes parent folder | download
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
"""
:mod:`pkcs11` defines a high-level, "Pythonic" interface to PKCS#11.
"""

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

_loaded = {}


def lib(so):
    """
    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):
    global _loaded
    try:
        loaded_lib = _loaded[so]
    except KeyError:
        return
    del _loaded[so]
    loaded_lib.unload()