Skip to content

Commit 70faf31

Browse files
committed
Fix all flake8 issues except for E501 (line too long)
1 parent 6b3d557 commit 70faf31

File tree

16 files changed

+157
-79
lines changed

16 files changed

+157
-79
lines changed

jose/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__copyright__ = 'Copyright 2016 Michael Davis'
66

77

8-
from .exceptions import JOSEError
9-
from .exceptions import JWSError
10-
from .exceptions import ExpiredSignatureError
11-
from .exceptions import JWTError
8+
from .exceptions import JOSEError # noqa: F401
9+
from .exceptions import JWSError # noqa: F401
10+
from .exceptions import ExpiredSignatureError # noqa: F401
11+
from .exceptions import JWTError # noqa: F401

jose/backends/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
try:
3-
from jose.backends.pycrypto_backend import RSAKey
3+
from jose.backends.pycrypto_backend import RSAKey # noqa: F401
44
except ImportError:
55
try:
6-
from jose.backends.cryptography_backend import CryptographyRSAKey as RSAKey
6+
from jose.backends.cryptography_backend import CryptographyRSAKey as RSAKey # noqa: F401
77
except ImportError:
8-
from jose.backends.rsa_backend import RSAKey
8+
from jose.backends.rsa_backend import RSAKey # noqa: F401
99

1010
try:
11-
from jose.backends.cryptography_backend import CryptographyECKey as ECKey
11+
from jose.backends.cryptography_backend import CryptographyECKey as ECKey # noqa: F401
1212
except ImportError:
13-
from jose.backends.ecdsa_backend import ECDSAECKey as ECKey
13+
from jose.backends.ecdsa_backend import ECDSAECKey as ECKey # noqa: F401

jose/backends/cryptography_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def sign(self, msg):
9393
if self.hash_alg.digest_size * 8 > self.prepared_key.curve.key_size:
9494
raise TypeError("this curve (%s) is too short "
9595
"for your digest (%d)" % (self.prepared_key.curve.name,
96-
8*self.hash_alg.digest_size))
96+
8 * self.hash_alg.digest_size))
9797
signature = self.prepared_key.sign(msg, ec.ECDSA(self.hash_alg()))
9898
order = (2 ** self.prepared_key.curve.key_size) - 1
9999
return sigencode_string(*sigdecode_der(signature, order), order=order)
@@ -104,7 +104,7 @@ def verify(self, msg, sig):
104104
try:
105105
self.prepared_key.verify(signature, msg, ec.ECDSA(self.hash_alg()))
106106
return True
107-
except:
107+
except Exception:
108108
return False
109109

110110
def is_public(self):

jose/backends/ecdsa_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def sign(self, msg):
9696
def verify(self, msg, sig):
9797
try:
9898
return self.prepared_key.verify(sig, msg, hashfunc=self.hash_alg, sigdecode=ecdsa.util.sigdecode_string)
99-
except:
99+
except Exception:
100100
return False
101101

102102
def is_public(self):

jose/backends/pycrypto_backend.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
_RSAKey = RSA.RsaKey
2424
else:
2525
_RSAKey = RSA._RSAobj
26-
2726

2827

2928
class RSAKey(Key):

jose/backends/rsa_backend.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
# to enable pure python rsa module to be in compliance with section 6.3.1 of RFC7518
1818
# which requires only private exponent (d) for private key.
1919

20+
2021
def _gcd(a, b):
2122
"""Calculate the Greatest Common Divisor of a and b.
2223
2324
Unless b==0, the result will have the same sign as b (so that when
2425
b is divided by it, the result comes out positive).
2526
"""
2627
while b:
27-
a, b = b, a%b
28+
a, b = b, (a % b)
2829
return a
2930

3031

@@ -138,7 +139,7 @@ def _process_jwk(self, jwk_dict):
138139
e = base64_to_long(jwk_dict.get('e'))
139140
n = base64_to_long(jwk_dict.get('n'))
140141

141-
if not 'd' in jwk_dict:
142+
if 'd' not in jwk_dict:
142143
return pyrsa.PublicKey(e=e, n=n)
143144
else:
144145
d = base64_to_long(jwk_dict.get('d'))
@@ -159,8 +160,6 @@ def _process_jwk(self, jwk_dict):
159160
p, q = _rsa_recover_prime_factors(n, e, d)
160161
return pyrsa.PrivateKey(n=n, e=e, d=d, p=p, q=q)
161162

