Skip to content

Commit f3ddd1a

Browse files
authored
Merge pull request #95 from roberthdevries/fix-various-boolean-expressions
Fix various boolean expressions involving None among others.
2 parents ab15863 + dc92410 commit f3ddd1a

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

wolfcrypt/ciphers.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,9 @@ def decrypt(self, string):
213213
string = t2b(string)
214214

215215
if not string:
216-
raise ValueError(
217-
"empty string not allowed")
216+
raise ValueError("empty string not allowed")
218217

219-
if len(string) % self.block_size and not self.mode == MODE_CTR and not "ChaCha" in self._native_type:
218+
if len(string) % self.block_size and self.mode != MODE_CTR and "ChaCha" not in self._native_type:
220219
raise ValueError(
221220
"string must be a multiple of %d in length" % self.block_size)
222221

@@ -498,15 +497,15 @@ def __init__(self, key="", size=32):
498497
self._dec = None
499498
self._key = None
500499
if len(key) > 0:
501-
if not size in self._key_sizes:
500+
if size not in self._key_sizes:
502501
raise ValueError("Invalid key size %d" % size)
503502
self._key = t2b(key)
504503
self.key_size = size
505504
self._IV_nonce = []
506505
self._IV_counter = 0
507506

508507
def _set_key(self, direction):
509-
if self._key == None:
508+
if self._key is None:
510509
return -1
511510
if self._enc:
512511
ret = _lib.wc_Chacha_SetKey(self._enc, self._key, len(self._key))
@@ -692,7 +691,7 @@ def _get_mgf(self):
692691

693692
class RsaPublic(_Rsa):
694693
def __init__(self, key=None, hash_type=None):
695-
if key != None:
694+
if key is not None:
696695
key = t2b(key)
697696
self._hash_type = hash_type
698697

@@ -830,7 +829,7 @@ def make_key(cls, size, rng=Random(), hash_type=None):
830829
Generates a new key pair of desired length **size**.
831830
"""
832831
rsa = cls(hash_type=hash_type)
833-
if rsa == None: # pragma: no cover
832+
if rsa is None: # pragma: no cover
834833
raise WolfCryptError("Invalid key error (%d)" % ret)
835834

836835
ret = _lib.wc_MakeRsaKey(rsa.native_object, size, 65537,
@@ -852,7 +851,7 @@ def __init__(self, key=None, hash_type=None): # pylint: disable=super-init-not-
852851
idx = _ffi.new("word32*")
853852
idx[0] = 0
854853

855-
if key != None:
854+
if key is not None:
856855
key = t2b(key)
857856
ret = _lib.wc_RsaPrivateKeyDecode(key, idx,
858857
self.native_object, len(key))
@@ -1622,7 +1621,7 @@ def verify(self, signature, data, ctx=None):
16221621
status = _ffi.new("int[1]")
16231622
ctx_buf = _ffi.NULL
16241623
ctx_buf_len = 0
1625-
if ctx != None:
1624+
if ctx is not None:
16261625
ctx_buf = t2b(ctx)
16271626
ctx_buf_len = len(ctx_buf)
16281627

@@ -1732,7 +1731,7 @@ def sign(self, plaintext, ctx=None):
17321731
signature_size[0] = self.max_signature_size
17331732
ctx_buf = _ffi.NULL
17341733
ctx_buf_len = 0
1735-
if (ctx != None):
1734+
if ctx is not None:
17361735
ctx_buf = t2b(ctx)
17371736
ctx_buf_len = len(ctx_buf)
17381737

0 commit comments

Comments
 (0)