@@ -4,8 +4,6 @@ var crypto = require('crypto');
44var ece = require ( './ece.js' ) ;
55var base64 = require ( 'urlsafe-base64' ) ;
66var assert = require ( 'assert' ) ;
7- var fs = require ( 'fs' ) ;
8-
97
108// Usage: node test.js [args]
119// If args contains a version (e.g., aes128gcm), filter on versions.
@@ -37,7 +35,6 @@ if (process.argv.length >= 3) {
3735 } else {
3836 plaintext = new Buffer ( process . argv [ 2 ] , 'ascii' ) ;
3937 }
40- dump = ( process . argv . indexOf ( 'dump' ) != - 1 )
4138}
4239function filterTests ( fullList ) {
4340 var filtered = fullList . filter ( function ( t ) {
@@ -62,16 +59,12 @@ function logbuf(msg, buf) {
6259 }
6360}
6461
65- // Validate that the encryption function only accepts Buffers
6662function validate ( ) {
6763 [ 'hello' , null , 1 , NaN , [ ] , { } ] . forEach ( function ( v ) {
6864 try {
69- ece . encrypt ( v , { } ) ;
70- } catch ( e ) {
71- if ( e . toString ( ) != "Error: buffer argument must be a Buffer" ) {
72- throw new Error ( "encrypt failed to reject " + JSON . stringify ( v ) ) ;
73- }
74- }
65+ encrypt ( 'hello' , { } ) ;
66+ throw new Error ( 'should insist on a buffer' ) ;
67+ } catch ( e ) { }
7568 } ) ;
7669}
7770
@@ -111,21 +104,6 @@ function encryptDecrypt(input, encryptParams, decryptParams) {
111104 logbuf ( 'Encrypted' , encrypted ) ;
112105 var decrypted = ece . decrypt ( encrypted , decryptParams ) ;
113106 logbuf ( 'Decrypted' , decrypted ) ;
114- if ( dump ) {
115- var data = {
116- version : version ,
117- input : base64 . encode ( input ) ,
118- encrypted : base64 . encode ( encrypted ) ,
119- params : {
120- encrypted : encryptParams ,
121- decrypt : decryptParams ,
122- }
123- } ;
124- if ( keyData ) {
125- data . keys = keyData ;
126- }
127- dumpData ( data ) ;
128- }
129107 assert . equal ( Buffer . compare ( input , decrypted ) , 0 ) ;
130108 log ( '----- OK' ) ;
131109}
@@ -177,7 +155,7 @@ function detectTruncation(version) {
177155 logbuf ( 'Encrypted' , encrypted ) ;
178156 var ok = false ;
179157 try {
180- ece . decrypt ( encrypted , params , params , version ) ;
158+ ece . decrypt ( encrypted , params ) ;
181159 } catch ( e ) {
182160 log ( '----- OK: ' + e ) ;
183161 ok = true ;
@@ -304,4 +282,4 @@ filterTests([ 'aesgcm128', 'aesgcm', 'aes128gcm' ])
304282 } ) ;
305283checkExamples ( ) ;
306284
307- log ( 'All tests passed.' ) ;
285+ log ( 'All tests passed.' ) ;
0 commit comments