AAS HTTP Client Documentation
Loading...
Searching...
No Matches
encoder.py
Go to the documentation of this file.
1"""Encoder module.
2
3Provides some helper methods for base 64 encoding.
4"""
5
6import base64
7
8
9def decode_base_64(text: str) -> str:
10 """Decode a Base64 encoded string.
11
12 :param text: Base64 encoded string to decode
13 :return: Decoded string
14 """
15 missing_padding = len(text) % 4
16 if missing_padding:
17 text += "=" * (4 - missing_padding)
18
19 decoded = base64.urlsafe_b64decode(text)
20 return decoded.decode("utf-8")
21
22
23def encode_base_64(text: str) -> str:
24 """Encode a string to Base64.
25
26 :param text: String to encode
27 :return: Base64 encoded string
28 """
29 encoded_bytes = base64.urlsafe_b64encode(text.encode("utf-8")).rstrip(b"=")
30 return encoded_bytes.decode("utf-8")
str decode_base_64(str text)
Decode a Base64 encoded string.
Definition encoder.py:14