"""
from ctypes import create_string_buffer, c_char_p, c_void_p, c_int
from ctypes import byref, POINTER
-from ctypescrypto import libcrypto
+from ctypescrypto import libcrypto, pyver, bintype
from ctypescrypto.exception import LibCryptoError
from ctypescrypto.oid import Oid
Constructs cipher algortihm using textual name as in openssl
command line
"""
+ if pyver > 2:
+ cipher_name = cipher_name.encode('utf-8')
self.cipher = libcrypto.EVP_get_cipherbyname(cipher_name)
if self.cipher is None:
raise CipherError("Unknown cipher: %s" % cipher_name)
"""
if self.cipher_finalized:
raise CipherError("No updates allowed")
- if not isinstance(data, str):
- raise TypeError("A string is expected")
+ if not isinstance(data, bintype):
+ raise TypeError("A byte string is expected")
if len(data) == 0:
return ""
outbuf = create_string_buffer(self.block_size+len(data))
if outlen.value > 0:
return outbuf.raw[:int(outlen.value)]
else:
- return ""
+ return b""
def _clean_ctx(self):
"""
"""
try:
if self.ctx is not None:
- libcrypto.EVP_CIPHER_CTX_cleanup(self.ctx)
+ self.__ctxcleanup(self.ctx)
libcrypto.EVP_CIPHER_CTX_free(self.ctx)
del self.ctx
except AttributeError:
# Used C function block_size
#
libcrypto.EVP_CIPHER_block_size.argtypes = (c_void_p, )
-libcrypto.EVP_CIPHER_CTX_cleanup.argtypes = (c_void_p, )
+
+#Function EVP_CIPHER_CTX_cleanup renamed to EVP_CIPHER_CTX_reset
+# in the OpenSSL 1.1.0
+if hasattr(libcrypto,"EVP_CIPHER_CTX_cleanup"):
+ Cipher.__ctxcleanup = libcrypto.EVP_CIPHER_CTX_cleanup
+else:
+ Cipher.__ctxcleanup = libcrypto.EVP_CIPHER_CTX_reset
+Cipher.__ctxcleanup.argtypes = (c_void_p, )
libcrypto.EVP_CIPHER_CTX_free.argtypes = (c_void_p, )
libcrypto.EVP_CIPHER_CTX_new.restype = c_void_p
libcrypto.EVP_CIPHER_CTX_set_padding.argtypes = (c_void_p, c_int)