OXIESEC PANEL
- Current Dir:
/
/
snap
/
certbot
/
4730
/
lib
/
python3.12
/
site-packages
/
josepy
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
06/10/2025 09:51:16 PM
rwxr-xr-x
📄
__init__.py
1.64 KB
06/10/2025 09:51:03 PM
rw-r--r--
📁
__pycache__
-
06/10/2025 09:51:14 PM
rwxr-xr-x
📄
b64.py
1.46 KB
06/10/2025 09:51:03 PM
rw-r--r--
📄
errors.py
792 bytes
06/10/2025 09:51:03 PM
rw-r--r--
📄
interfaces.py
7.61 KB
06/10/2025 09:51:03 PM
rw-r--r--
📄
json_util.py
18.61 KB
06/10/2025 09:51:03 PM
rw-r--r--
📄
jwa.py
7.31 KB
06/10/2025 09:51:03 PM
rw-r--r--
📄
jwk.py
13.66 KB
06/10/2025 09:51:03 PM
rw-r--r--
📄
jws.py
15.49 KB
06/10/2025 09:51:03 PM
rw-r--r--
📄
magic_typing.py
557 bytes
06/10/2025 09:51:03 PM
rw-r--r--
📄
py.typed
0 bytes
06/10/2025 09:51:03 PM
rw-r--r--
📄
util.py
8.27 KB
06/10/2025 09:51:03 PM
rw-r--r--
Editing: b64.py
Close
"""`JOSE Base64`_ is defined as: - URL-safe Base64 - padding stripped .. _`JOSE Base64`: https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-37#appendix-C .. Do NOT try to call this module "base64", as it will "shadow" the standard library. """ import base64 from typing import Union def b64encode(data: bytes) -> bytes: """JOSE Base64 encode. :param data: Data to be encoded. :type data: bytes :returns: JOSE Base64 string. :rtype: bytes :raises TypeError: if ``data`` is of incorrect type """ if not isinstance(data, bytes): raise TypeError("argument should be bytes") return base64.urlsafe_b64encode(data).rstrip(b"=") def b64decode(data: Union[bytes, str]) -> bytes: """JOSE Base64 decode. :param data: Base64 string to be decoded. If it's unicode, then only ASCII characters are allowed. :type data: bytes or unicode :returns: Decoded data. :rtype: bytes :raises TypeError: if input is of incorrect type :raises ValueError: if input is unicode with non-ASCII characters """ if isinstance(data, str): try: data = data.encode("ascii") except UnicodeEncodeError: raise ValueError("unicode argument should contain only ASCII characters") elif not isinstance(data, bytes): raise TypeError("argument should be a str or unicode") return base64.urlsafe_b64decode(data + b"=" * (4 - (len(data) % 4)))