From 95671dff0fba45c80b2de08cb533c8eb4f7b7fb0 Mon Sep 17 00:00:00 2001 From: DavidVentura Date: Sun, 28 Jan 2024 20:14:41 +0100 Subject: [PATCH] fix `add` on dataview missing byteOffset from previous dv --- shim.ts | 2 +- tests/fn.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/shim.ts b/shim.ts index 10f1059..9f3855b 100644 --- a/shim.ts +++ b/shim.ts @@ -1,5 +1,5 @@ DataView.prototype.add = function (offset) { - return new DataView(this.buffer, offset); + return new DataView(this.buffer, offset + this.byteOffset); }; DataView.prototype.writeU8 = function (val) { return this.setUint8(0, val); diff --git a/tests/fn.test.js b/tests/fn.test.js index 0285156..132c55b 100644 --- a/tests/fn.test.js +++ b/tests/fn.test.js @@ -106,6 +106,13 @@ describe("module", () => { XqBytesEnc(in_buf, long_dec_bytes.byteLength, 4); // this mutates in_buf assert.deepEqual(new Uint8Array(in_buf.buffer), long_enc_bytes); }); + /* TODO + it("decrypts offset dataviews", () => { + const in_buf = new DataView(simple_enc_bytes.buffer.slice(0)); + XqBytesDec(in_buf, simple_enc_bytes.byteLength, 4); // this mutates in_buf + assert.deepEqual(new Uint8Array(in_buf.buffer), simple_dec_bytes); + }); + */ it("reverts Enc with Dec", () => { const in_buf = new DataView(long_dec_bytes.buffer.slice(0)); XqBytesEnc(in_buf, long_dec_bytes.byteLength, 4); // this mutates in_buf