mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: remove var redeclarations in test-crypto-*
PR-URL: https://github.com/nodejs/node/pull/4981 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
f7feab5b3b
commit
2c97bd47e4
@ -46,11 +46,11 @@ assert.throws(function() {
|
||||
}, 'not enough data');
|
||||
|
||||
// Test HMAC
|
||||
var h1 = crypto.createHmac('sha1', 'Node')
|
||||
.update('some data')
|
||||
.update('to hmac')
|
||||
.digest('hex');
|
||||
assert.equal(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', 'test HMAC');
|
||||
const hmacHash = crypto.createHmac('sha1', 'Node')
|
||||
.update('some data')
|
||||
.update('to hmac')
|
||||
.digest('hex');
|
||||
assert.equal(hmacHash, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', 'test HMAC');
|
||||
|
||||
// Test HMAC-SHA-* (rfc 4231 Test Cases)
|
||||
var rfc4231 = [
|
||||
@ -199,7 +199,7 @@ var rfc4231 = [
|
||||
}
|
||||
];
|
||||
|
||||
for (var i = 0, l = rfc4231.length; i < l; i++) {
|
||||
for (let i = 0, l = rfc4231.length; i < l; i++) {
|
||||
for (var hash in rfc4231[i]['hmac']) {
|
||||
var result = crypto.createHmac(hash, rfc4231[i]['key'])
|
||||
.update(rfc4231[i]['data'])
|
||||
@ -322,7 +322,7 @@ var rfc2202_sha1 = [
|
||||
}
|
||||
];
|
||||
|
||||
for (var i = 0, l = rfc2202_md5.length; i < l; i++) {
|
||||
for (let i = 0, l = rfc2202_md5.length; i < l; i++) {
|
||||
if (!common.hasFipsCrypto) {
|
||||
assert.equal(rfc2202_md5[i]['hmac'],
|
||||
crypto.createHmac('md5', rfc2202_md5[i]['key'])
|
||||
@ -331,7 +331,7 @@ for (var i = 0, l = rfc2202_md5.length; i < l; i++) {
|
||||
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202');
|
||||
}
|
||||
}
|
||||
for (var i = 0, l = rfc2202_sha1.length; i < l; i++) {
|
||||
for (let i = 0, l = rfc2202_sha1.length; i < l; i++) {
|
||||
assert.equal(rfc2202_sha1[i]['hmac'],
|
||||
crypto.createHmac('sha1', rfc2202_sha1[i]['key'])
|
||||
.update(rfc2202_sha1[i]['data'])
|
||||
@ -394,29 +394,29 @@ assert.throws(function() {
|
||||
var s1 = crypto.createSign('RSA-SHA1')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'base64');
|
||||
var verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s1, 'base64');
|
||||
assert.strictEqual(verified, true, 'sign and verify (base 64)');
|
||||
var s1Verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s1, 'base64');
|
||||
assert.strictEqual(s1Verified, true, 'sign and verify (base 64)');
|
||||
|
||||
var s2 = crypto.createSign('RSA-SHA256')
|
||||
.update('Test123')
|
||||
.sign(keyPem); // binary
|
||||
var verified = crypto.createVerify('RSA-SHA256')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s2); // binary
|
||||
assert.strictEqual(verified, true, 'sign and verify (binary)');
|
||||
var s2Verified = crypto.createVerify('RSA-SHA256')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s2); // binary
|
||||
assert.strictEqual(s2Verified, true, 'sign and verify (binary)');
|
||||
|
||||
var s3 = crypto.createSign('RSA-SHA1')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'buffer');
|
||||
var verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s3);
|
||||
assert.strictEqual(verified, true, 'sign and verify (buffer)');
|
||||
var s3Verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s3);
|
||||
assert.strictEqual(s3Verified, true, 'sign and verify (buffer)');
|
||||
|
||||
|
||||
function testCipher1(key) {
|
||||
|
@ -59,14 +59,14 @@ var wikipedia = [
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0, l = wikipedia.length; i < l; i++) {
|
||||
for (var hash in wikipedia[i]['hmac']) {
|
||||
for (let i = 0, l = wikipedia.length; i < l; i++) {
|
||||
for (const hash in wikipedia[i]['hmac']) {
|
||||
// FIPS does not support MD5.
|
||||
if (common.hasFipsCrypto && hash == 'md5')
|
||||
continue;
|
||||
var result = crypto.createHmac(hash, wikipedia[i]['key'])
|
||||
.update(wikipedia[i]['data'])
|
||||
.digest('hex');
|
||||
const result = crypto.createHmac(hash, wikipedia[i]['key'])
|
||||
.update(wikipedia[i]['data'])
|
||||
.digest('hex');
|
||||
assert.equal(wikipedia[i]['hmac'][hash],
|
||||
result,
|
||||
'Test HMAC-' + hash + ': Test case ' + (i + 1) + ' wikipedia');
|
||||
@ -221,14 +221,14 @@ var rfc4231 = [
|
||||
}
|
||||
];
|
||||
|
||||
for (var i = 0, l = rfc4231.length; i < l; i++) {
|
||||
for (var hash in rfc4231[i]['hmac']) {
|
||||
var str = crypto.createHmac(hash, rfc4231[i].key);
|
||||
for (let i = 0, l = rfc4231.length; i < l; i++) {
|
||||
for (const hash in rfc4231[i]['hmac']) {
|
||||
const str = crypto.createHmac(hash, rfc4231[i].key);
|
||||
str.end(rfc4231[i].data);
|
||||
var strRes = str.read().toString('hex');
|
||||
var result = crypto.createHmac(hash, rfc4231[i]['key'])
|
||||
.update(rfc4231[i]['data'])
|
||||
.digest('hex');
|
||||
let strRes = str.read().toString('hex');
|
||||
let result = crypto.createHmac(hash, rfc4231[i]['key'])
|
||||
.update(rfc4231[i]['data'])
|
||||
.digest('hex');
|
||||
if (rfc4231[i]['truncate']) {
|
||||
result = result.substr(0, 32); // first 128 bits == 32 hex chars
|
||||
strRes = strRes.substr(0, 32);
|
||||
@ -350,7 +350,7 @@ var rfc2202_sha1 = [
|
||||
];
|
||||
|
||||
if (!common.hasFipsCrypto) {
|
||||
for (var i = 0, l = rfc2202_md5.length; i < l; i++) {
|
||||
for (let i = 0, l = rfc2202_md5.length; i < l; i++) {
|
||||
assert.equal(rfc2202_md5[i]['hmac'],
|
||||
crypto.createHmac('md5', rfc2202_md5[i]['key'])
|
||||
.update(rfc2202_md5[i]['data'])
|
||||
@ -358,7 +358,7 @@ if (!common.hasFipsCrypto) {
|
||||
'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202');
|
||||
}
|
||||
}
|
||||
for (var i = 0, l = rfc2202_sha1.length; i < l; i++) {
|
||||
for (let i = 0, l = rfc2202_sha1.length; i < l; i++) {
|
||||
assert.equal(rfc2202_sha1[i]['hmac'],
|
||||
crypto.createHmac('sha1', rfc2202_sha1[i]['key'])
|
||||
.update(rfc2202_sha1[i]['data'])
|
||||
|
@ -227,28 +227,30 @@ assert.throws(function() {
|
||||
//
|
||||
// Test DSA signing and verification with encrypted key
|
||||
//
|
||||
(function() {
|
||||
var input = 'I AM THE WALRUS';
|
||||
const input = 'I AM THE WALRUS';
|
||||
|
||||
var sign = crypto.createSign('DSS1');
|
||||
{
|
||||
const sign = crypto.createSign('DSS1');
|
||||
sign.update(input);
|
||||
assert.throws(function() {
|
||||
sign.sign({ key: dsaKeyPemEncrypted, passphrase: 'wrong' }, 'hex');
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
// DSA signatures vary across runs so there is no static string to verify
|
||||
// against
|
||||
var sign = crypto.createSign('DSS1');
|
||||
const sign = crypto.createSign('DSS1');
|
||||
sign.update(input);
|
||||
|
||||
var signature;
|
||||
let signature;
|
||||
assert.doesNotThrow(function() {
|
||||
var signOptions = { key: dsaKeyPemEncrypted, passphrase: 'password' };
|
||||
const signOptions = { key: dsaKeyPemEncrypted, passphrase: 'password' };
|
||||
signature = sign.sign(signOptions, 'hex');
|
||||
});
|
||||
|
||||
var verify = crypto.createVerify('DSS1');
|
||||
const verify = crypto.createVerify('DSS1');
|
||||
verify.update(input);
|
||||
|
||||
assert.strictEqual(verify.verify(dsaPubPem, signature, 'hex'), true);
|
||||
})();
|
||||
}
|
||||
|
@ -14,53 +14,59 @@ var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');
|
||||
var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii');
|
||||
|
||||
// Test signing and verifying
|
||||
var s1 = crypto.createSign('RSA-SHA1')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'base64');
|
||||
var s1stream = crypto.createSign('RSA-SHA1');
|
||||
s1stream.end('Test123');
|
||||
s1stream = s1stream.sign(keyPem, 'base64');
|
||||
assert.equal(s1, s1stream, 'Stream produces same output');
|
||||
{
|
||||
const s1 = crypto.createSign('RSA-SHA1')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'base64');
|
||||
let s1stream = crypto.createSign('RSA-SHA1');
|
||||
s1stream.end('Test123');
|
||||
s1stream = s1stream.sign(keyPem, 'base64');
|
||||
assert.equal(s1, s1stream, 'Stream produces same output');
|
||||
|
||||
var verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s1, 'base64');
|
||||
assert.strictEqual(verified, true, 'sign and verify (base 64)');
|
||||
const verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s1, 'base64');
|
||||
assert.strictEqual(verified, true, 'sign and verify (base 64)');
|
||||
}
|
||||
|
||||
var s2 = crypto.createSign('RSA-SHA256')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'binary');
|
||||
var s2stream = crypto.createSign('RSA-SHA256');
|
||||
s2stream.end('Test123');
|
||||
s2stream = s2stream.sign(keyPem, 'binary');
|
||||
assert.equal(s2, s2stream, 'Stream produces same output');
|
||||
{
|
||||
const s2 = crypto.createSign('RSA-SHA256')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'binary');
|
||||
let s2stream = crypto.createSign('RSA-SHA256');
|
||||
s2stream.end('Test123');
|
||||
s2stream = s2stream.sign(keyPem, 'binary');
|
||||
assert.equal(s2, s2stream, 'Stream produces same output');
|
||||
|
||||
var verified = crypto.createVerify('RSA-SHA256')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s2, 'binary');
|
||||
assert.strictEqual(verified, true, 'sign and verify (binary)');
|
||||
let verified = crypto.createVerify('RSA-SHA256')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s2, 'binary');
|
||||
assert.strictEqual(verified, true, 'sign and verify (binary)');
|
||||
|
||||
var verStream = crypto.createVerify('RSA-SHA256');
|
||||
verStream.write('Tes');
|
||||
verStream.write('t12');
|
||||
verStream.end('3');
|
||||
verified = verStream.verify(certPem, s2, 'binary');
|
||||
assert.strictEqual(verified, true, 'sign and verify (stream)');
|
||||
const verStream = crypto.createVerify('RSA-SHA256');
|
||||
verStream.write('Tes');
|
||||
verStream.write('t12');
|
||||
verStream.end('3');
|
||||
verified = verStream.verify(certPem, s2, 'binary');
|
||||
assert.strictEqual(verified, true, 'sign and verify (stream)');
|
||||
}
|
||||
|
||||
var s3 = crypto.createSign('RSA-SHA1')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'buffer');
|
||||
var verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s3);
|
||||
assert.strictEqual(verified, true, 'sign and verify (buffer)');
|
||||
{
|
||||
const s3 = crypto.createSign('RSA-SHA1')
|
||||
.update('Test123')
|
||||
.sign(keyPem, 'buffer');
|
||||
let verified = crypto.createVerify('RSA-SHA1')
|
||||
.update('Test')
|
||||
.update('123')
|
||||
.verify(certPem, s3);
|
||||
assert.strictEqual(verified, true, 'sign and verify (buffer)');
|
||||
|
||||
var verStream = crypto.createVerify('RSA-SHA1');
|
||||
verStream.write('Tes');
|
||||
verStream.write('t12');
|
||||
verStream.end('3');
|
||||
verified = verStream.verify(certPem, s3);
|
||||
assert.strictEqual(verified, true, 'sign and verify (stream)');
|
||||
const verStream = crypto.createVerify('RSA-SHA1');
|
||||
verStream.write('Tes');
|
||||
verStream.write('t12');
|
||||
verStream.end('3');
|
||||
verified = verStream.verify(certPem, s3);
|
||||
assert.strictEqual(verified, true, 'sign and verify (stream)');
|
||||
}
|
||||
|
@ -67,7 +67,6 @@ assert.equal(-1, crypto.getCiphers().indexOf('AES-128-CBC'));
|
||||
assertSorted(crypto.getCiphers());
|
||||
|
||||
// Assume that we have at least AES256-SHA.
|
||||
var tls = require('tls');
|
||||
assert.notEqual(0, tls.getCiphers().length);
|
||||
assert.notEqual(-1, tls.getCiphers().indexOf('aes256-sha'));
|
||||
assert.equal(-1, tls.getCiphers().indexOf('AES256-SHA'));
|
||||
|
Loading…
Reference in New Issue
Block a user