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
mrismanaziz authored Jan 5, 2022
1 parent 7eb8835 commit 699ff18
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions helper_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ async def is_subscribed(filter, client, update):

async def encode(string):
string_bytes = string.encode("ascii")
base64_bytes = base64.b64encode(string_bytes)
return 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)
return string_bytes.decode("ascii")
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


async def get_messages(client, message_ids):
Expand Down

0 comments on commit 699ff18

Please sign in to comment.