Skip to content

Fixes #2079: Update "From Base32" operation to support strict mode and custom padding #2082

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

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

Conversation

irebased
Copy link

@irebased irebased commented Jul 29, 2025

Description

This implements #2079

The From Base64 operation allows for a strict mode, and also allows removing the padding character from the alphabet. The From Base32 operation, on the other hand, is not aligned with this design and produces an "Invalid byte array".

This change updates the Base32 operation to include a strict mode, which enforces the same rules as the Base64 tool (adhering to Base32 expectations instead of Base64, such as a maximum of 6 padding characters). In non-strict mode, this allows the user to enter inputs that are not divisible by 8 while still producing a valid output, even without a padding character.

This change also enables users to provide custom padding characters instead of forcing =.

Example:

  • Input: "GE"
  • Alphabet: "A-Z2-7"
Existing result:
image
Result after this change:
image

How it works

  • Updates the default encoded character to be null instead of = to allow for the absence of a padding character
  • Updates the Base32 logic to allow for a custom padding character instead of hard-coding =
  • Only pushes a character to the byte array if it is between 0 and 256 to avoid pushing -1 and causing an invalid byte array
  • Strict mode forces the text to not be 5n + 1 in length as it is an invalid length for a Base32 string.

Testing

All unit tests for Base32 continue to pass after this change. I also tested the following inputs and got valid results:

  • "GE" with alphabet "A-Z2-7" produces output "1"
  • "JBSWY3DP" with alphabet "A-Z2-7" produces "Hello"
  • "O4" with alphabet "A-Z2-7" produces "04"
  • "04=======" produces error "Error: Invalid Base32 input length (9). Cannot be 8n+1, even without padding chars."
  • "..." produces error "Error: Base32 input contains non-alphabet char(s)"

References

See the Base64 implementation.

…o padding

The Base64 operation allows for a strict mode, and also allows for removing the padding character from the alphabet. Base32 on the other hand is not aligned with this design. This change updates the Base32 operation to include a strict mode which enforces the same rules as the Base64 tool (adhering to Base32 expectations instead of Base64, such as a maximum of 6 padding characters).

In non-strict mode, this allows the user to enter inputs that are not divisible by 8 while still producing an output, such as inputting "GE" to get the output "1" with alphabet "A-Z2-7" (no padding characer).

All unit tests for Base32 continue to pass after this change.
@CLAassistant
Copy link

CLAassistant commented Jul 29, 2025

CLA assistant check
All committers have signed the CLA.

@irebased irebased changed the title Fixes #2079: Update Base32 operation to support strict mode and no padding Fixes #2079: Update "From Base32" operation to support strict mode and no padding Jul 29, 2025
@irebased irebased changed the title Fixes #2079: Update "From Base32" operation to support strict mode and no padding Fixes #2079: Update "From Base32" operation to support strict mode and custom padding Jul 29, 2025
irebased and others added 2 commits July 29, 2025 00:08
…o padding

The Base64 operation allows for a strict mode, and also allows for removing the padding character from the alphabet. Base32 on the other hand is not aligned with this design. This change updates the Base32 operation to include a strict mode which enforces the same rules as the Base64 tool (adhering to Base32 expectations instead of Base64, such as a maximum of 6 padding characters).

In non-strict mode, this allows the user to enter inputs that are not divisible by 8 while still producing an output, such as inputting "GE" to get the output "1" with alphabet "A-Z2-7" (no padding characer).

All unit tests for Base32 continue to pass after this change.
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