UNPKG

3.64 kBSource Map (JSON)View Raw
1{"version":3,"file":"rabin-uncached.cjs","sources":["../hash/rabin-uncached.js"],"sourcesContent":["/**\n * It is not recommended to use this package. This is the uncached implementation of the rabin\n * fingerprint algorithm. However, it can be used to verify the `rabin.js` implementation.\n *\n * @module rabin-uncached\n */\n\nimport * as math from '../math.js'\nimport * as buffer from '../buffer.js'\n\nexport class RabinUncachedEncoder {\n /**\n * @param {Uint8Array} m assert(m[0] === 1)\n */\n constructor (m) {\n this.m = m\n this.blen = m.byteLength\n this.bs = new Uint8Array(this.blen)\n /**\n * This describes the position of the most significant byte (starts with 0 and increases with\n * shift)\n */\n this.bpos = 0\n }\n\n /**\n * Add/Xor/Substract bytes.\n *\n * Discards bytes that are out of range.\n * @todo put this in function or inline\n *\n * @param {Uint8Array} cs\n */\n add (cs) {\n const copyLen = math.min(this.blen, cs.byteLength)\n // copy from right to left until max is reached\n for (let i = 0; i < copyLen; i++) {\n this.bs[(this.bpos + this.blen - i - 1) % this.blen] ^= cs[cs.byteLength - i - 1]\n }\n }\n\n /**\n * @param {number} byte\n */\n write (byte) {\n // [0,m1,m2,b]\n // x <- bpos\n // Shift one byte to the left, add b\n this.bs[this.bpos] = byte\n this.bpos = (this.bpos + 1) % this.blen\n // mod\n for (let i = 7; i >= 0; i--) {\n if (((this.bs[this.bpos] >>> i) & 1) === 1) {\n this.add(buffer.shiftNBitsLeft(this.m, i))\n }\n }\n // if (this.bs[this.bpos] !== 0) { error.unexpectedCase() }\n // assert(this.bs[this.bpos] === 0)\n }\n\n getFingerprint () {\n const result = new Uint8Array(this.blen - 1)\n for (let i = 0; i < result.byteLength; i++) {\n result[i] = this.bs[(this.bpos + i + 1) % this.blen]\n }\n return result\n }\n}\n"],"names":["math.min","buffer.shiftNBitsLeft"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAIA;AACO,MAAM,oBAAoB,CAAC;AAClC;AACA;AACA;AACA,EAAE,WAAW,CAA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