mirror of
https://github.com/nodejs/node.git
synced 2024-11-25 08:19:38 +01:00
becb4e980e
This commit distributes many of the various tests that were previously strewn about `test-crypto.js` into their own files, such as for Ciphers and Deciphers, Hashing, and HMACs. Copy pasta, and no style changes besides removing a few now-unnecessary closures. Helps eliminate file bloat and allows for easier test prognosis. PR-URL: https://github.com/iojs/io.js/pull/827 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
var common = require('../common');
|
|
var assert = require('assert');
|
|
var fs = require('fs');
|
|
|
|
try {
|
|
var crypto = require('crypto');
|
|
} catch (e) {
|
|
console.log('Not compiled with OPENSSL support.');
|
|
process.exit();
|
|
}
|
|
|
|
// Test certificates
|
|
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');
|
|
|
|
var 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');
|
|
|
|
var 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)');
|
|
|
|
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 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)');
|