From: Justin Wind Date: Sat, 17 Sep 2022 19:43:51 +0000 (-0700) Subject: replace deprecated Buffer slice() calls with subarray() X-Git-Tag: v1.2.0~2 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=75c98d382607b7d6bcfba9f97cc9edabb6f0395b;p=squeep-mystery-box replace deprecated Buffer slice() calls with subarray() --- diff --git a/lib/mystery-box.js b/lib/mystery-box.js index cb85ebe..2fb68a5 100644 --- a/lib/mystery-box.js +++ b/lib/mystery-box.js @@ -74,7 +74,6 @@ class MysteryBox { if (!this.secrets.length) { throw new Error('missing encryption secret'); } - // TODO: support secret rolling // Filter any unavailable algorithms const availableCiphers = crypto.getCiphers(); @@ -218,7 +217,7 @@ class MysteryBox { const raw = Buffer.from(base64URLToBase64(box), 'base64'); let offset = 0; - const version = raw.slice(offset, 1).readUInt8(0); + const version = raw.subarray(offset, 1).readUInt8(0); if (!(version in this.versionParameters)) { throw new RangeError('unsupported version'); } @@ -231,23 +230,23 @@ class MysteryBox { throw new RangeError('not enough to unpack'); } - const flags = raw.slice(offset, offset + v.flagsBytes).readUInt8(0); + const flags = raw.subarray(offset, offset + v.flagsBytes).readUInt8(0); offset += v.flagsBytes; const { compression, payloadIsBuffer } = MysteryBox._decodeFlags(flags); - const iv = raw.slice(offset, offset + v.ivBytes); + const iv = raw.subarray(offset, offset + v.ivBytes); offset += v.ivBytes; - const salt = raw.slice(offset, offset + v.saltBytes); + const salt = raw.subarray(offset, offset + v.saltBytes); offset += v.saltBytes; - const aad = raw.slice(0, offset); // Everything up to here + const aad = raw.subarray(0, offset); // Everything up to here - const tag = raw.slice(offset, offset + v.tagBytes); + const tag = raw.subarray(offset, offset + v.tagBytes); offset += v.tagBytes; - const encrypted = raw.slice(offset); + const encrypted = raw.subarray(offset); timingsMs.preCrypt = performance.now();