BREAKING(encoding): remove deprecated APIs (#3952)

This commit is contained in:
Asher Gomez 2023-12-14 14:23:10 +11:00 committed by GitHub
parent 48c489e716
commit b8acd30150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1 additions and 167 deletions

View File

@ -48,17 +48,6 @@ const rfc1924 =
const Z85 =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
/**
* Encodes a given Uint8Array into ascii85, supports multiple standards
* @param uint8 input to encode
* @param [options] encoding options
* @param [options.standard=Adobe] encoding standard (Adobe, btoa, RFC 1924 or Z85)
* @param [options.delimiter] whether to use a delimiter, if supported by encoding standard
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode encodeAscii85} instead.
*/
export const encode: typeof encodeAscii85 = encodeAscii85;
/**
* Converts data into an ascii58-encoded string.
*
@ -134,16 +123,6 @@ export function encodeAscii85(
return output.slice(0, output.length - difference).join("");
}
/**
* Decodes a given ascii85 encoded string.
* @param ascii85 input to decode
* @param [options] decoding options
* @param [options.standard=Adobe] encoding standard used in the input string (Adobe, btoa, RFC 1924 or Z85)
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode decodeAscii85} instead.
*/
export const decode: typeof decodeAscii85 = decodeAscii85;
/**
* Decodes a given ascii85-encoded string.
*

View File

@ -63,14 +63,6 @@ function _byteLength(validLen: number, placeHoldersLen: number): number {
return ((validLen + placeHoldersLen) * 5) / 8 - _getPadLen(placeHoldersLen);
}
/**
* Decodes a given RFC4648 base32 encoded string.
* @param b32
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode decodeBase32} instead.
*/
export const decode: typeof decodeBase32 = decodeBase32;
/**
* Decodes a base32-encoded string.
*
@ -173,14 +165,6 @@ function encodeChunk(uint8: Uint8Array, start: number, end: number): string {
return output.join("");
}
/**
* Encodes a given Uint8Array into RFC4648 base32 representation
* @param uint8
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode encodeBase32} instead.
*/
export const encode: typeof encodeBase32 = encodeBase32;
/**
* Converts data to a base32-encoded string.
*

View File

@ -26,22 +26,6 @@ const mapBase58: Record<string, number> = {
const base58alphabet =
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split("");
/**
* Encodes a given Uint8Array, ArrayBuffer or string into draft-mspotny-base58-03 RFC base58 representation:
* https://tools.ietf.org/id/draft-msporny-base58-01.html#rfc.section.1
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode encodeBase58} instead.
*/
export const encode: typeof encodeBase58 = encodeBase58;
/**
* Decodes a given b58 string according to draft-mspotny-base58-03 RFC base58 representation:
* https://tools.ietf.org/id/draft-msporny-base58-01.html#rfc.section.1
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode decodeBase58} instead.
*/
export const decode: typeof decodeBase58 = decodeBase58;
/**
* Converts data to a base58-encoded string.
*

View File

@ -80,21 +80,6 @@ const base64abc = [
"/",
];
/**
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode encodeBase64} instead.
*/
export const encode: typeof encodeBase64 = encodeBase64;
/**
* Decodes a given RFC4648 base64 encoded string
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode decodeBase64} instead.
*/
export const decode: typeof decodeBase64 = decodeBase64;
/**
* Converts data into a base64-encoded string.
*

View File

@ -43,22 +43,6 @@ function convertBase64ToBase64url(b64: string) {
: b64.replace(/\+/g, "-").replace(/\//g, "_");
}
/**
* Encodes a given ArrayBuffer or string into a base64url representation
* @param data
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode encodeBase64Url} instead.
*/
export const encode: typeof encodeBase64Url = encodeBase64Url;
/**
* Converts given base64url encoded data back to original
* @param b64url
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode decodeBase64Url} instead.
*/
export const decode: typeof decodeBase64Url = decodeBase64Url;
/**
* Convert data into a base64url-encoded string.
*

View File

@ -55,21 +55,6 @@ function fromHexChar(byte: number): number {
throw errInvalidByte(byte);
}
/**
* Encodes `src` into `src.length * 2` bytes.
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode encodeHex} instead.
*/
export function encode(src: Uint8Array): Uint8Array {
const dst = new Uint8Array(src.length * 2);
for (let i = 0; i < dst.length; i++) {
const v = src[i];
dst[i * 2] = hexTable[v >> 4];
dst[i * 2 + 1] = hexTable[v & 0x0f];
}
return dst;
}
/**
* Converts data into a hex-encoded string.
*
@ -92,30 +77,6 @@ export function encodeHex(src: string | Uint8Array | ArrayBuffer): string {
return textDecoder.decode(dst);
}
/**
* Decodes `src` into `src.length / 2` bytes.
* If the input is malformed, an error will be thrown.
*
* @deprecated (will be removed in 0.210.0) Use {@linkcode decodeHex} instead.
*/
export function decode(src: Uint8Array): Uint8Array {
const dst = new Uint8Array(src.length / 2);
for (let i = 0; i < dst.length; i++) {
const a = fromHexChar(src[i * 2]);
const b = fromHexChar(src[i * 2 + 1]);
dst[i] = (a << 4) | b;
}
if (src.length % 2 === 1) {
// Check for invalid char before reporting bad length,
// since the invalid char (if present) is an earlier problem.
fromHexChar(src[dst.length * 2]);
throw errLength();
}
return dst;
}
/**
* Decodes the given hex-encoded string. If the input is malformed, an error is
* thrown.

View File

@ -6,7 +6,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertThrows } from "../assert/mod.ts";
import { decode, decodeHex, encode, encodeHex } from "./hex.ts";
import { decodeHex, encodeHex } from "./hex.ts";
const testCases = [
// encoded(hex) / decoded(Uint8Array)
@ -31,23 +31,6 @@ const errCases: [string, ErrorConstructor, string][] = [
["ffeed", RangeError, ""],
];
Deno.test("[encoding.hex] encode", () => {
{
const srcStr = "abc";
const src = new TextEncoder().encode(srcStr);
const dest = encode(src);
assertEquals(src, new Uint8Array([97, 98, 99]));
assertEquals(dest.length, 6);
}
for (const [enc, dec] of testCases) {
const src = new Uint8Array(dec as number[]);
const dest = encode(src);
assertEquals(dest.length, src.length * 2);
assertEquals(new TextDecoder().decode(dest), enc);
}
});
Deno.test("[encoding.hex] encodeHex", () => {
{
const srcStr = "abc";
@ -63,22 +46,6 @@ Deno.test("[encoding.hex] encodeHex", () => {
}
});
Deno.test("[encoding.hex] decode", () => {
// Case for decoding uppercase hex characters, since
// Encode always uses lowercase.
const extraTestcase = [
["F8F9FAFBFCFDFEFF", [0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff]],
];
const cases = testCases.concat(extraTestcase);
for (const [enc, dec] of cases) {
const src = new TextEncoder().encode(enc as string);
const dest = decode(src);
assertEquals(Array.from(dest), Array.from(dec as number[]));
}
});
Deno.test("[encoding.hex] decodeHex", () => {
// Case for decoding uppercase hex characters, since
// Encode always uses lowercase.
@ -94,16 +61,6 @@ Deno.test("[encoding.hex] decodeHex", () => {
}
});
Deno.test("[encoding.hex] decode error", () => {
for (const [input, expectedErr, msg] of errCases) {
assertThrows(
() => decode(new TextEncoder().encode(input)),
expectedErr,
msg,
);
}
});
Deno.test("[encoding.hex] decodeHex error", () => {
for (const [input, expectedErr, msg] of errCases) {
assertThrows(