Skip to content

Commit 699a9f6

Browse files
cpetrovtbuschto
authored andcommitted
Fix return value of Crypto#getRandomValues()
It should return the same array passed to it [1]. [1]: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#Return_value Change-Id: I4d7095d762bc50f4d5170d61aad8440634bbe91e
1 parent fe22c64 commit 699a9f6

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/tabris/Crypto.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class Crypto extends NativeObject {
2020
throw new Error('Not enough random bytes available');
2121
}
2222
new Uint8Array(typedArray.buffer).set(values);
23+
return typedArray;
2324
}
2425

2526
}

test/tabris/Crypto.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ describe('Crypto', function() {
130130
expect(buffer[2]).to.equal(0xffffffff);
131131
});
132132

133+
it('returns given array', function() {
134+
const buffer = new Uint32Array(3);
135+
returnValue = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 1, 255, 255, 255, 255]);
136+
137+
expect(crypto.getRandomValues(buffer)).to.equal(buffer);
138+
});
139+
133140
});
134141

135142
});

typings/global/crypto.d.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
declare class Crypto {
2-
3-
getRandomValues(
4-
typedArray: Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array
5-
): void;
1+
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array;
62

3+
declare class Crypto {
4+
getRandomValues(typedArray: TypedArray): TypedArray;
75
}
86

9-
declare var crypto: Crypto;
7+
declare var crypto: Crypto;

0 commit comments

Comments
 (0)