X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fcms.py;h=d92b7335f2dc4917352c0c422a6376332dd6f016;hb=HEAD;hp=ede20f5e631bad5d346f90391cde2c97371985f2;hpb=4507d5ef438ad37cf587f321e553f43751f70333;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/cms.py b/ctypescrypto/cms.py index ede20f5..d92b733 100644 --- a/ctypescrypto/cms.py +++ b/ctypescrypto/cms.py @@ -17,6 +17,12 @@ from ctypescrypto.bio import Membio from ctypescrypto.oid import Oid from ctypescrypto.x509 import StackOfX509 +# Check for neccesary functionality in libcrypto +# LibreSSL fails this check + +if not hasattr(libcrypto,"CMS_decrypt"): + raise OSError("libcrypto lacks CMS functionality. Try using different libcrypto") + class CMSError(LibCryptoError): """ Exception which is raised when error occurs @@ -243,7 +249,7 @@ class EnvelopedData(CMSBase): """ recp = StackOfX509(recipients) bio = Membio(data) - cms_ptr = libcrypto.CMS_encrypt(recp.ptr, bio.bio, cipher.cipher_type, + cms_ptr = libcrypto.CMS_encrypt(recp.ptr, bio.bio, cipher.cipher, flags) if cms_ptr is None: raise CMSError("encrypt EnvelopedData") @@ -263,7 +269,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.key, cert.ccert, None, + res = libcrypto.CMS_decrypt(self.ptr, pkey.key, cert.cert, None, bio.bio, flags) if res <= 0: raise CMSError("decrypting CMS") @@ -285,7 +291,7 @@ class EncryptedData(CMSBase): @param flags - OR-ed combination of Flags constant """ bio = Membio(data) - ptr = libcrypto.CMS_EncryptedData_encrypt(bio.bio, cipher.cipher_type, + ptr = libcrypto.CMS_EncryptedData_encrypt(bio.bio, cipher.cipher, key, len(key), flags) if ptr is None: raise CMSError("encrypt data")