diff --git a/packages/compiler/src/i18n/digest.ts b/packages/compiler/src/i18n/digest.ts index 0f5b64feacb..2970b83d0d3 100644 --- a/packages/compiler/src/i18n/digest.ts +++ b/packages/compiler/src/i18n/digest.ts @@ -152,7 +152,18 @@ export function sha1(str: string): string { e = add32(e, h4); } - return bytesToHexString(words32ToByteString([a, b, c, d, e])); + // Convert the output parts to a 160-bit hexadecimal string + return toHexU32(a) + toHexU32(b) + toHexU32(c) + toHexU32(d) + toHexU32(e); +} + +/** + * Convert and format a number as a string representing a 32-bit unsigned hexadecimal number. + * @param value The value to format as a string. + * @returns A hexadecimal string representing the value. + */ +function toHexU32(value: number): string { + // unsigned right shift of zero ensures an unsigned 32-bit number + return (value >>> 0).toString(16).padStart(8, '0'); } function fk(index: number, b: number, c: number, d: number): [number, number] { @@ -357,27 +368,6 @@ function wordAt(bytes: Byte[], index: number, endian: Endian): number { return word; } -function words32ToByteString(words32: number[]): Byte[] { - return words32.reduce((bytes, word) => bytes.concat(word32ToByteString(word)), [] as Byte[]); -} - -function word32ToByteString(word: number): Byte[] { - let bytes: Byte[] = []; - for (let i = 0; i < 4; i++) { - bytes.push((word >>> 8 * (3 - i)) & 0xff); - } - return bytes; -} - -function bytesToHexString(bytes: Byte[]): string { - let hex: string = ''; - for (let i = 0; i < bytes.length; i++) { - const b = byteAt(bytes, i); - hex += (b >>> 4).toString(16) + (b & 0x0f).toString(16); - } - return hex.toLowerCase(); -} - /** * Create a shared exponentiation pool for base-256 computations. This shared pool provides memoized * power-of-256 results with memoized power-of-two computations for efficient multiplication.