aboutsummaryrefslogtreecommitdiff
path: root/cryptech/py11/exceptions.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-05-04 02:33:40 -0400
committerRob Austein <sra@hactrn.net>2017-05-04 02:33:40 -0400
commit0cc1b0a7b5605d86d8a8639651987e25fdb3bdc9 (patch)
tree9560dbda984b8ece29f2018e3bff143fa4f5ce97 /cryptech/py11/exceptions.py
parentce8ba928172071dc89cc1fc0520f840211bbfa0d (diff)
Support using C_GetFunctionList() instead of library symbols.
The Python ctypes library allows us direct access to the public symbols of a shared library, so we never bothered to implement support for using the dispatch vector returned by C_GetFunctionList(). Well, it turns out that there are useful debugging tools like pkcs11-spy which require the dispatch vector support, so refactor to add it.
Diffstat (limited to 'cryptech/py11/exceptions.py')
-rw-r--r--cryptech/py11/exceptions.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/cryptech/py11/exceptions.py b/cryptech/py11/exceptions.py
index 7f86fe4..9512cda 100644
--- a/cryptech/py11/exceptions.py
+++ b/cryptech/py11/exceptions.py
@@ -28,6 +28,11 @@ class CKR_Exception(Exception):
def __int__(self):
return self.ckr_code
+ @classmethod
+ def raise_on_failure(cls, rv, func, *args):
+ if rv != CKR_OK:
+ raise cls.ckr_map[rv]
+
CKR_OK = 0x00000000
class CKR_CANCEL (CKR_Exception): ckr_code = 0x00000001