File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -83,5 +83,5 @@ def sign(claims, key):
8383 token = "{}.{}" .format (header , claims )
8484 rsig = key .sign (token .encode ('utf8' ), ec .ECDSA (hashes .SHA256 ()))
8585 (r , s ) = utils .decode_dss_signature (rsig )
86- sig = b64urlencode (num_to_bytes (r ) + num_to_bytes (s ))
86+ sig = b64urlencode (num_to_bytes (r , 32 ) + num_to_bytes (s , 32 ))
8787 return "{}.{}" .format (token , sig )
Original file line number Diff line number Diff line change @@ -26,11 +26,14 @@ def b64urlencode(data):
2626 return base64 .urlsafe_b64encode (data ).replace (b'=' , b'' ).decode ('utf8' )
2727
2828
29- def num_to_bytes (n ):
29+ def num_to_bytes (n , pad_to ):
3030 """Returns the byte representation of an integer, in big-endian order.
3131 :param n: The integer to encode.
3232 :type n: int
33+ :param pad_to: Expected length of result, zeropad if necessary.
34+ :type pad_to: int
3335 :returns bytes
3436 """
3537 h = '%x' % n
36- return binascii .unhexlify ('0' * (len (h ) % 2 ) + h )
38+ r = binascii .unhexlify ('0' * (len (h ) % 2 ) + h )
39+ return b'\x00 ' * (pad_to - len (r )) + r
You can’t perform that action at this time.
0 commit comments