Fixes #2079: Update "From Base32" operation to support strict mode and custom padding #2082
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Existing result:
Result after this change:
How it works
null
instead of=
to allow for the absence of a padding character=
-1
and causing an invalid byte array5n + 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:
References
See the Base64 implementation.