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
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.key, certstack, bio.bio, flags)
"""
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")
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")
@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")