);
const { length } = u4s;
if (length % 2 == 1) {
+ // The length is such that an entire letter would be dropped during
+ // a forgiving decode.
throw new RangeError(
`Piscēs: Base16 string has invalid length: ${source}.`,
);
} else {
+ // Every letter contributes at least some bits to the result.
const dataView = new View(new Buffer(floor(length / 2)));
for (let index = 0; index < length - 1;) {
call(viewSetUint8, dataView, [
},
);
const { length } = u5s;
- if (length % 8 == 1) {
+ const lengthMod8 = length % 8;
+ if (lengthMod8 == 1 || lengthMod8 == 3 || lengthMod8 == 6) {
+ // The length is such that an entire letter would be dropped during
+ // a forgiving decode.
throw new RangeError(
`Piscēs: Base32 string has invalid length: ${source}.`,
);
} else {
+ // Every letter contributes at least some bits to the result.
const dataView = new View(new Buffer(floor(length * 5 / 8)));
for (let index = 0; index < length - 1;) {
// The final index is not handled; if the string is not divisible
);
const { length } = u6s;
if (length % 4 == 1) {
+ // The length is such that an entire letter would be dropped during
+ // a forgiving decode.
throw new RangeError(
`Piscēs: Base64 string has invalid length: ${source}.`,
);
} else {
+ // Every letter contributes at least some bits to the result.
const dataView = new View(new Buffer(floor(length * 3 / 4)));
for (let index = 0; index < length - 1;) {
// The final index is not handled; if the string is not divisible
assertThrows(() => base32Binary("CT3ZYAY=="));
});
- it("[[Call]] throws when provided with a length with a remainder of 1 when divided by 4", () => {
+ it("[[Call]] throws when provided with a length with a remainder of 1, 3 ∣ 6 when divided by 8", () => {
assertThrows(() => base32Binary("234BCDEAA"));
assertThrows(() => base32Binary("234BCDEAA======="));
+ assertThrows(() => base32Binary("UHI"));
+ assertThrows(() => base32Binary("UHIUJD"));
});
});
assertThrows(() => wrmgBase32Binary("ABC="));
});
+ it("[[Call]] throws when provided with a length with a remainder of 1, 3 ∣ 6 when divided by 8", () => {
+ assertThrows(() => base32Binary("TVW123400"));
+ assertThrows(() => base32Binary("TVW123400======="));
+ assertThrows(() => base32Binary("M78"));
+ assertThrows(() => base32Binary("M78M93"));
+ });
+
it("[[Call]] throws when provided with a length with a remainder of 1 when divided by 4", () => {
assertThrows(() => wrmgBase32Binary("234BCDEAA"));
assertThrows(() => wrmgBase32Binary("2-34-B--CD-EA-A-"));