mirror of
https://github.com/gtbu/Typesetter-5.3-p8.git
synced 2024-11-22 14:19:14 +01:00
1 line
151 KiB
Text
1 line
151 KiB
Text
|
{"version":3,"file":"sha.js","sources":["../src/converters.ts","../src/common.ts","../node_modules/tslib/tslib.es6.js","../src/primitives_32.ts","../src/sha1.ts","../src/sha256.ts","../src/primitives_64.ts","../src/sha512.ts","../src/sha3.ts","../src/sha.ts"],"sourcesContent":["import { packedValue, EncodingType, FormatType } from \"./custom_types\";\n/**\n * Return type for all the *2packed functions\n */\nconst b64Tab = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\nconst arraybuffer_error = \"ARRAYBUFFER not supported by this environment\";\nconst uint8array_error = \"UINT8ARRAY not supported by this environment\";\n\n/**\n * Convert a string to an array of words.\n *\n * There is a known bug with an odd number of existing bytes and using a UTF-16 encoding. However, this function is\n * used such that the existing bytes are always a result of a previous UTF-16 str2packed call and therefore there \n * should never be an odd number of existing bytes.\n\n * @param str Unicode string to be converted to binary representation.\n * @param utfType The Unicode type to use to encode the source string.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked`.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns Hashmap of the packed values.\n */\nfunction str2packed(\n str: string,\n utfType: EncodingType,\n existingPacked: number[] | undefined,\n existingPackedLen: number | undefined,\n bigEndianMod: -1 | 1\n): packedValue {\n let codePnt,\n codePntArr,\n byteCnt = 0,\n i,\n j,\n intOffset,\n byteOffset,\n shiftModifier,\n transposeBytes;\n\n existingPackedLen = existingPackedLen || 0;\n const packed = existingPacked || [0],\n existingByteLen = existingPackedLen >>> 3;\n\n if (\"UTF8\" === utfType) {\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n for (i = 0; i < str.length; i += 1) {\n codePnt = str.charCodeAt(i);\n codePntArr = [];\n\n if (0x80 > codePnt) {\n codePntArr.push(codePnt);\n } else if (0x800 > codePnt) {\n codePntArr.push(0xc0 | (codePnt >>> 6));\n codePntArr.push(0x80 | (codePnt & 0x3f));\n } else if (0xd800 > codePnt || 0xe000 <= codePnt) {\n codePntArr.push(0xe0 | (codePnt >>> 12), 0x80 | ((codePnt >>> 6) & 0x3f), 0x80 | (codePnt & 0x3f));\n } else {\n i += 1;\n codePnt = 0x10000 + (((codePnt & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));\n codePntArr.push(\n 0xf0 | (codePnt >>> 18),\n 0x80 | ((codePnt >>> 12) & 0x3f),\n 0x80 | ((codePnt >>> 6) & 0x3f),\n 0x80 | (codePnt & 0x3f)\n );\n }\n\n for (j = 0; j < codePntArr.length; j += 1) {\n byteOffset = byteCnt + existingByteLen;\n intOffset = byteOffset >>> 2;\n while (packed.length <= intOffset) {\n packed.push(0);\n }\n /* Known bug kicks in here */\n packed[intOffset] |= codePntArr[j] << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));\n byteCnt += 1;\n }\n }\n } else {\n /* UTF16BE or UTF16LE */\n shiftModifier = bigEndianMod === -1 ? 2 : 0;\n /* Internally strings are UTF-16BE so transpose bytes under two conditions:\n * need LE and not switching endianness due to SHA-3\n * need BE and switching endianness due to SHA-3 */\n transposeBytes = (\"UTF16LE\" === utfType && bigEndianMod !== 1) || (\"UTF16LE\" !== utfType && bigEndianMod === 1);\n for (i = 0; i < str.length; i += 1) {\n codePnt = str.charCodeAt(i);\n if (transposeBytes === true) {\n j = codePnt & 0xff;\n codePnt = (j << 8) | (codePnt >>> 8);\n }\n\n byteOffset = byteCnt + existingByteLen;\n intOffset = byteOffset >>> 2;\n while (packed.length <= intOffset) {\n packed.push(0);\n }\n packed[intOffset] |= codePnt << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));\n byteCnt += 2;\n }\n }\n return
|