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

[stdlib] Add a new validate parameter to the b64decode() function #3929

Open
wants to merge 6 commits into
base: nightly
Choose a base branch
from

Conversation

msaelices
Copy link
Contributor

Matching the validate bool argument in Python's base64.b64decode but a using comp time parameter so it will not add CPU cycles if validation is not needed.

Signed-off-by: Manuel Saelices <msaelices@gmail.com>
@msaelices msaelices requested a review from a team as a code owner January 6, 2025 22:45
@msaelices msaelices changed the title [stdlib] Add a new validate parameter to the b64decode() function [stdlib] Add a new validate parameter to the b64decode() function Jan 6, 2025
Copy link
Collaborator

@JoeLoser JoeLoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, happy to sync it once the minor comments are addressed. Thanks!

@parameter
if validate:
if n % 4 != 0:
raise Error("ValueError: Input length must be divisible by 4")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion Include the byte length value (n) in the error message.

@parameter
if validate:
if a < 0 or b < 0 or c < 0 or d < 0:
raise Error("ValueError: Unexpected character encountered")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion Include the unexpected character value in the error message.

This may mean pulling the snippet out into a local function and call it for each of the values a, b, c, and d.

@msaelices
Copy link
Contributor Author

LGTM, happy to sync it once the minor comments are addressed. Thanks!

Thanks. I've fixed both of them here: msaelices@c1873d6

Could you please TAL?

@msaelices msaelices requested a review from JoeLoser January 21, 2025 13:47
@JoeLoser
Copy link
Collaborator

LGTM, happy to sync it once the minor comments are addressed. Thanks!

Thanks. I've fixed both of them here: msaelices@c1873d6

Could you please TAL?

Nice improvement, thanks! Syncing now.

@JoeLoser
Copy link
Collaborator

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Jan 22, 2025
@JoeLoser
Copy link
Collaborator

@msaelices do you mind rebasing with latest nightly so I can sync this? Thanks!

@msaelices
Copy link
Contributor Author

@msaelices do you mind rebasing with latest nightly so I can sync this? Thanks!

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported-internally Signals that a given pull request has been imported internally.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants