Merge pull request #1991 from peterc-s/master
Some checks are pending
CodeQL Analysis / Analyze (push) Waiting to run
Master Build, Test & Deploy / main (push) Waiting to run

Add Base32 Hex Extended Alphabet and Base32 Tests.
This commit is contained in:
a3957273 2025-04-05 05:57:56 +01:00 committed by GitHub
commit 74d631c71e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 214 additions and 4 deletions

23
src/core/lib/Base32.mjs Normal file
View file

@ -0,0 +1,23 @@
// import Utils from "../Utils.mjs";
/**
* Base32 resources.
*
* @author Peter C-S [petercs@purelymail.com]
* @license Apache-2.0
*/
/**
* Base32 alphabets.
*/
export const ALPHABET_OPTIONS = [
{
name: "Standard", // https://www.rfc-editor.org/rfc/rfc4648#section-6
value: "A-Z2-7=",
},
{
name: "Hex Extended", // https://www.rfc-editor.org/rfc/rfc4648#section-7
value: "0-9A-V=",
},
];

View file

@ -6,6 +6,8 @@
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
/**
* From Base32 operation
@ -27,8 +29,8 @@ class FromBase32 extends Operation {
this.args = [
{
name: "Alphabet",
type: "binaryString",
value: "A-Z2-7="
type: "editableOption",
value: ALPHABET_OPTIONS
},
{
name: "Remove non-alphabet chars",
@ -41,6 +43,11 @@ class FromBase32 extends Operation {
pattern: "^(?:[A-Z2-7]{8})+(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}={1})?$",
flags: "",
args: ["A-Z2-7=", false]
},
{
pattern: "^(?:[0-9A-V]{8})+(?:[0-9A-V]{2}={6}|[0-9A-V]{4}={4}|[0-9A-V]{5}={3}|[0-9A-V]{7}={1})?$",
flags: "",
args: ["0-9A-V=", false]
}
];
}
@ -96,3 +103,4 @@ class FromBase32 extends Operation {
}
export default FromBase32;

View file

@ -6,6 +6,7 @@
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
/**
* To Base32 operation
@ -27,8 +28,8 @@ class ToBase32 extends Operation {
this.args = [
{
name: "Alphabet",
type: "binaryString",
value: "A-Z2-7="
type: "editableOption",
value: ALPHABET_OPTIONS
}
];
}
@ -83,3 +84,4 @@ class ToBase32 extends Operation {
}
export default ToBase32;