diff --git a/wolfcrypt/ciphers.py b/wolfcrypt/ciphers.py index 77ea987..d08fe5f 100644 --- a/wolfcrypt/ciphers.py +++ b/wolfcrypt/ciphers.py @@ -364,7 +364,7 @@ def _prepare_associated_data(associated_data): C function has been called, in order to make sure that the memory is not freed by the FFI garbage collector before the data is read. """ - if (isinstance(associated_data, str) or isinstance(associated_data, bytes)): + if isinstance(associated_data, str) or isinstance(associated_data, bytes): # A single block is provided. # Make sure we have bytes. associated_data = t2b(associated_data) @@ -374,7 +374,7 @@ def _prepare_associated_data(associated_data): else: # It is assumed that a list is provided. num_blocks = len(associated_data) - if (num_blocks > 126): + if num_blocks > 126: raise WolfCryptError("AES-SIV does not support more than 126 blocks " "of associated data, got: %d" % num_blocks) # Make sure we have bytes. @@ -410,7 +410,7 @@ def __init__(self, key, IV, tag_bytes=16): raise ValueError( "tag_bytes must be one of 4, 8, 12, 13, 14, 15, or 16") # Per-instance state: AAD, tag length, and current mode (enc/dec). - self._aad = bytes() + self._aad = b"" self._tag_bytes = tag_bytes self._mode = None if len(key) not in self._key_sizes: @@ -447,7 +447,7 @@ def encrypt(self, data): Add more data to the encryption stream """ data = t2b(data) - aad = bytes() + aad = b"" if self._mode is None: self._mode = _ENCRYPTION aad = self._aad @@ -463,7 +463,7 @@ def decrypt(self, data): """ Add more data to the decryption stream """ - aad = bytes() + aad = b"" data = t2b(data) if self._mode is None: self._mode = _DECRYPTION @@ -826,8 +826,7 @@ def verify_pss(self, plaintext, signature): Returns a string containing the plaintext. """ if not self._hash_type: - raise WolfCryptError(("Hash type not set. Cannot verify a " - "PSS signature without a hash type.")) + raise WolfCryptError("Hash type not set. Cannot verify a PSS signature without a hash type.") hash_cls = hash_type_to_cls(self._hash_type) if not hash_cls: @@ -1022,8 +1021,7 @@ def sign_pss(self, plaintext): Returns a string containing the signature. """ if not self._hash_type: - raise WolfCryptError(("Hash type not set. Cannot verify a " - "PSS signature without a hash type.")) + raise WolfCryptError("Hash type not set. Cannot verify a PSS signature without a hash type.") hash_cls = hash_type_to_cls(self._hash_type) if not hash_cls: @@ -1128,8 +1126,8 @@ def encode_key_raw(self): Returns (Qx, Qy) """ - Qx = _ffi.new("byte[%d]" % (self.size)) - Qy = _ffi.new("byte[%d]" % (self.size)) + Qx = _ffi.new("byte[%d]" % self.size) + Qy = _ffi.new("byte[%d]" % self.size) qx_size = _ffi.new("word32[1]") qy_size = _ffi.new("word32[1]") qx_size[0] = self.size @@ -1305,9 +1303,9 @@ def encode_key_raw(self): Returns (Qx, Qy, d) """ - Qx = _ffi.new("byte[%d]" % (self.size)) - Qy = _ffi.new("byte[%d]" % (self.size)) - d = _ffi.new("byte[%d]" % (self.size)) + Qx = _ffi.new("byte[%d]" % self.size) + Qy = _ffi.new("byte[%d]" % self.size) + d = _ffi.new("byte[%d]" % self.size) qx_size = _ffi.new("word32[1]") qy_size = _ffi.new("word32[1]") d_size = _ffi.new("word32[1]") @@ -1450,7 +1448,7 @@ def decode_key(self, key): Decodes an ED25519 public key """ key = t2b(key) - if (len(key) < _lib.wc_ed25519_pub_size(self.native_object)): + if len(key) < _lib.wc_ed25519_pub_size(self.native_object): raise WolfCryptError("Key decode error: key too short") idx = _ffi.new("word32*") @@ -1537,7 +1535,7 @@ def decode_key(self, key, pub = None): """ key = t2b(key) - if (len(key) < _lib.wc_ed25519_priv_size(self.native_object)/2): + if len(key) < _lib.wc_ed25519_priv_size(self.native_object)/2: raise WolfCryptError("Key decode error: key too short") idx = _ffi.new("word32*") @@ -1650,7 +1648,7 @@ def decode_key(self, key): Decodes an ED448 public key """ key = t2b(key) - if (len(key) < _lib.wc_ed448_pub_size(self.native_object)): + if len(key) < _lib.wc_ed448_pub_size(self.native_object): raise WolfCryptError("Key decode error: key too short") idx = _ffi.new("word32*") @@ -1743,7 +1741,7 @@ def decode_key(self, key, pub = None): """ key = t2b(key) - if (len(key) < _lib.wc_ed448_priv_size(self.native_object)/2): + if len(key) < _lib.wc_ed448_priv_size(self.native_object)/2: raise WolfCryptError("Key decode error: key too short") idx = _ffi.new("word32*")