@@ -4963,8 +4963,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
49634963| [AES](#function-aes) |
49644964| [AESGCM](#function-aesgcm) |
49654965| [AESGCMDecrypt](#function-aesgcmdecrypt) |
4966+ | [assertValidHex](#function-assertvalidhex) |
49664967| [base64ToArray](#function-base64toarray) |
49674968| [ghash](#function-ghash) |
4969+ | [normalizeHex](#function-normalizehex) |
49684970| [pbkdf2](#function-pbkdf2) |
49694971| [red](#function-red) |
49704972| [toArray](#function-toarray) |
@@ -5004,6 +5006,15 @@ export function AESGCMDecrypt(cipherText: number[], additionalAuthenticatedData:
50045006
50055007Links: [API](#api ), [Interfaces](#interfaces ), [Classes](#classes ), [Functions](#functions ), [Types](#types ), [Enums](#enums ), [Variables](#variables )
50065008
5009+ ---
5010+ ### Function: assertValidHex
5011+
5012+ ```ts
5013+ export function assertValidHex(msg : string ): void
5014+ ```
5015+
5016+ Links: [API](#api ), [Interfaces](#interfaces ), [Classes](#classes ), [Functions](#functions ), [Types](#types ), [Enums](#enums ), [Variables](#variables )
5017+
50075018---
50085019### Function: base64ToArray
50095020
@@ -5022,6 +5033,15 @@ export function ghash(input: number[], hashSubKey: number[]): number[]
50225033
50235034Links: [API](#api ), [Interfaces](#interfaces ), [Classes](#classes ), [Functions](#functions ), [Types](#types ), [Enums](#enums ), [Variables](#variables )
50245035
5036+ ---
5037+ ### Function: normalizeHex
5038+
5039+ ```ts
5040+ export function normalizeHex(msg : string ): string
5041+ ```
5042+
5043+ Links: [API](#api ), [Interfaces](#interfaces ), [Classes](#classes ), [Functions](#functions ), [Types](#types ), [Enums](#enums ), [Variables](#variables )
5044+
50255045---
50265046### Function: pbkdf2
50275047
@@ -6100,49 +6120,78 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
61006120` ` ` ts
61016121toUTF8 = (arr : number []): string => {
61026122 let result = " " ;
6103- let skip = 0 ;
6123+ const replacementChar = " \uFFFD " ;
61046124 for (let i = 0 ; i < arr .length ; i ++ ) {
6105- const byte = arr [i ];
6106- if (skip > 0 ) {
6107- skip -- ;
6108- continue ;
6109- }
6110- if (byte <= 127 ) {
6111- result += String .fromCharCode (byte );
6125+ const byte1 = arr [i ];
6126+ if (byte1 <= 127 ) {
6127+ result += String .fromCharCode (byte1 );
61126128 continue ;
61136129 }
6114- if (byte >= 192 && byte <= 223 ) {
6115- const avail = arr .length - (i + 1 );
6116- const byte2 = avail >= 1 ? arr [i + 1 ] : 0 ;
6117- skip = Math .min (1 , avail );
6118- const codePoint = ((byte & 31 ) << 6 ) | (byte2 & 63 );
6130+ const emitReplacement = (): void => {
6131+ result += replacementChar ;
6132+ };
6133+ if (byte1 >= 192 && byte1 <= 223 ) {
6134+ if (i + 1 >= arr .length ) {
6135+ emitReplacement ();
6136+ continue ;
6137+ }
6138+ const byte2 = arr [i + 1 ];
6139+ if ((byte2 & 192 ) !== 128 ) {
6140+ emitReplacement ();
6141+ i += 1 ;
6142+ continue ;
6143+ }
6144+ const codePoint = ((byte1 & 31 ) << 6 ) | (byte2 & 63 );
61196145 result += String .fromCharCode (codePoint );
6146+ i += 1 ;
61206147 continue ;
61216148 }
6122- if (byte >= 224 && byte <= 239 ) {
6123- const avail = arr .length - (i + 1 );
6124- const byte2 = avail >= 1 ? arr [i + 1 ] : 0 ;
6125- const byte3 = avail >= 2 ? arr [i + 2 ] : 0 ;
6126- skip = Math .min (2 , avail );
6127- const codePoint = ((byte & 15 ) << 12 ) | ((byte2 & 63 ) << 6 ) | (byte3 & 63 );
6149+ if (byte1 >= 224 && byte1 <= 239 ) {
6150+ if (i + 2 >= arr .length ) {
6151+ emitReplacement ();
6152+ continue ;
6153+ }
6154+ const byte2 = arr [i + 1 ];
6155+ const byte3 = arr [i + 2 ];
6156+ if ((byte2 & 192 ) !== 128 || (byte3 & 192 ) !== 128 ) {
6157+ emitReplacement ();
6158+ i += 2 ;
6159+ continue ;
6160+ }
6161+ const codePoint = ((byte1 & 15 ) << 12 ) |
6162+ ((byte2 & 63 ) << 6 ) |
6163+ (byte3 & 63 );
61286164 result += String .fromCharCode (codePoint );
6165+ i += 2 ;
61296166 continue ;
61306167 }
6131- if (byte >= 240 && byte <= 247 ) {
6132- const avail = arr .length - (i + 1 );
6133- const byte2 = avail >= 1 ? arr [i + 1 ] : 0 ;
6134- const byte3 = avail >= 2 ? arr [i + 2 ] : 0 ;
6135- const byte4 = avail >= 3 ? arr [i + 3 ] : 0 ;
6136- skip = Math .min (3 , avail );
6137- const codePoint = ((byte & 7 ) << 18 ) |
6168+ if (byte1 >= 240 && byte1 <= 247 ) {
6169+ if (i + 3 >= arr .length ) {
6170+ emitReplacement ();
6171+ continue ;
6172+ }
6173+ const byte2 = arr [i + 1 ];
6174+ const byte3 = arr [i + 2 ];
6175+ const byte4 = arr [i + 3 ];
6176+ if ((byte2 & 192 ) !== 128 ||
6177+ (byte3 & 192 ) !== 128 ||
6178+ (byte4 & 192 ) !== 128 ) {
6179+ emitReplacement ();
6180+ i += 3 ;
6181+ continue ;
6182+ }
6183+ const codePoint = ((byte1 & 7 ) << 18 ) |
61386184 ((byte2 & 63 ) << 12 ) |
61396185 ((byte3 & 63 ) << 6 ) |
61406186 (byte4 & 63 );
6141- const surrogate1 = 55296 + ((codePoint - 65536 ) >> 10 );
6142- const surrogate2 = 56320 + ((codePoint - 65536 ) & 1023 );
6143- result += String .fromCharCode (surrogate1 , surrogate2 );
6187+ const offset = codePoint - 65536 ;
6188+ const highSurrogate = 55296 + (offset >> 10 );
6189+ const lowSurrogate = 56320 + (offset & 1023 );
6190+ result += String .fromCharCode (highSurrogate , lowSurrogate );
6191+ i += 3 ;
61446192 continue ;
61456193 }
6194+ emitReplacement ();
61466195 }
61476196 return result ;
61486197}
0 commit comments