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

Closed
wants to merge 6 commits into 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.

@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

@skongum02 skongum02 deleted the branch modular:main January 29, 2025 18:59
@skongum02 skongum02 closed this Jan 29, 2025
@skongum02 skongum02 reopened this Jan 29, 2025
@skongum02 skongum02 changed the base branch from nightly to main January 29, 2025 20:33
@JoeLoser
Copy link
Collaborator

!sync

@modularbot
Copy link
Collaborator

✅🟣 This contribution has been merged 🟣✅

Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the main branch during the next Mojo nightly release, typically within the next 24-48 hours.

We use Copybara to merge external contributions, click here to learn more.

@modularbot modularbot added the merged-internally Indicates that this pull request has been merged internally label Jan 31, 2025
@modularbot
Copy link
Collaborator

Landed in 9c6d9fa! Thank you for your contribution 🎉

@modularbot modularbot added the merged-externally Merged externally in public mojo repo label Feb 1, 2025
@modularbot modularbot closed this in 9c6d9fa Feb 1, 2025
modularbot pushed a commit that referenced this pull request Feb 13, 2025
…)` function (#54857)

[External] [stdlib] Add a new `validate` parameter to the `b64decode()`
function

Matching the `validate` bool argument in Python's
[base64.b64decode](https://docs.python.org/3/library/base64.html#base64.b64decode)
but a using comp time parameter so it will not add CPU cycles if
validation is not needed.

Co-authored-by: Manuel Saelices <[email protected]>
Closes #3929
MODULAR_ORIG_COMMIT_REV_ID: 10ee9bb8c9b339c8360afc75f2f28717188e954d
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. merged-externally Merged externally in public mojo repo merged-internally Indicates that this pull request has been merged internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants