]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blobdiff - ctypescrypto/cms.py
CMS_sign expects certstack to be a pointer
[oss/ctypescrypto.git] / ctypescrypto / cms.py
index 685d52bd642c1cde132c002f5c1f65b5d87eac2b..ede20f5e631bad5d346f90391cde2c97371985f2 100644 (file)
@@ -84,7 +84,7 @@ class CMSBase(object):
         """
         bio = Membio()
         if not libcrypto.i2d_CMS_bio(bio.bio, self.ptr):
-            raise CMSError("writing CMS to PEM")
+            raise CMSError("writing CMS to DER")
         return str(bio)
 
     def pem(self):
@@ -120,10 +120,10 @@ class SignedData(CMSBase):
             raise ValueError("Certificate doesn't match public key")
         bio = Membio(data)
         if certs is not None and len(certs) > 0:
-            certstack = StackOfX509(certs)
+            certstack = StackOfX509(certs).ptr
         else:
             certstack = None
-        ptr = libcrypto.CMS_sign(cert.cert, pkey.ptr, certstack, bio.bio, flags)
+        ptr = libcrypto.CMS_sign(cert.cert, pkey.key, certstack, bio.bio, flags)
         if ptr is None:
             raise CMSError("signing message")
         return SignedData(ptr)
@@ -142,7 +142,7 @@ class SignedData(CMSBase):
             raise ValueError("Specified keypair has no private part")
         if cert.pubkey != pkey:
             raise ValueError("Certificate doesn't match public key")
-        if libcrypto.CMS_add1_signer(self.ptr, cert.cert, pkey.ptr,
+        if libcrypto.CMS_add1_signer(self.ptr, cert.cert, pkey.key,
                                           digest_type.digest, flags) is None:
             raise CMSError("adding signer")
         if flags & Flags.REUSE_DIGEST == 0:
@@ -263,7 +263,7 @@ class EnvelopedData(CMSBase):
         if pkey != cert.pubkey:
             raise ValueError("Certificate doesn't match private key")
         bio = Membio()
-        res = libcrypto.CMS_decrypt(self.ptr, pkey.ptr, cert.ccert, None,
+        res = libcrypto.CMS_decrypt(self.ptr, pkey.key, cert.ccert, None,
                                     bio.bio, flags)
         if res <= 0:
             raise CMSError("decrypting CMS")
@@ -306,6 +306,8 @@ class EncryptedData(CMSBase):
 __all__ = ['CMS', 'CMSError', 'Flags', 'SignedData', 'EnvelopedData',
            'EncryptedData']
 
+libcrypto.CMS_get0_type.restype = c_void_p
+libcrypto.CMS_get0_type.argtypes = (c_void_p,)
 libcrypto.CMS_add1_cert.restype = c_int
 libcrypto.CMS_add1_cert.argtypes = (c_void_p, c_void_p)
 libcrypto.CMS_decrypt.restype = c_int