Skip to content

Commit 3e37673

Browse files
Aileenaddaleax
Aileen
authored andcommitted
test: refactor test-crypto-cipheriv-decipheriv
Make change in test file from var to const/let. PR-URL: #10018 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 03b1c31 commit 3e37673

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

test/parallel/test-crypto-cipheriv-decipheriv.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
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
function testCipher1(key, iv) {
1212
// Test encyrption and decryption with explicit key and iv
13-
var plaintext =
14-
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
15-
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
16-
'jAfaFg**';
17-
var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
18-
var ciph = cipher.update(plaintext, 'utf8', 'hex');
13+
const plaintext =
14+
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
15+
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
16+
'jAfaFg**';
17+
const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
18+
let ciph = cipher.update(plaintext, 'utf8', 'hex');
1919
ciph += cipher.final('hex');
2020

21-
var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
22-
var txt = decipher.update(ciph, 'hex', 'utf8');
21+
const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
22+
let txt = decipher.update(ciph, 'hex', 'utf8');
2323
txt += decipher.final('utf8');
2424

2525
assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv');
@@ -28,11 +28,11 @@ function testCipher1(key, iv) {
2828
// NB: In real life, it's not guaranteed that you can get all of it
2929
// in a single read() like this. But in this case, we know it's
3030
// quite small, so there's no harm.
31-
var cStream = crypto.createCipheriv('des-ede3-cbc', key, iv);
31+
const cStream = crypto.createCipheriv('des-ede3-cbc', key, iv);
3232
cStream.end(plaintext);
3333
ciph = cStream.read();
3434

35-
var dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv);
35+
const dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv);
3636
dStream.end(ciph);
3737
txt = dStream.read().toString('utf8');
3838

@@ -42,16 +42,16 @@ function testCipher1(key, iv) {
4242

4343
function testCipher2(key, iv) {
4444
// Test encyrption and decryption with explicit key and iv
45-
var plaintext =
46-
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
47-
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
48-
'jAfaFg**';
49-
var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
50-
var ciph = cipher.update(plaintext, 'utf8', 'buffer');
45+
const plaintext =
46+
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
47+
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
48+
'jAfaFg**';
49+
const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
50+
let ciph = cipher.update(plaintext, 'utf8', 'buffer');
5151
ciph = Buffer.concat([ciph, cipher.final('buffer')]);
5252

53-
var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
54-
var txt = decipher.update(ciph, 'buffer', 'utf8');
53+
const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
54+
let txt = decipher.update(ciph, 'buffer', 'utf8');
5555
txt += decipher.final('utf8');
5656

5757
assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv');

0 commit comments

Comments
 (0)