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

Enhancement encoder #448

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Kaakati
Copy link

@Kaakati Kaakati commented Dec 24, 2024

  • Separated configuration into a Config module
  • Created smaller, focused methods following KISS principle
  • Used Ruby's built-in Base64 module instead of manual string manipulation
  • Added custom error class for better error handling
  • Improved method names for better readability
  • Removed redundant comments and added meaningful method names
  • Used proper Ruby idioms like send for dynamic method calling

Copy link
Contributor

@santiagorodriguez96 santiagorodriguez96 left a comment

Choose a reason for hiding this comment

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

Hey @Kaakati! Thank you so much for your contribution! 👋

Sorry for the delayed response. Left a couple of comments 🙂

# @param data [String] the data to encode
# @return [String] Base64 encoded data
def encode_base64(data)
Base64.strict_encode64(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +4 to +17
module Config
module Encoder
# Default encoding type used for WebAuthn operations
DEFAULT_ENCODING = :base64url

# Supported encoding types and their corresponding Base64 methods
ENCODINGS = {
base64: :strict,
base64url: :urlsafe
}.freeze

# Error message template for unsupported encoding types
INVALID_ENCODING_ERROR = "Unsupported or unknown encoding: %s".freeze
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just moving these constants inside Webauthn::Encoder?

# Encode data using URL-safe Base64 encoding without padding
# @param data [String] the data to encode
# @return [String] URL-safe Base64 encoded data
def encode_base64url(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice to have these methods public in some way, so that they can be used in our specs to encode/decode data and we can remove the base64 dependency altogether – see this PR.

Comment on lines +10 to +13
ENCODINGS = {
base64: :strict,
base64url: :urlsafe
}.freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

We are not using the values of this hash right? Why not just storing the encodings as an array?

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.

2 participants