Skip to content

Commit e48fb07

Browse files
authored
Merge pull request #113 from roberthdevries/remove-redundant-stuff
Remove redundant parentheses and bytes() calls.
2 parents 87fbbe5 + 17dad74 commit e48fb07

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
@@ -829,8 +829,7 @@ def verify_pss(self, plaintext, signature):
829829
Returns a string containing the plaintext.
830830
"""
831831
if not self._hash_type:
832-
raise WolfCryptError(("Hash type not set. Cannot verify a "
833-
"PSS signature without a hash type."))
832+
raise WolfCryptError("Hash type not set. Cannot verify a PSS signature without a hash type.")
834833

835834
hash_cls = hash_type_to_cls(self._hash_type)
836835
if not hash_cls:
@@ -1025,8 +1024,7 @@ def sign_pss(self, plaintext):
10251024
Returns a string containing the signature.
10261025
"""
10271026
if not self._hash_type:
1028-
raise WolfCryptError(("Hash type not set. Cannot verify a "
1029-
"PSS signature without a hash type."))
1027+
raise WolfCryptError("Hash type not set. Cannot verify a PSS signature without a hash type.")
10301028

10311029
hash_cls = hash_type_to_cls(self._hash_type)
10321030
if not hash_cls:
@@ -1131,8 +1129,8 @@ def encode_key_raw(self):
11311129
11321130
Returns (Qx, Qy)
11331131
"""
1134-
Qx = _ffi.new("byte[%d]" % (self.size))
1135-
Qy = _ffi.new("byte[%d]" % (self.size))
1132+
Qx = _ffi.new("byte[%d]" % self.size)
1133+
Qy = _ffi.new("byte[%d]" % self.size)
11361134
qx_size = _ffi.new("word32[1]")
11371135
qy_size = _ffi.new("word32[1]")
11381136
qx_size[0] = self.size
@@ -1308,9 +1306,9 @@ def encode_key_raw(self):
13081306
13091307
Returns (Qx, Qy, d)
13101308
"""
1311-
Qx = _ffi.new("byte[%d]" % (self.size))
1312-
Qy = _ffi.new("byte[%d]" % (self.size))
1313-
d = _ffi.new("byte[%d]" % (self.size))
1309+
Qx = _ffi.new("byte[%d]" % self.size)
1310+
Qy = _ffi.new("byte[%d]" % self.size)
1311+
d = _ffi.new("byte[%d]" % self.size)
13141312
qx_size = _ffi.new("word32[1]")
13151313
qy_size = _ffi.new("word32[1]")
13161314
d_size = _ffi.new("word32[1]")
@@ -1453,7 +1451,7 @@ def decode_key(self, key):
14531451
Decodes an ED25519 public key
14541452
"""
14551453
key = t2b(key)
1456-
if (len(key) < _lib.wc_ed25519_pub_size(self.native_object)):
1454+
if len(key) < _lib.wc_ed25519_pub_size(self.native_object):
14571455
raise WolfCryptError("Key decode error: key too short")
14581456

14591457
idx = _ffi.new("word32*")
@@ -1540,7 +1538,7 @@ def decode_key(self, key, pub = None):
15401538
"""
15411539
key = t2b(key)
15421540

1543-
if (len(key) < _lib.wc_ed25519_priv_size(self.native_object)/2):
1541+
if len(key) < _lib.wc_ed25519_priv_size(self.native_object)/2:
15441542
raise WolfCryptError("Key decode error: key too short")
15451543

15461544
idx = _ffi.new("word32*")
@@ -1653,7 +1651,7 @@ def decode_key(self, key):
16531651
Decodes an ED448 public key
16541652
"""
16551653
key = t2b(key)
1656-
if (len(key) < _lib.wc_ed448_pub_size(self.native_object)):
1654+
if len(key) < _lib.wc_ed448_pub_size(self.native_object):
16571655
raise WolfCryptError("Key decode error: key too short")
16581656

16591657
idx = _ffi.new("word32*")
@@ -1746,7 +1744,7 @@ def decode_key(self, key, pub = None):
17461744
"""
17471745
key = t2b(key)
17481746

1749-
if (len(key) < _lib.wc_ed448_priv_size(self.native_object)/2):
1747+
if len(key) < _lib.wc_ed448_priv_size(self.native_object)/2:
17501748
raise WolfCryptError("Key decode error: key too short")
17511749

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

0 commit comments

Comments
 (0)