encryptCdsDiscoveryRequest: Reset offset after writing to array

This commit is contained in:
Scott Nonnenberg 2021-04-26 16:52:20 -07:00
parent 86a01f289d
commit 7ed54111e2
2 changed files with 6 additions and 0 deletions

View File

@ -669,10 +669,15 @@ export async function encryptCdsDiscoveryRequest(
// Long.fromString handles numbers with or without a leading '+'
numbersArray.writeLong(window.dcodeIO.ByteBuffer.Long.fromString(number));
});
// We've written to the array, so offset === byteLength; we need to reset it. Then we'll
// have access to everything in the array when we generate an ArrayBuffer from it.
numbersArray.reset();
const queryDataPlaintext = concatenateBytes(
nonce,
numbersArray.toArrayBuffer()
);
const queryDataKey = getRandomBytes(32);
const commitment = sha256(queryDataPlaintext);
const iv = getRandomBytes(12);

1
ts/window.d.ts vendored
View File

@ -608,6 +608,7 @@ export class ByteBufferClass {
readLong: (offset: number) => Long;
readShort: (offset: number) => number;
readVarint32: () => number;
reset: () => void;
writeLong: (l: Long) => void;
skip: (length: number) => void;
}