[docs]def__init__(self,data:bytes):""" Initializes the object. If the provided data is already in base64 encoded format, it will store it. If the data is a regular byte string, it will encode and then store it. """ifself.is_base64(data):self._data=str(data,"utf-8")else:encoded=base64.b64encode(data)self._data=str(encoded,"utf-8")
[docs]@staticmethoddefis_base64(data:bytes)->bool:"""Checks if given data is base64 encoded."""try:str_data=str(data,"utf-8")_=base64.urlsafe_b64decode(str_data.strip("=")+"===")returnTrueexceptbinascii.Error:returnFalse
[docs]defget_encoded(self)->str:"""Returns the stored base64 encoded data."""returnself._data
[docs]defget_decoded(self)->bytes:"""Returns the decoded byte string."""returnbase64.urlsafe_b64decode(self._data.strip("=")+"===")