diff options
author | Marco Munizaga <marco.munizaga@ufl.edu> | 2013-10-05 15:35:32 -0400 |
---|---|---|
committer | Marco Munizaga <marco.munizaga@ufl.edu> | 2013-10-26 19:19:57 -0400 |
commit | 0e6166ee4418bec330fcbc356be1a8225865b02d (patch) | |
tree | 805136ef3ebe2b7e5498e5cebc27cfe0dce4f261 /test/codec_arraybuffer_test.js | |
parent | c40c85cf72d4eb71492f5aa0bacc82dadf2ac4a5 (diff) | |
download | sjcl-0e6166ee4418bec330fcbc356be1a8225865b02d.zip sjcl-0e6166ee4418bec330fcbc356be1a8225865b02d.tar.gz sjcl-0e6166ee4418bec330fcbc356be1a8225865b02d.tar.bz2 |
oops forgot to add the codec_arraybuffer_test
Diffstat (limited to 'test/codec_arraybuffer_test.js')
-rw-r--r-- | test/codec_arraybuffer_test.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/codec_arraybuffer_test.js b/test/codec_arraybuffer_test.js new file mode 100644 index 0000000..6dba0ad --- /dev/null +++ b/test/codec_arraybuffer_test.js @@ -0,0 +1,33 @@ +//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") + +//This ccm implementation is only defined for IV Lengths of 8 bytes +var test_bytes = [] + +var zeropad_hex = function(number){ + var hex = number.toString(16) + while ( hex.length%2 != 0 ){ + hex = "0"+hex; + } + return hex +} + +for (var i = 0; i <= 0xffff; i++){ + test_bytes.push(zeropad_hex(i)) +} + + +test_bytes.map(function(test_byte, index){ + var bitArray = sjcl.codec.hex.toBits(test_byte), + arrayBuffer = sjcl.codec.arrayBuffer.fromBits(bitArray, false), + roundTripArrayBuffer = sjcl.codec.arrayBuffer.toBits(arrayBuffer), + roundTripHex = sjcl.codec.hex.fromBits(roundTripArrayBuffer) + + if (roundTripHex !== test_byte){ + console.error("Failed test, expected ",roundTripHex,"to be",test_byte) + throw("Failed at: "+i) + } +}) + +phantom.exit() + |