Lemonldap-NG-Portal

 view release on metacpan or  search on metacpan

site/htdocs/static/bwr/jssha/dist/sha1.js  view on Meta::CPAN

                }
                else {
                    i += 1;
                    codePnt = 0x10000 + (((codePnt & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
                    codePntArr.push(0xf0 | (codePnt >>> 18), 0x80 | ((codePnt >>> 12) & 0x3f), 0x80 | ((codePnt >>> 6) & 0x3f), 0x80 | (codePnt & 0x3f));
                }
                for (j = 0; j < codePntArr.length; j += 1) {
                    byteOffset = byteCnt + existingByteLen;
                    intOffset = byteOffset >>> 2;
                    while (packed.length <= intOffset) {
                        packed.push(0);
                    }
                    /* Known bug kicks in here */
                    packed[intOffset] |= codePntArr[j] << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));
                    byteCnt += 1;
                }
            }
        }
        else {
            /* UTF16BE or UTF16LE */
            shiftModifier = bigEndianMod === -1 ? 2 : 0;
            /* Internally strings are UTF-16BE so transpose bytes under two conditions:
             * need LE and not switching endianness due to SHA-3
             * need BE and switching endianness due to SHA-3 */
            transposeBytes = ("UTF16LE" === utfType && bigEndianMod !== 1) || ("UTF16LE" !== utfType && bigEndianMod === 1);
            for (i = 0; i < str.length; i += 1) {
                codePnt = str.charCodeAt(i);
                if (transposeBytes === true) {
                    j = codePnt & 0xff;
                    codePnt = (j << 8) | (codePnt >>> 8);
                }
                byteOffset = byteCnt + existingByteLen;
                intOffset = byteOffset >>> 2;
                while (packed.length <= intOffset) {
                    packed.push(0);
                }
                packed[intOffset] |= codePnt << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));
                byteCnt += 2;
            }
        }
        return { value: packed, binLen: byteCnt * 8 + existingPackedLen };
    }
    /**
     * Convert a hex string to an array of words.
     *
     * @param str Hexadecimal string to be converted to binary representation.
     * @param existingPacked A packed int array of bytes to append the results to.
     * @param existingPackedLen The number of bits in `existingPacked` array.
     * @param bigEndianMod Modifier for whether hash function is big or small endian.
     * @returns Hashmap of the packed values.
     */
    function hex2packed(str, existingPacked, existingPackedLen, bigEndianMod) {
        var i, num, intOffset, byteOffset;
        if (0 !== str.length % 2) {
            throw new Error("String of HEX type must be in byte increments");
        }
        existingPackedLen = existingPackedLen || 0;
        var packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3, shiftModifier = bigEndianMod === -1 ? 3 : 0;
        for (i = 0; i < str.length; i += 2) {
            num = parseInt(str.substr(i, 2), 16);
            if (!isNaN(num)) {
                byteOffset = (i >>> 1) + existingByteLen;
                intOffset = byteOffset >>> 2;
                while (packed.length <= intOffset) {
                    packed.push(0);
                }
                packed[intOffset] |= num << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));
            }
            else {
                throw new Error("String of HEX type contains invalid characters");
            }
        }
        return { value: packed, binLen: str.length * 4 + existingPackedLen };
    }
    /**
     * Convert a string of raw bytes to an array of words.
     *
     * @param str String of raw bytes to be converted to binary representation.
     * @param existingPacked A packed int array of bytes to append the results to.
     * @param existingPackedLen The number of bits in `existingPacked` array.
     * @param bigEndianMod Modifier for whether hash function is big or small endian.
     * @returns Hashmap of the packed values.
     */
    function bytes2packed(str, existingPacked, existingPackedLen, bigEndianMod) {
        var codePnt, i, intOffset, byteOffset;
        existingPackedLen = existingPackedLen || 0;
        var packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3, shiftModifier = bigEndianMod === -1 ? 3 : 0;
        for (i = 0; i < str.length; i += 1) {
            codePnt = str.charCodeAt(i);
            byteOffset = i + existingByteLen;
            intOffset = byteOffset >>> 2;
            if (packed.length <= intOffset) {
                packed.push(0);
            }
            packed[intOffset] |= codePnt << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));
        }
        return { value: packed, binLen: str.length * 8 + existingPackedLen };
    }
    /**
     * Convert a base-64 string to an array of words.
     *
     * @param str Base64-encoded string to be converted to binary representation.
     * @param existingPacked A packed int array of bytes to append the results to.
     * @param existingPackedLen The number of bits in `existingPacked` array.
     * @param bigEndianMod Modifier for whether hash function is big or small endian.
     * @returns Hashmap of the packed values.
     */
    function b642packed(str, existingPacked, existingPackedLen, bigEndianMod) {
        var byteCnt = 0, index, i, j, tmpInt, strPart, intOffset, byteOffset;
        existingPackedLen = existingPackedLen || 0;
        var packed = existingPacked || [0], existingByteLen = existingPackedLen >>> 3, shiftModifier = bigEndianMod === -1 ? 3 : 0, firstEqual = str.indexOf("=");
        if (-1 === str.search(/^[a-zA-Z0-9=+/]+$/)) {
            throw new Error("Invalid character in base-64 string");
        }
        str = str.replace(/=/g, "");
        if (-1 !== firstEqual && firstEqual < str.length) {
            throw new Error("Invalid '=' found in base-64 string");
        }
        for (i = 0; i < str.length; i += 4) {
            strPart = str.substr(i, 4);
            tmpInt = 0;

site/htdocs/static/bwr/jssha/dist/sha1.js  view on Meta::CPAN

    function getOutputOpts(options) {
        var retVal = { outputUpper: false, b64Pad: "=", outputLen: -1 }, outputOptions = options || {}, lenErrstr = "Output length must be a multiple of 8";
        retVal["outputUpper"] = outputOptions["outputUpper"] || false;
        if (outputOptions["b64Pad"]) {
            retVal["b64Pad"] = outputOptions["b64Pad"];
        }
        if (outputOptions["outputLen"]) {
            if (outputOptions["outputLen"] % 8 !== 0) {
                throw new Error(lenErrstr);
            }
            retVal["outputLen"] = outputOptions["outputLen"];
        }
        else if (outputOptions["shakeLen"]) {
            if (outputOptions["shakeLen"] % 8 !== 0) {
                throw new Error(lenErrstr);
            }
            retVal["outputLen"] = outputOptions["shakeLen"];
        }
        if ("boolean" !== typeof retVal["outputUpper"]) {
            throw new Error("Invalid outputUpper formatting option");
        }
        if ("string" !== typeof retVal["b64Pad"]) {
            throw new Error("Invalid b64Pad formatting option");
        }
        return retVal;
    }
    /**
     * Parses an external constructor object and returns a packed number, if possible.
     *
     * @param key The human-friendly key name to prefix any errors with
     * @param value The input value object to parse
     * @param bigEndianMod Modifier for whether hash function is big or small endian.
     * @param fallback Fallback value if `value` is undefined.  If not present and `value` is undefined, an Error is thrown
     */
    function parseInputOption(key, value, bigEndianMod, fallback) {
        var errStr = key + " must include a value and format";
        if (!value) {
            if (!fallback) {
                throw new Error(errStr);
            }
            return fallback;
        }
        if (typeof value["value"] === "undefined" || !value["format"]) {
            throw new Error(errStr);
        }
        return getStrConverter(value["format"], 
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore - the value of encoding gets value checked by getStrConverter
        value["encoding"] || "UTF8", bigEndianMod)(value["value"]);
    }
    var jsSHABase = /** @class */ (function () {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        function jsSHABase(variant, inputFormat, options) {
            var inputOptions = options || {};
            this.inputFormat = inputFormat;
            this.utfType = inputOptions["encoding"] || "UTF8";
            this.numRounds = inputOptions["numRounds"] || 1;
            /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
            // @ts-ignore - The spec actually says ToString is called on the first parseInt argument so it's OK to use it here
            // to check if an arugment is an integer. This cheat would break if it's used to get the value of the argument.
            if (isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) {
                throw new Error("numRounds must a integer >= 1");
            }
            this.shaVariant = variant;
            this.remainder = [];
            this.remainderLen = 0;
            this.updateCalled = false;
            this.processedLen = 0;
            this.macKeySet = false;
            this.keyWithIPad = [];
            this.keyWithOPad = [];
        }
        /**
         * Hashes as many blocks as possible.  Stores the rest for either a future update or getHash call.
         *
         * @param srcString The input to be hashed.
         * @returns A reference to the object.
         */
        jsSHABase.prototype.update = function (srcString) {
            var i, updateProcessedLen = 0;
            var variantBlockIntInc = this.variantBlockSize >>> 5, convertRet = this.converterFunc(srcString, this.remainder, this.remainderLen), chunkBinLen = convertRet["binLen"], chunk = convertRet["value"], chunkIntLen = chunkBinLen >>> 5;
            for (i = 0; i < chunkIntLen; i += variantBlockIntInc) {
                if (updateProcessedLen + this.variantBlockSize <= chunkBinLen) {
                    this.intermediateState = this.roundFunc(chunk.slice(i, i + variantBlockIntInc), this.intermediateState);
                    updateProcessedLen += this.variantBlockSize;
                }
            }
            this.processedLen += updateProcessedLen;
            this.remainder = chunk.slice(updateProcessedLen >>> 5);
            this.remainderLen = chunkBinLen % this.variantBlockSize;
            this.updateCalled = true;
            return this;
        };
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        jsSHABase.prototype.getHash = function (format, options) {
            var i, finalizedState, outputBinLen = this.outputBinLen;
            var outputOptions = getOutputOpts(options);
            if (this.isVariableLen) {
                if (outputOptions["outputLen"] === -1) {
                    throw new Error("Output length must be specified in options");
                }
                outputBinLen = outputOptions["outputLen"];
            }
            var formatFunc = getOutputConverter(format, outputBinLen, this.bigEndianMod, outputOptions);
            if (this.macKeySet && this.getMAC) {
                return formatFunc(this.getMAC(outputOptions));
            }
            finalizedState = this.finalizeFunc(this.remainder.slice(), this.remainderLen, this.processedLen, this.stateCloneFunc(this.intermediateState), outputBinLen);
            for (i = 1; i < this.numRounds; i += 1) {
                /* Need to mask out bits that should be zero due to output not being a multiple of 32 */
                if (this.isVariableLen && outputBinLen % 32 !== 0) {
                    finalizedState[finalizedState.length - 1] &= 0x00ffffff >>> (24 - (outputBinLen % 32));
                }
                finalizedState = this.finalizeFunc(finalizedState, outputBinLen, 0, this.newStateFunc(this.shaVariant), outputBinLen);
            }
            return formatFunc(finalizedState);
        };
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        jsSHABase.prototype.setHMACKey = function (key, inputFormat, options) {
            if (!this.HMACSupported) {
                throw new Error("Variant does not support HMAC");



( run in 0.905 second using v1.01-cache-2.11-cpan-b16cb0d3907 )