mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
BREAKING(encoding): remove base32.byteLength()
(#4173)
This commit is contained in:
parent
c9a1aaa874
commit
ccc139d6e3
@ -50,17 +50,6 @@ function getLens(b32: string): [number, number] {
|
|||||||
return [validLen, placeHoldersLen];
|
return [validLen, placeHoldersLen];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns number of bytes encoded in the given RFC4648 base32 string input.
|
|
||||||
* @param b32
|
|
||||||
*
|
|
||||||
* @deprecated (will be removed in 0.212.0)
|
|
||||||
*/
|
|
||||||
export function byteLength(b32: string): number {
|
|
||||||
const [validLen, placeHoldersLen] = getLens(b32);
|
|
||||||
return _byteLength(validLen, placeHoldersLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _byteLength(validLen: number, placeHoldersLen: number): number {
|
function _byteLength(validLen: number, placeHoldersLen: number): number {
|
||||||
return ((validLen + placeHoldersLen) * 5) / 8 - _getPadLen(placeHoldersLen);
|
return ((validLen + placeHoldersLen) * 5) / 8 - _getPadLen(placeHoldersLen);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
import { assertThrows } from "../assert/assert_throws.ts";
|
import { assertThrows } from "../assert/assert_throws.ts";
|
||||||
import { assertEquals, assertExists } from "../assert/mod.ts";
|
import { assertEquals, assertExists } from "../assert/mod.ts";
|
||||||
import { byteLength, decodeBase32, encodeBase32 } from "./base32.ts";
|
import { decodeBase32, encodeBase32 } from "./base32.ts";
|
||||||
|
|
||||||
// Lifted from https://stackoverflow.com/questions/38987784
|
// Lifted from https://stackoverflow.com/questions/38987784
|
||||||
const fromHexString = (hexString: string): Uint8Array =>
|
const fromHexString = (hexString: string): Uint8Array =>
|
||||||
@ -125,22 +125,6 @@ Deno.test({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
|
||||||
name: "encodeBase32() checks byteLength",
|
|
||||||
fn() {
|
|
||||||
const tests: [string, number][] = [
|
|
||||||
["JBSWY3DPEBLW64TMMQ======", 11],
|
|
||||||
["3X4A5PRBX4NR4EVGJROMNJ2LLWJN2===", 18],
|
|
||||||
["WB2K5C467XQPC7ZXXTFN3YAG2A4ZS62ZZDX3AWW5", 25],
|
|
||||||
["6L6CGGN5FFCXZTIB5DQZJ3U327UXFGFWMEG7JKYPHVN2UCZNPTHWTAU63N2O33Y=", 39],
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const [input, expect] of tests) {
|
|
||||||
assertEquals(byteLength(input), expect);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "encodeBase32() encodes very long text",
|
name: "encodeBase32() encodes very long text",
|
||||||
fn() {
|
fn() {
|
||||||
|
Loading…
Reference in New Issue
Block a user