11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
44
55if ( ! common . hasCrypto ) {
66 common . skip ( 'missing crypto' ) ;
77 return ;
88}
9- var crypto = require ( 'crypto' ) ;
9+ const crypto = require ( 'crypto' ) ;
1010
1111crypto . DEFAULT_ENCODING = 'buffer' ;
1212
@@ -21,7 +21,7 @@ const EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi';
2121const KEY_PLAIN = 'S3c.r.e.t.K.e.Y!' ;
2222const IV_PLAIN = 'blahFizz2011Buzz' ;
2323
24- var CIPHER_NAME = 'aes-128-cbc' ;
24+ const CIPHER_NAME = 'aes-128-cbc' ;
2525
2626
2727/*
@@ -31,20 +31,20 @@ var CIPHER_NAME = 'aes-128-cbc';
3131// echo -n 'Hello node world!' | \
3232// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \
3333// -iv 626c616846697a7a3230313142757a7a | xxd -p -c256
34- var ODD_LENGTH_ENCRYPTED =
34+ const ODD_LENGTH_ENCRYPTED =
3535 '7f57859550d4d2fdb9806da2a750461a9fe77253cd1cbd4b07beee4e070d561f' ;
3636
3737// echo -n 'Hello node world!AbC09876dDeFgHi' | \
3838// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \
3939// -iv 626c616846697a7a3230313142757a7a | xxd -p -c256
40- var EVEN_LENGTH_ENCRYPTED =
40+ const EVEN_LENGTH_ENCRYPTED =
4141 '7f57859550d4d2fdb9806da2a750461ab46e71b3d78ebe2d9684dfc87f7575b988' +
4242 '6119866912cb8c7bcaf76c5ebc2378' ;
4343
4444// echo -n 'Hello node world!AbC09876dDeFgHi' | \
4545// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \
4646// -iv 626c616846697a7a3230313142757a7a -nopad | xxd -p -c256
47- var EVEN_LENGTH_ENCRYPTED_NOPAD =
47+ const EVEN_LENGTH_ENCRYPTED_NOPAD =
4848 '7f57859550d4d2fdb9806da2a750461ab46e' +
4949 '71b3d78ebe2d9684dfc87f7575b9' ;
5050
@@ -54,17 +54,17 @@ var EVEN_LENGTH_ENCRYPTED_NOPAD =
5454 */
5555
5656function enc ( plain , pad ) {
57- var encrypt = crypto . createCipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
57+ const encrypt = crypto . createCipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
5858 encrypt . setAutoPadding ( pad ) ;
59- var hex = encrypt . update ( plain , 'ascii' , 'hex' ) ;
59+ let hex = encrypt . update ( plain , 'ascii' , 'hex' ) ;
6060 hex += encrypt . final ( 'hex' ) ;
6161 return hex ;
6262}
6363
6464function dec ( encd , pad ) {
65- var decrypt = crypto . createDecipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
65+ const decrypt = crypto . createDecipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
6666 decrypt . setAutoPadding ( pad ) ;
67- var plain = decrypt . update ( encd , 'hex' ) ;
67+ let plain = decrypt . update ( encd , 'hex' ) ;
6868 plain += decrypt . final ( 'latin1' ) ;
6969 return plain ;
7070}
@@ -104,9 +104,7 @@ assert.doesNotThrow(function() {
104104
105105assert . throws ( function ( ) {
106106 // must have at least 1 byte of padding (PKCS):
107- assert . strictEqual (
108- dec ( EVEN_LENGTH_ENCRYPTED_NOPAD , true ) , EVEN_LENGTH_PLAIN
109- ) ;
107+ assert . strictEqual ( dec ( EVEN_LENGTH_ENCRYPTED_NOPAD , true ) , EVEN_LENGTH_PLAIN ) ;
110108} , / b a d d e c r y p t / ) ;
111109
112110assert . doesNotThrow ( function ( ) {
0 commit comments