Skip to content

Remove base64 dependency#459

Merged
santiagorodriguez96 merged 9 commits intomasterfrom
sr--encoder-refactor
May 23, 2025
Merged

Remove base64 dependency#459
santiagorodriguez96 merged 9 commits intomasterfrom
sr--encoder-refactor

Conversation

@santiagorodriguez96
Copy link
Copy Markdown
Contributor

@santiagorodriguez96 santiagorodriguez96 commented Apr 11, 2025

Motivation

Fixes #422.

Details

This PR introduces the new Encoders module in order to encapsulate the logic of the different encoding methods into the same place and let us re-use this logic in across all the different parts of the gem which will in turn allow us to cleanly (and finally) remove the base64 dependency. This logic was previously encapsulated in Encoder which now will just delegates encoding and decoding tasks to specific encoder classes defined in the new Encoders module - we are really just keeping it, just in case, for backward compatibility.

The new Encoders contains classes for Base64Encoder, Base64UrlEncoder, and NullEncoder and a lookup method to return the appropriate encoder class based on the encoding type.

Finally, it also updates the different parts of the gem where the base64 gem was used.

BREAKING CHANGE: The `STANDARD_ENCODING` const is now under `Encoders`
instead of `Encoder` which may lead to undefined const errors if you are
using this const for some reason.
…ment

Let's add it to `Encoders.new` for backward compatibility.
Comment thread lib/webauthn/encoders.rb
data = data.ljust((data.length + 3) & ~3, "=")
end

data = data.tr("-_", "+/")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed that in the base64 gem, the method tr has a bang in the if branch, but not in the else branch 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interesting! I'll open a separate PR to fix that 🙂

Copy link
Copy Markdown
Member

@nicolastemciuc nicolastemciuc left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks! ❤️

It is not a runtime dependency yet we were still using it in
`lib/webauthn/u2f_migrator.rb`.
That way we can avoid breaking changes. Let's change its namespace in
the future when we decide to release a new major version.
@santiagorodriguez96 santiagorodriguez96 merged commit d3ed671 into master May 23, 2025
11 checks passed
@santiagorodriguez96 santiagorodriguez96 deleted the sr--encoder-refactor branch May 23, 2025 18:27
This was referenced May 23, 2025
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.

base64 cleanup needed: U2fMigrator still calls Base64 methods, and a require exists

2 participants