__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
"""`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)))
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 1.91 KB | 0644 |
|
| b64.py | File | 1.45 KB | 0644 |
|
| errors.py | File | 791 B | 0644 |
|
| interfaces.py | File | 7.61 KB | 0644 |
|
| json_util.py | File | 18.11 KB | 0644 |
|
| jwa.py | File | 7.31 KB | 0644 |
|
| jwk.py | File | 13.66 KB | 0644 |
|
| jws.py | File | 15.13 KB | 0644 |
|
| magic_typing.py | File | 556 B | 0644 |
|
| py.typed | File | 0 B | 0644 |
|
| util.py | File | 9.81 KB | 0644 |
|