fix wrong buffer conversion for Uint8Array

If the BufferSource is already an Uint8Array which is a view of a subset of the underlying ArrayBuffer then accessing .buffer caused the whole backing buffer to be returned. Fix this by just returning the original Uint8Array as-is.
This commit is contained in:
Marc Bärtschi 2024-04-17 16:11:50 +00:00
parent f15bffb040
commit 04d1a0bf22
1 changed files with 4 additions and 2 deletions

View File

@ -11,8 +11,10 @@ export class Fido2Utils {
return Utils.fromUrlB64ToArray(str);
}
static bufferSourceToUint8Array(bufferSource: BufferSource) {
if (Fido2Utils.isArrayBuffer(bufferSource)) {
static bufferSourceToUint8Array(bufferSource: BufferSource): Uint8Array {
if (bufferSource instanceof Uint8Array) {
return bufferSource;
} else if (Fido2Utils.isArrayBuffer(bufferSource)) {
return new Uint8Array(bufferSource);
} else {
return new Uint8Array(bufferSource.buffer);