File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -166,10 +166,7 @@ def b64d(b):
166166 :param b: bytes
167167 """
168168
169- if b .endswith (b'=' ): # shouldn't but there you are
170- cb = b .split (b'=' )[0 ]
171- else :
172- cb = b
169+ cb = b .rstrip (b"=" ) # shouldn't but there you are
173170
174171 # Python's base64 functions ignore invalid characters, so we need to
175172 # check for them explicitly.
Original file line number Diff line number Diff line change 1+ import base64
12import os
23import struct
3- from jwkest import long2intarr
4+ from jwkest import long2intarr , b64d , b64e
45from jwkest import intarr2long
56from jwkest import base64_to_long
67from jwkest import long_to_base64
1415def full_path (local_file ):
1516 return os .path .join (BASEDIR , local_file )
1617
18+
1719CERT = full_path ("cert.pem" )
1820KEY = full_path ("server.key" )
1921
2022_CKEY = pem_cert2rsa (CERT )
2123
24+
2225def test_long_intarr_long ():
2326 ia = long2intarr (_CKEY .n )
2427 _n = intarr2long (ia )
@@ -39,5 +42,16 @@ def test_long_base64_long():
3942 assert _CKEY .n == l
4043
4144
45+ def test_b64d_with_padded_data ():
46+ data = "abcd" .encode ("utf-8" )
47+ encoded = base64 .urlsafe_b64encode (data )
48+ assert b64d (encoded ) == data
49+
50+
51+ def test_b64_encode_decode ():
52+ data = "abcd" .encode ("utf-8" )
53+ assert b64d (b64e (data )) == data
54+
55+
4256if __name__ == "__main__" :
43- test_long_base64_long ()
57+ test_long_base64_long ()
You can’t perform that action at this time.
0 commit comments