Fixes #2079: Update Base32 operation to support strict mode and no 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.
This commit is contained in:
The Winter Soldier 2025-07-29 00:08:52 -07:00
parent 0470319e54
commit c2df522646

View file

@ -61,7 +61,7 @@ export function fromBase32(data, alphabet="A-Z0-7=", returnType="string", remove
if (strictMode) {
// Check for incorrect lengths (even without padding)
if (data.length % 8 === 1) {
throw new OperationError(`Error: Invalid Base32 input length (${data.length}). Cannot be 5n+1, even without padding chars.`);
throw new OperationError(`Error: Invalid Base32 input length (${data.length}). Cannot be 8n+1, even without padding chars.`);
}
if (alphabet.length === 33) { // Padding character included