test: refactor test-crypto-cipheriv-decipheriv
Make change in test file from var to const/let. PR-URL: https://github.com/nodejs/node/pull/10018 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
b5453ee7b8
commit
07ef682c51
@ -1,25 +1,25 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
if (!common.hasCrypto) {
|
if (!common.hasCrypto) {
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
function testCipher1(key, iv) {
|
function testCipher1(key, iv) {
|
||||||
// Test encyrption and decryption with explicit key and iv
|
// Test encyrption and decryption with explicit key and iv
|
||||||
var plaintext =
|
const plaintext =
|
||||||
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
|
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
|
||||||
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
|
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
|
||||||
'jAfaFg**';
|
'jAfaFg**';
|
||||||
var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
|
const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
|
||||||
var ciph = cipher.update(plaintext, 'utf8', 'hex');
|
let ciph = cipher.update(plaintext, 'utf8', 'hex');
|
||||||
ciph += cipher.final('hex');
|
ciph += cipher.final('hex');
|
||||||
|
|
||||||
var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
|
const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
|
||||||
var txt = decipher.update(ciph, 'hex', 'utf8');
|
let txt = decipher.update(ciph, 'hex', 'utf8');
|
||||||
txt += decipher.final('utf8');
|
txt += decipher.final('utf8');
|
||||||
|
|
||||||
assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv');
|
assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv');
|
||||||
@ -28,11 +28,11 @@ function testCipher1(key, iv) {
|
|||||||
// NB: In real life, it's not guaranteed that you can get all of it
|
// NB: In real life, it's not guaranteed that you can get all of it
|
||||||
// in a single read() like this. But in this case, we know it's
|
// in a single read() like this. But in this case, we know it's
|
||||||
// quite small, so there's no harm.
|
// quite small, so there's no harm.
|
||||||
var cStream = crypto.createCipheriv('des-ede3-cbc', key, iv);
|
const cStream = crypto.createCipheriv('des-ede3-cbc', key, iv);
|
||||||
cStream.end(plaintext);
|
cStream.end(plaintext);
|
||||||
ciph = cStream.read();
|
ciph = cStream.read();
|
||||||
|
|
||||||
var dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv);
|
const dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv);
|
||||||
dStream.end(ciph);
|
dStream.end(ciph);
|
||||||
txt = dStream.read().toString('utf8');
|
txt = dStream.read().toString('utf8');
|
||||||
|
|
||||||
@ -42,16 +42,16 @@ function testCipher1(key, iv) {
|
|||||||
|
|
||||||
function testCipher2(key, iv) {
|
function testCipher2(key, iv) {
|
||||||
// Test encyrption and decryption with explicit key and iv
|
// Test encyrption and decryption with explicit key and iv
|
||||||
var plaintext =
|
const plaintext =
|
||||||
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
|
'32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
|
||||||
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
|
'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
|
||||||
'jAfaFg**';
|
'jAfaFg**';
|
||||||
var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
|
const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv);
|
||||||
var ciph = cipher.update(plaintext, 'utf8', 'buffer');
|
let ciph = cipher.update(plaintext, 'utf8', 'buffer');
|
||||||
ciph = Buffer.concat([ciph, cipher.final('buffer')]);
|
ciph = Buffer.concat([ciph, cipher.final('buffer')]);
|
||||||
|
|
||||||
var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
|
const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
|
||||||
var txt = decipher.update(ciph, 'buffer', 'utf8');
|
let txt = decipher.update(ciph, 'buffer', 'utf8');
|
||||||
txt += decipher.final('utf8');
|
txt += decipher.final('utf8');
|
||||||
|
|
||||||
assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv');
|
assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user