Skip to content

Commit 17dad74

Browse files
Remove redundant parentheses and bytes() calls.
1 parent ec8ce54 commit 17dad74

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

wolfcrypt/ciphers.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def _prepare_associated_data(associated_data):
364364
C function has been called, in order to make sure that the memory
365365
is not freed by the FFI garbage collector before the data is read.
366366
"""
367-
if (isinstance(associated_data, str) or isinstance(associated_data, bytes)):
367+
if isinstance(associated_data, str) or isinstance(associated_data, bytes):
368368
# A single block is provided.
369369
# Make sure we have bytes.
370370
associated_data = t2b(associated_data)
@@ -374,7 +374,7 @@ def _prepare_associated_data(associated_data):
374374
else:
375375
# It is assumed that a list is provided.
376376
num_blocks = len(associated_data)
377-
if (num_blocks > 126):
377+
if num_blocks > 126:
378378
raise WolfCryptError("AES-SIV does not support more than 126 blocks "
379379
"of associated data, got: %d" % num_blocks)
380380
# Make sure we have bytes.
@@ -410,7 +410,7 @@ def __init__(self, key, IV, tag_bytes=16):
410410
raise ValueError(
411411
"tag_bytes must be one of 4, 8, 12, 13, 14, 15, or 16")
412412
# Per-instance state: AAD, tag length, and current mode (enc/dec).
413-
self._aad = bytes()
413+
self._aad = b""
414414
self._tag_bytes = tag_bytes
415415
self._mode = None
416416
if len(key) not in self._key_sizes:
@@ -447,7 +447,7 @@ def encrypt(self, data):
447447
Add more data to the encryption stream
448448
"""
449449
data = t2b(data)
450-
aad = bytes()
450+
aad = b""
451451
if self._mode is None:
452452
self._mode = _ENCRYPTION
453453
aad = self._aad
@@ -463,7 +463,7 @@ def decrypt(self, data):
463463
"""
464464
Add more data to the decryption stream
465465
"""
466-
aad = bytes()
466+
aad = b""
467467
data = t2b(data)
468468
if self._mode is None:
469469
self._mode = _DECRYPTION
@@ -826,8 +826,7 @@ def verify_pss(self, plaintext, signature):
826826
Returns a string containing the plaintext.
827827
"""
828828
if not self._hash_type:
829-
raise WolfCryptError(("Hash type not set. Cannot verify a "
830-
"PSS signature without a hash type."))
829+
raise WolfCryptError("Hash type not set. Cannot verify a PSS signature without a hash type.")
831830

832831
hash_cls = hash_type_to_cls(self._hash_type)
833832
if not hash_cls:
@@ -1022,8 +1021,7 @@ def sign_pss(self, plaintext):
10221021
Returns a string containing the signature.
10231022
"""
10241023
if not self._hash_type:
1025-
raise WolfCryptError(("Hash type not set. Cannot verify a "
1026-
"PSS signature without a hash type."))
1024+
raise WolfCryptError("Hash type not set. Cannot verify a PSS signature without a hash type.")
10271025

10281026
hash_cls = hash_type_to_cls(self._hash_type)
10291027
if not hash_cls:
@@ -1128,8 +1126,8 @@ def encode_key_raw(self):
11281126
11291127
Returns (Qx, Qy)
11301128
"""
1131-
Qx = _ffi.new("byte[%d]" % (self.size))
1132-
Qy = _ffi.new("byte[%d]" % (self.size))
1129+
Qx = _ffi.new("byte[%d]" % self.size)
1130+
Qy = _ffi.new("byte[%d]" % self.size)
11331131
qx_size = _ffi.new("word32[1]")
11341132
qy_size = _ffi.new("word32[1]")
11351133
qx_size[0] = self.size
@@ -1305,9 +1303,9 @@ def encode_key_raw(self):
13051303
13061304
Returns (Qx, Qy, d)
13071305
"""
1308-
Qx = _ffi.new("byte[%d]" % (self.size))
1309-
Qy = _ffi.new("byte[%d]" % (self.size))
1310-
d = _ffi.new("byte[%d]" % (self.size))
1306+
Qx = _ffi.new("byte[%d]" % self.size)
1307+
Qy = _ffi.new("byte[%d]" % self.size)
1308+
d = _ffi.new("byte[%d]" % self.size)
13111309
qx_size = _ffi.new("word32[1]")
13121310
qy_size = _ffi.new("word32[1]")
13131311
d_size = _ffi.new("word32[1]")
@@ -1450,7 +1448,7 @@ def decode_key(self, key):
14501448
Decodes an ED25519 public key
14511449
"""
14521450
key = t2b(key)
1453-
if (len(key) < _lib.wc_ed25519_pub_size(self.native_object)):
1451+
if len(key) < _lib.wc_ed25519_pub_size(self.native_object):
14541452
raise WolfCryptError("Key decode error: key too short")
14551453

14561454
idx = _ffi.new("word32*")
@@ -1537,7 +1535,7 @@ def decode_key(self, key, pub = None):
15371535
"""
15381536
key = t2b(key)
15391537

1540-
if (len(key) < _lib.wc_ed25519_priv_size(self.native_object)/2):
1538+
if len(key) < _lib.wc_ed25519_priv_size(self.native_object)/2:
15411539
raise WolfCryptError("Key decode error: key too short")
15421540

15431541
idx = _ffi.new("word32*")
@@ -1650,7 +1648,7 @@ def decode_key(self, key):
16501648
Decodes an ED448 public key
16511649
"""
16521650
key = t2b(key)
1653-
if (len(key) < _lib.wc_ed448_pub_size(self.native_object)):
1651+
if len(key) < _lib.wc_ed448_pub_size(self.native_object):
16541652
raise WolfCryptError("Key decode error: key too short")
16551653

16561654
idx = _ffi.new("word32*")
@@ -1743,7 +1741,7 @@ def decode_key(self, key, pub = None):
17431741
"""
17441742
key = t2b(key)
17451743

1746-
if (len(key) < _lib.wc_ed448_priv_size(self.native_object)/2):
1744+
if len(key) < _lib.wc_ed448_priv_size(self.native_object)/2:
17471745
raise WolfCryptError("Key decode error: key too short")
17481746

17491747
idx = _ffi.new("word32*")

0 commit comments

Comments
 (0)