8000 PR Comments · burhan/twilio-python@f59c211 · GitHub
[go: up one dir, main page]

Skip to content

Commit f59c211

Browse files
committed
PR Comments
1 parent 590a808 commit f59c211

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

twilio/jwt/__init__.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,38 @@ def _from_jwt(cls, headers, payload, key=None):
7777
def payload(self):
7878
if self.__decoded_payload:
7979
return self.__decoded_payload
80-
else:
81-
payload = self._generate_payload().copy()
82-
payload['iss'] = self.issuer
83-
payload['nbf'] = self.nbf or int(time.time())
84-
payload['exp'] = int(time.time()) + self.ttl
85-
if self.valid_until:
86-
payload['exp'] = self.valid_until
87-
if self.subject:
88-
payload['sub'] = self.subject
89-
90-
return payload
80+
81+
payload = self._generate_payload().copy()
82+
payload['iss'] = self.issuer
83+
payload['nbf'] = self.nbf or int(time.time())
84+
payload['exp'] = int(time.time()) + self.ttl
85+
if self.valid_until:
86+
payload['exp'] = self.valid_until
87+
if self.subject:
88+
payload['sub'] = self.subject
89+
90+
return payload
9191

9292
@property
9393
def headers(self):
9494
if self.__decoded_headers:
9595
return self.__decoded_headers
96-
else:
97-
headers = self._generate_headers().copy()
98-
headers['typ'] = 'JWT'
99-
headers['alg'] = self.algorithm
100-
return headers
96+
97+
headers = self._generate_headers().copy()
98+
headers['typ'] = 'JWT'
99+
headers['alg'] = self.algorithm
100+
return headers
101101

102102
def to_jwt(self, algorithm=None, ttl=None):
103103
"""
104-
Encode this Jwt object into a Jwt string
105-
:param str algorithm: override the algorithm used to encode the jwt
104+
Encode this JWT object into a JWT string
105+
:param str algorithm: override the algorithm used to encode the JWT
106106
:param int ttl: override the ttl configured in the constructor
107-
:rtype: str The Jwt string
107+
:rtype: str The JWT string
108108
"""
109109

110110
if not self.secret_key:
111-
raise ValueError('Jwt does not have a signing key configured.')
111+
raise ValueError('JWT does not have a signing key configured.')
112112

113113
headers = self.headers.copy()
114114
if algorithm:
@@ -124,11 +124,11 @@ def to_jwt(self, algorithm=None, ttl=None):
124124
@classmethod
125125
def from_jwt(cls, jwt, key=''):
126126
"""
127-
Decode a Jwt string into a Jwt object
128-
:param str jwt: jwt string
129-
:param Optional[str] key: key used to verify jwt signature, if not provided then validation
127+
Decode a JWT string into a Jwt object
128+
:param str jwt: JWT string
129+
:param Optional[str] key: key used to verify JWT signature, if not provided then validation
130130
is skipped.
131-
:raises JwtDecodeError if decoding jwt fails for any reason.
131+
:raises JwtDecodeError if decoding JWT fails for any reason.
132132
:return: A DecodedJwt object containing the jwt information.
133133
"""
134134
verify = True if key else False

twilio/jwt/compat.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
2-
3-
#
4-
# PyJWT expects hmac.compare_digest to exist for all Python 3.x, however it was added in Python > 3.3
5-
# Copied from: https://github.com/python/cpython/commit/6cea65555caf2716b4633827715004ab0291a282#diff-c49659257ec1b129707ce47a98adc96eL16
6-
#
71
def compare_digest(a, b):
8-
"""Returns the equivalent of 'a == b', but avoids content based short
9-
circuiting to reduce the vulnerability to timing attacks."""
2+
"""
3+
PyJWT expects hmac.compare_digest to exist for all Python 3.x, however it was added in Python > 3.3
4+
It has a fallback for Python 2.x but not for Pythons between 2.x and 3.3
5+
Copied from: https://github.com/python/cpython/commit/6cea65555caf2716b4633827715004ab0291a282#diff-c49659257ec1b129707ce47a98adc96eL16
6+
7+
Returns the equivalent of 'a == b', but avoids content based short
8+
circuiting to reduce the vulnerability to timing attacks.
9+
"""
1010
# Consistent timing matters more here than data type flexibility
1111
if not (isinstance(a, bytes) and isinstance(b, bytes)):
1212
raise TypeError("inputs must be bytes instances")

0 commit comments

Comments
 (0)
0