from ctypes import create_string_buffer,c_char_p,c_void_p,c_int,c_long,byref,POINTER
from ctypescrypto import libcrypto
from ctypescrypto.exception import LibCryptoError
from ctypes import create_string_buffer,c_char_p,c_void_p,c_int,c_long,byref,POINTER
from ctypescrypto import libcrypto
from ctypescrypto.exception import LibCryptoError
if not iv is None and len(iv) != cipher_type.iv_length():
raise ValueError("Invalid IV length for this algorithm")
if len(key) != cipher_type.key_length():
if (cipher_type.flags() & 8) != 0:
# Variable key length cipher.
if not iv is None and len(iv) != cipher_type.iv_length():
raise ValueError("Invalid IV length for this algorithm")
if len(key) != cipher_type.key_length():
if (cipher_type.flags() & 8) != 0:
# Variable key length cipher.
- result = libcrypto.EVP_CipherInit_ex(self.ctx,cipher_type.cipher,None,None,None,c_int(enc))
- result=libcrypto.EVP_CIPHER_CTX_set_key_length(self.ctx,len(key))
+ result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, None, None, c_int(enc))
+ result = libcrypto.EVP_CIPHER_CTX_set_key_length(self.ctx,len(key))
- result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc))
+ else:
+ result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc))
self.cipher_type = cipher_type
self.block_size = self.cipher_type.block_size()
self.cipher_finalized = False
self.cipher_type = cipher_type
self.block_size = self.cipher_type.block_size()
self.cipher_finalized = False
- raise CipherError, "No updates allowed"
- if type(data) != type(""):
- raise TypeError, "A string is expected"
- if len(data) <= 0:
+ raise CipherError("No updates allowed")
+ if not isinstance(data,str):
+ raise TypeError("A string is expected")
+ if len(data) == 0:
state, they would be processed and returned.
"""
if self.cipher_finalized :
state, they would be processed and returned.
"""
if self.cipher_finalized :
libcrypto.EVP_CipherUpdate.argtypes=(c_void_p,c_char_p,POINTER(c_int),c_char_p,c_int)
libcrypto.EVP_get_cipherbyname.restype=c_void_p
libcrypto.EVP_get_cipherbyname.argtypes=(c_char_p,)
libcrypto.EVP_CipherUpdate.argtypes=(c_void_p,c_char_p,POINTER(c_int),c_char_p,c_int)
libcrypto.EVP_get_cipherbyname.restype=c_void_p
libcrypto.EVP_get_cipherbyname.argtypes=(c_char_p,)