diff options
author | Jason Humphrey <Humphrey.jason32@gmail.com> | 2016-12-01 10:22:34 -0600 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-12-06 13:03:39 -0800 |
commit | a1bd070f87bfb7d32ef9ddee5c121d8eaf2f0c2b (patch) | |
tree | da9a96421fc7b148c8687e8cb3bb271417257314 /test/parallel/test-crypto-cipher-decipher.js | |
parent | a3a3937d7611d458f8b955db9941d29df9740abf (diff) | |
download | android-node-v8-a1bd070f87bfb7d32ef9ddee5c121d8eaf2f0c2b.tar.gz android-node-v8-a1bd070f87bfb7d32ef9ddee5c121d8eaf2f0c2b.tar.bz2 android-node-v8-a1bd070f87bfb7d32ef9ddee5c121d8eaf2f0c2b.zip |
test: use ES6 to update let & const
Also updating assertStrict and moving the assert required.
PR-URL: https://github.com/nodejs/node/pull/9917
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'test/parallel/test-crypto-cipher-decipher.js')
-rw-r--r-- | test/parallel/test-crypto-cipher-decipher.js | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js index c63bcd6f9e..e53f02edfa 100644 --- a/test/parallel/test-crypto-cipher-decipher.js +++ b/test/parallel/test-crypto-cipher-decipher.js @@ -1,6 +1,5 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); @@ -10,21 +9,22 @@ if (common.hasFipsCrypto) { common.skip('not supported in FIPS mode'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); +const assert = require('assert'); function testCipher1(key) { // Test encryption and decryption - var plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; - var cipher = crypto.createCipher('aes192', key); + const plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; + const cipher = crypto.createCipher('aes192', key); // encrypt plaintext which is in utf8 format // to a ciphertext which will be in hex - var ciph = cipher.update(plaintext, 'utf8', 'hex'); + let ciph = cipher.update(plaintext, 'utf8', 'hex'); // Only use binary or hex, not base64. ciph += cipher.final('hex'); - var decipher = crypto.createDecipher('aes192', key); - var txt = decipher.update(ciph, 'hex', 'utf8'); + const decipher = crypto.createDecipher('aes192', key); + let txt = decipher.update(ciph, 'hex', 'utf8'); txt += decipher.final('utf8'); assert.strictEqual(txt, plaintext, 'encryption and decryption'); @@ -33,11 +33,11 @@ function testCipher1(key) { // 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 // quite small, so there's no harm. - var cStream = crypto.createCipher('aes192', key); + const cStream = crypto.createCipher('aes192', key); cStream.end(plaintext); ciph = cStream.read(); - var dStream = crypto.createDecipher('aes192', key); + const dStream = crypto.createDecipher('aes192', key); dStream.end(ciph); txt = dStream.read().toString('utf8'); @@ -48,19 +48,19 @@ function testCipher1(key) { function testCipher2(key) { // encryption and decryption with Base64 // reported in https://github.com/joyent/node/issues/738 - var plaintext = + const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + 'jAfaFg**'; - var cipher = crypto.createCipher('aes256', key); + const cipher = crypto.createCipher('aes256', key); // encrypt plaintext which is in utf8 format // to a ciphertext which will be in Base64 - var ciph = cipher.update(plaintext, 'utf8', 'base64'); + let ciph = cipher.update(plaintext, 'utf8', 'base64'); ciph += cipher.final('base64'); - var decipher = crypto.createDecipher('aes256', key); - var txt = decipher.update(ciph, 'base64', 'utf8'); + const decipher = crypto.createDecipher('aes256', key); + let txt = decipher.update(ciph, 'base64', 'utf8'); txt += decipher.final('utf8'); assert.strictEqual(txt, plaintext, 'encryption and decryption with Base64'); @@ -119,12 +119,12 @@ testCipher2(Buffer.from('0123456789abcdef')); const key = '0123456789abcdef'; const plaintext = 'Top secret!!!'; const c = crypto.createCipher('aes192', key); - var ciph = c.update(plaintext, 'utf16le', 'base64'); + let ciph = c.update(plaintext, 'utf16le', 'base64'); ciph += c.final('base64'); - var decipher = crypto.createDecipher('aes192', key); + let decipher = crypto.createDecipher('aes192', key); - var txt; + let txt; assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2')); assert.doesNotThrow(() => txt += decipher.final('ucs2')); assert.strictEqual(txt, plaintext, 'decrypted result in ucs2'); |