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):
83
83
token = "{}.{}" .format (header , claims )
84
84
rsig = key .sign (token .encode ('utf8' ), ec .ECDSA (hashes .SHA256 ()))
85
85
(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 ))
87
87
return "{}.{}" .format (token , sig )
Original file line number Diff line number Diff line change @@ -26,11 +26,14 @@ def b64urlencode(data):
26
26
return base64 .urlsafe_b64encode (data ).replace (b'=' , b'' ).decode ('utf8' )
27
27
28
28
29
- def num_to_bytes (n ):
29
+ def num_to_bytes (n , pad_to ):
30
30
"""Returns the byte representation of an integer, in big-endian order.
31
31
:param n: The integer to encode.
32
32
:type n: int
33
+ :param pad_to: Expected length of result, zeropad if necessary.
34
+ :type pad_to: int
33
35
:returns bytes
34
36
"""
35
37
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