diff options
author | Nils Kenneweg <nk@ovt.me> | 2014-09-26 18:14:50 +0200 |
---|---|---|
committer | Nils Kenneweg <nk@ovt.me> | 2014-09-26 18:14:50 +0200 |
commit | 221c6edd91b06660694f377d9b63d5a6f507437e (patch) | |
tree | c9698d17beb941f483b9668f0ac104b5eb9ba642 /test/ccm_arraybuffer_test.js | |
parent | 37eb69607aad0079c6479f5d4d2842d93d3a5f11 (diff) | |
download | sjcl-221c6edd91b06660694f377d9b63d5a6f507437e.zip sjcl-221c6edd91b06660694f377d9b63d5a6f507437e.tar.gz sjcl-221c6edd91b06660694f377d9b63d5a6f507437e.tar.bz2 |
make tests work in nodejs.
Diffstat (limited to 'test/ccm_arraybuffer_test.js')
-rw-r--r-- | test/ccm_arraybuffer_test.js | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/test/ccm_arraybuffer_test.js b/test/ccm_arraybuffer_test.js index 75c47bf..0dac1e7 100644 --- a/test/ccm_arraybuffer_test.js +++ b/test/ccm_arraybuffer_test.js @@ -1,22 +1,15 @@ //Run using phantomjs, since rhino doesn't support array buffers, and node has an issue with create dataviews with a bytelength of 0 -sjcl = require("../sjcl.js") - -sjcl = sjcl || {} -sjcl.test = {} -sjcl.test.vector = {} -require("./ccm_vectors.js") - -console.log("Running CCM using ArrayBuffer tests") -var start_time = +(new Date()) +console.log("Running CCM using ArrayBuffer tests"); +var start_time = +(new Date()); //This ccm implementation is only defined for IV Lengths of 8 bytes var applicable_tests = sjcl.test.vector.ccm.filter(function(test){ - return test.iv.length === 16 -}) + return test.iv.length === 16 ; +}); applicable_tests.map(function(tv, index){ var len = 32 * tv.key.length, - h = sjcl.codec.hex + h = sjcl.codec.hex, aes = new sjcl.cipher.aes(h.toBits(tv.key)), iv = h.toBits(tv.iv), ad = h.toBits(tv.adata), @@ -28,22 +21,21 @@ applicable_tests.map(function(tv, index){ pass_e = sjcl.bitArray.equal( sjcl.arrayBuffer.ccm.compat_encrypt(aes, pt, iv, ad, tlen), ct - ) + ); pass_d = sjcl.bitArray.equal( sjcl.arrayBuffer.ccm.compat_decrypt(aes, ct, iv, ad, tlen), pt - ) + ); if (!(pass_e && pass_d)){ - console.log("Failed at : ",len+"-ccm #", index, "Pass?:", pass_d) + console.log("Failed at : ",len+"-ccm #", index, "Pass?:", pass_d); phantom.exit(1); } return pass_e && pass_d; -}) +}); -var total_time = parseInt(+(new Date())-start_time) -console.log(" + passed all",applicable_tests.length,"tests. ("+ total_time, "ms)") -phantom.exit(); +var total_time = parseInt(+(new Date())-start_time); +console.log(" + passed all",applicable_tests.length,"tests. ("+ total_time, "ms)"); |