Skip to content

Commit

Permalink
strip = sign at the end of b64 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
subinps authored Jan 5, 2022
1 parent 0ed4723 commit f6b1897
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions helper_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ async def is_subscribed(filter, client, update):

async def encode(string):
string_bytes = string.encode("ascii")
base64_bytes = base64.b64encode(string_bytes)
base64_string = base64_bytes.decode("ascii")
base64_bytes = base64.urlsafe_b64encode(string_bytes)
base64_string = (base64_bytes.decode("ascii")).strip("=")
return base64_string

async def decode(base64_string):
base64_bytes = base64_string.encode("ascii")
string_bytes = base64.b64decode(base64_bytes)
base64_string = base64_string.strip("=") # links generated before this commit will be having = sign, hence striping them to handle padding errors.
base64_bytes = (base64_string + "=" * (-len(base64_string) % 4)).encode("ascii")
string_bytes = base64.urlsafe_b64decode(base64_bytes)
string = string_bytes.decode("ascii")
return string

Expand Down

0 comments on commit f6b1897

Please sign in to comment.