auto_b64decode¶
-
privex.helpers.crypto.base.
auto_b64decode
(data: Union[str, bytes], urlsafe: bool = True) → bytes[source]¶ Determines if
data
is base64 encoded. If it is, then it will decode it and return the decoded bytes. Otherwise, it will return the original data as bytes.Example usage
>>> a = b'dGVzdGluZw==' >>> b = 'hello world' >>> auto_b64decode(a) # This is detected to be Base64 encoded, and so the decoded data is returned b'testing' >>> auto_b64decode(b) # This does not appear to be Base64, and so is returned as normal (but as bytes) b'hello world'
- Parameters
data (str|bytes) – Data to check for base64, and decode if required
urlsafe (bool) – (Default:
True
) Usebase64.urlsafe_b64decode()
, instead of plainbase64.b64decode()
- Return bytes data
If
data
was base64, this will be the decoded bytes. Otherwise, the original data as bytes.