This commit is contained in:
Christian Mantha
2026-03-02 19:10:52 -05:00
commit 2ca0b9ef7c
28907 changed files with 5233713 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
from base64 import b64encode, b64decode
import binascii
__all__ = ["base64", "unbase64"]
Base64String = str
def base64(s: str) -> Base64String:
"""Encode the string s using Base64."""
b: bytes = s.encode("utf-8") if isinstance(s, str) else s
return b64encode(b).decode("ascii")
def unbase64(s: Base64String) -> str:
"""Decode the string s using Base64."""
try:
b: bytes = s.encode("ascii") if isinstance(s, str) else s
except UnicodeEncodeError:
return ""
try:
return b64decode(b).decode("utf-8")
except (binascii.Error, UnicodeDecodeError):
return ""