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

Simplify base64URLStringToBuffer padding #566

Closed
wants to merge 1 commit into from

Conversation

qalandarov
Copy link

No description provided.

* (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
* (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
*/
const padLength = (4 - (base64.length % 4)) % 4;
Copy link

@lesha-co lesha-co May 16, 2024

Choose a reason for hiding this comment

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

I actually like padEnd approach better because padEnd is there so you don't have to write a while loop and avoid multiple assignments and multiple concatenations

the only thing I'd change there is I would remove the last % 4

I do realize though that impact here is minuscule as the loop runs at most two times


// Pad with '=' until it's a multiple of four
while (base64.length % 4 != 0) {
base64 += "=";

Choose a reason for hiding this comment

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

Actually, did you know that atob() works with un-padded base64 strings? check this out:

> btoa("padding")
'cGFkZGluZw=='
> atob("cGFkZGluZw")
'padding'

because if it's trivial to calculate amount of padding needed, it's trivial to change decoding logic to not need any padding.

I'd say it's not really needed here

@MasterKale
Copy link
Owner

Thank you for your effort @qalandarov but this project is currently not open to external contributions as per the README. If you believe you have found an issue or identified an optimization then please open a new issue to begin discussing it.

@MasterKale MasterKale closed this May 16, 2024
@lesha-co
Copy link

I just gotta ask, is this because of xz incident last month?

@MasterKale
Copy link
Owner

It's typically because reviewing PRs from external contributors takes time and energy and isn't fun for me when I do so much of that as my day job.

And sometimes, if I don't feel like reviewing something right away, I think it can seem disrespectful for making the potential contributor wait when really I just haven't found time to thoroughly review the content of their PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants