Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore whitespace in Base64.from_encoded #108

Closed
robin-nitrokey opened this issue Mar 15, 2024 · 0 comments · Fixed by #118
Closed

Ignore whitespace in Base64.from_encoded #108

robin-nitrokey opened this issue Mar 15, 2024 · 0 comments · Fixed by #118
Labels
enhancement New feature or request

Comments

@robin-nitrokey
Copy link
Member

The base64 tool wraps lines after 76 characters. This can be disabled with the --wrap=0 option, but we could also just ignore whitespace when creating base64 data.

@classmethod
def from_encoded(cls, data: Union[bytes, str]) -> "Base64":
try:
b64decode(data, validate=True)
if isinstance(data, bytes):
data = data.decode()
return cls(data=data)
except binascii.Error:
raise ValueError(f"Invalid base64 data: {data!r}")

@robin-nitrokey robin-nitrokey added the enhancement New feature or request label Mar 15, 2024
robin-nitrokey added a commit that referenced this issue May 3, 2024
This patch makes it easy to ignore whitespace in Base64 input, e. g.
generated by the base64 tool without the --wrap=0 option.

Fixes: #108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant