Skip to content

Commit 404306f

Browse files
Konstantin Likhteraddaleax
authored andcommitted
test: refactor test-crypto-padding.js
- Replaced var with const and let. - Replaced assert.equal() with assert.strictEqual(). - Added error message checking for assert.throws(). PR-URL: #9971 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 821518d commit 404306f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

‎test/parallel/test-crypto-padding.js‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
2-
varcommon=require('../common');
3-
varassert=require('assert');
2+
constcommon=require('../common');
3+
constassert=require('assert');
44

55
if(!common.hasCrypto){
66
common.skip('missing crypto');
77
return;
88
}
9-
varcrypto=require('crypto');
9+
constcrypto=require('crypto');
1010

1111
crypto.DEFAULT_ENCODING='buffer';
1212

@@ -21,7 +21,7 @@ const EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi'
2121
constKEY_PLAIN='S3c.r.e.t.K.e.Y!';
2222
constIV_PLAIN='blahFizz2011Buzz';
2323

24-
varCIPHER_NAME='aes-128-cbc';
24+
constCIPHER_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-
varODD_LENGTH_ENCRYPTED=
34+
constODD_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-
varEVEN_LENGTH_ENCRYPTED=
40+
constEVEN_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-
varEVEN_LENGTH_ENCRYPTED_NOPAD=
47+
constEVEN_LENGTH_ENCRYPTED_NOPAD=
4848
'7f57859550d4d2fdb9806da2a750461ab46e'+
4949
'71b3d78ebe2d9684dfc87f7575b9';
5050

@@ -54,17 +54,17 @@ var EVEN_LENGTH_ENCRYPTED_NOPAD =
5454
*/
5555

5656
functionenc(plain,pad){
57-
varencrypt=crypto.createCipheriv(CIPHER_NAME,KEY_PLAIN,IV_PLAIN);
57+
constencrypt=crypto.createCipheriv(CIPHER_NAME,KEY_PLAIN,IV_PLAIN);
5858
encrypt.setAutoPadding(pad);
59-
varhex=encrypt.update(plain,'ascii','hex');
59+
lethex=encrypt.update(plain,'ascii','hex');
6060
hex+=encrypt.final('hex');
6161
returnhex;
6262
}
6363

6464
functiondec(encd,pad){
65-
vardecrypt=crypto.createDecipheriv(CIPHER_NAME,KEY_PLAIN,IV_PLAIN);
65+
constdecrypt=crypto.createDecipheriv(CIPHER_NAME,KEY_PLAIN,IV_PLAIN);
6666
decrypt.setAutoPadding(pad);
67-
varplain=decrypt.update(encd,'hex');
67+
letplain=decrypt.update(encd,'hex');
6868
plain+=decrypt.final('latin1');
6969
returnplain;
7070
}
@@ -104,9 +104,7 @@ assert.doesNotThrow(function(){
104104

105105
assert.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
},/baddecrypt/);
111109

112110
assert.doesNotThrow(function(){

0 commit comments

Comments
(0)