From 405a65dea4ef1c12aaec4e232dc3a4b123ca3017 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Wed, 16 Sep 2015 00:59:35 -0400 Subject: Add C_SignUpdate(), C_SignFinal(), C_VerifyUpdate(), C_VerifyFinal(). --- py11/__init__.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'py11') diff --git a/py11/__init__.py b/py11/__init__.py index fa6e0f5..af7e053 100644 --- a/py11/__init__.py +++ b/py11/__init__.py @@ -109,6 +109,16 @@ class PKCS11 (object): self.so.C_Sign(session, data, len(data), sig, byref(n)) return sig.raw + def C_SignUpdate(self, session, data): + self.so.C_SignUpdate(session, data, len(data)) + + def C_SignFinal(self, session): + n = CK_ULONG() + self.so.C_Sign(session, None, byref(n)) + sig = create_string_buffer(n.value) + self.so.C_Sign(session, sig, byref(n)) + return sig.raw + def C_VerifyInit(self, session, mechanism_type, public_key): mechanism = CK_MECHANISM(mechanism_type, None, 0) self.so.C_VerifyInit(session, byref(mechanism), public_key) @@ -116,12 +126,39 @@ class PKCS11 (object): def C_Verify(self, session, data, signature): self.so.C_Verify(session, data, len(data), signature, len(signature)) + def C_VerifyUpdate(self, session, data): + self.so.C_Verify(session, data, len(data)) + + def C_VerifyFinal(self, session, signature): + self.so.C_Verify(session, signature, len(signature)) + def C_CreateObject(self, session, template): template = self.adb.to_ctypes(template) handle = CK_OBJECT_HANDLE() self.so.C_CreateObject(session, template, len(template), byref(handle)) return handle.value + def C_DigestInit(self, session, mechanism_type): + mechanism = CK_MECHANISM(mechanism_type, None, 0) + self.so.C_DigestInit(session, byref(mechanism)) + + def C_Digest(self, session, data): + n = CK_ULONG() + self.so.C_Digest(session, data, len(data), None, byref(n)) + hash = create_string_buffer(n.value) + self.so.C_Digest(session, data, len(data), hash, byref(n)) + return hash.raw + + def C_DigestUpdate(self, session, data): + self.so.C_DigestUpdate(session, data, len(data)) + + def C_DigestFinal(self, session): + n = CK_ULONG() + self.so.C_Digest(session, None, byref(n)) + hash = create_string_buffer(n.value) + self.so.C_Digest(session, hash, byref(n)) + return hash.raw + __all__ = ["PKCS11"] __all__.extend(name for name in globals() if name.startswith("CK") -- cgit v1.2.3