162-
163-
164163
def sign(self, msg):
165164
return pyrsa.sign(msg, self._prepared_key, self.hash_alg)
166165

jose/jwk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from jose.backends.base import Key
1111

1212
try:
13-
from jose.backends import RSAKey
13+
from jose.backends import RSAKey # noqa: F401
1414
except ImportError:
1515
pass
1616

1717
try:
18-
from jose.backends import ECKey
18+
from jose.backends import ECKey # noqa: F401
1919
except ImportError:
2020
pass
2121

@@ -26,10 +26,10 @@ def get_key(algorithm):
2626
elif algorithm in ALGORITHMS.HMAC:
2727
return HMACKey
2828
elif algorithm in ALGORITHMS.RSA:
29-
from jose.backends import RSAKey
29+
from jose.backends import RSAKey # noqa: F811
3030
return RSAKey
3131
elif algorithm in ALGORITHMS.EC:
32-
from jose.backends import ECKey
32+
from jose.backends import ECKey # noqa: F811
3333
return ECKey
3434
return None
3535

jose/jws.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _sig_matches_keys(keys, signing_input, signature, alg):
211211
try:
212212
if key.verify(signing_input, signature):
213213
return True
214-
except:
214+
except Exception:
215215
pass
216216
return False
217217

@@ -250,18 +250,18 @@ def _get_keys(key):
250250

251251
def _verify_signature(signing_input, header, signature, key='', algorithms=None):
252252

253-
alg = header.get('alg')
254-
if not alg:
255-
raise JWSError('No algorithm was specified in the JWS header.')
253+
alg = header.get('alg')
254+
if not alg:
255+
raise JWSError('No algorithm was specified in the JWS header.')
256256

257-
if algorithms is not None and alg not in algorithms:
258-
raise JWSError('The specified alg value is not allowed')
257+
if algorithms is not None and alg not in algorithms:
258+
raise JWSError('The specified alg value is not allowed')
259259

260-
keys = _get_keys(key)
261-
try:
262-
if not _sig_matches_keys(keys, signing_input, signature, alg):
263-
raise JWSSignatureError()
264-
except JWSSignatureError:
265-
raise JWSError('Signature verification failed.')
266-
except JWSError:
267-
raise JWSError('Invalid or unsupported algorithm: %s' % alg)
260+
keys = _get_keys(key)
261+
try:
262+
if not _sig_matches_keys(keys, signing_input, signature, alg):
263+
raise JWSSignatureError()
264+
except JWSSignatureError:
265+
raise JWSError('Signature verification failed.')
266+
except JWSError:
267+
raise JWSError('Invalid or unsupported algorithm: %s' % alg)

jose/jwt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
import binascii
32
import json
43

54
from calendar import timegm
@@ -168,7 +167,7 @@ def get_unverified_header(token):
168167
"""
169168
try:
170169
headers = jws.get_unverified_headers(token)
171-
except:
170+
except Exception:
172171
raise JWTError('Error decoding token headers.')
173172

174173
return headers
@@ -206,7 +205,7 @@ def get_unverified_claims(token):
206205
"""
207206
try:
208207
claims = jws.get_unverified_claims(token)
209-
except:
208+
except Exception:
210209
raise JWTError('Error decoding token claims.')
211210

212211
try:
@@ -384,6 +383,7 @@ def _validate_sub(claims, subject=None):
384383
if claims.get('sub') != subject:
385384
raise JWTClaimsError('Invalid subject')
386385

386+
387387
def _validate_jti(claims):
388388
"""Validates that the 'jti' claim is valid.
389389
@@ -433,7 +433,7 @@ def _validate_at_hash(claims, access_token, algorithm):
433433
except (TypeError, ValueError):
434434
msg = 'Unable to calculate at_hash to verify against token claims.'
435435
raise JWTClaimsError(msg)
436-
436+
437437
if claims['at_hash'] != expected_hash:
438438
raise JWTClaimsError('at_hash claim does not match access_token.')
439439

tests/algorithms/test_EC.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def test_verify(self, Backend):
107107
signature = key.sign(msg)
108108
public_key = key.public_key()
109109

110-
assert public_key.verify(msg, signature) == True
111-
assert public_key.verify(msg, b'not a signature') == False
110+
assert bool(public_key.verify(msg, signature))
111+
assert not bool(public_key.verify(msg, b'not a signature'))
112112

113113
def assert_parameters(self, as_dict, private):
114114
assert isinstance(as_dict, dict)

0 commit comments

Comments
 (0)