Skip to content

Commit 52545bb

Browse files
Konstantin Likhtercjihrig
Konstantin Likhter
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 dc08ced commit 52545bb

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

test/parallel/test-crypto-padding.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

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

1111
crypto.DEFAULT_ENCODING = 'buffer';
1212

@@ -21,7 +21,7 @@ const EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi';
2121
const KEY_PLAIN = 'S3c.r.e.t.K.e.Y!';
2222
const 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

5656
function 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

6464
function 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

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
}, /bad decrypt/);
111109

112110
assert.doesNotThrow(function() {

0 commit comments

Comments
 (0)