@@ -21,6 +21,12 @@ def b64urldecode(data):
2121 return base64 .urlsafe_b64decode (data + "====" [:len (data ) % 4 ])
2222
2323
24+ def b64urlencode (bstring ):
25+ return binascii .b2a_base64 (
26+ bstring ).decode ('utf8' ).replace ('\n ' , '' ).replace (
27+ '+' , '-' ).replace ('/' , '_' ).replace ('=' , '' )
28+
29+
2430class VapidException (Exception ):
2531 """An exception wrapper for Vapid."""
2632 pass
@@ -205,11 +211,6 @@ def _base_sign(self, claims):
205211 "'sub' is your admin email as a mailto: link." )
206212 return claims
207213
208- def encode (self , bstring ):
209- return binascii .b2a_base64 (
210- bstring ).decode ('utf8' ).replace ('\n ' , '' ).replace (
211- '+' , '-' ).replace ('/' , '_' ).replace ('=' , '' )
212-
213214 def sign (self , claims , crypto_key = None ):
214215 """Sign a set of claims.
215216 :param claims: JSON object containing the JWT claims to use.
@@ -228,7 +229,7 @@ def sign(self, claims, crypto_key=None):
228229 pubkey = self .public_key .to_string ()
229230 if len (pubkey ) == 64 :
230231 pubkey = b'\04 ' + pubkey
231- pkey += self . encode (pubkey )
232+ pkey += b64urlencode (pubkey )
232233 if crypto_key :
233234 crypto_key = crypto_key + ';' + pkey
234235 else :
@@ -257,7 +258,7 @@ def sign(self, claims, crypto_key=None):
257258 "Authorization" : "{schema} t={t},k={k}" .format (
258259 schema = self ._schema ,
259260 t = sig ,
260- k = self . encode (pkey )
261+ k = b64urlencode (pkey )
261262 )
262263 }
263264
0 commit comments