Changeset - 11975fd44f93
[Not reviewed]
default
0 1 0
Laman - 5 years ago 2019-07-05 19:20:40

tests: mocked window.crypto.getRandomValues()
1 file changed with 13 insertions and 3 deletions:
0 comments (0 inline, 0 general)
spec/test/chachaSpec.js
Show inline comments
 
/* global expect */
 

	
 
function getRandomValues(arr){
 
	for(let i=0;i<arr.length;i++){
 
		arr[i]=Math.floor(Math.random()*256);
 
	}
 
}
 

	
 
window={
 
	crypto: {
 
		getRandomValues: getRandomValues
 
	}
 
};
 

	
 
describe("Chacha",function(){
 
	let cryptoJS=require("../../dist/main.js");
 
	let util=cryptoJS.util;
 
@@ -43,9 +55,7 @@ describe("Chacha",function(){
 
			let text=str2utf8(plaintext);
 
			let key=[];
 
			for(let i=0;i<16;i++){key.push(Math.floor(Math.random()*256));}
 
			let nonce=[];
 
			for(let i=0;i<8;i++){nonce.push(Math.floor(Math.random()*256));}
 
			let [_,ciphertext]=encrypt(text,key,nonce);
 
			let [nonce,ciphertext]=encrypt(text,key);
 
			expect(decrypt(ciphertext,key,nonce)).toEqual(text);
 
		});
 
	});
0 comments (0 inline, 0 general)