update becnhmark test
This commit is contained in:
parent
afabb56d41
commit
01a0a218c7
|
@ -61,23 +61,51 @@ describe('Basic', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
it('Performance test', function (done) {
|
it('Performance test', function (done) {
|
||||||
|
// init test data
|
||||||
function randomString(length, chars) {
|
function randomString(length, chars) {
|
||||||
var result = '';
|
var result = '';
|
||||||
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
|
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
var rString = randomString(1024*1024, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
var message = randomString(1024*1024*3, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||||
|
|
||||||
|
var userid = 'Test McTestington <test@example.com>';
|
||||||
|
var passphrase = 'password';
|
||||||
|
|
||||||
|
var key = openpgp.generateKeyPair(openpgp.enums.publicKey.rsa_encrypt_sign, 512, userid, passphrase);
|
||||||
|
|
||||||
|
var info = '\npassphrase: ' + passphrase + '\n' + 'userid: ' + userid + '\n' + 'message: ' + message;
|
||||||
|
|
||||||
|
var privKeys = openpgp.key.readArmored(key.privateKeyArmored);
|
||||||
|
var publicKeys = openpgp.key.readArmored(key.publicKeyArmored);
|
||||||
|
|
||||||
|
var privKey = privKeys.keys[0];
|
||||||
|
var pubKey = publicKeys.keys[0];
|
||||||
|
|
||||||
|
var success = privKey.decrypt(passphrase);
|
||||||
|
|
||||||
if (console.profile) {
|
if (console.profile) {
|
||||||
console.profile("encrypt/sign/verify/decrypt");
|
console.profile("encrypt/sign/verify/decrypt");
|
||||||
}
|
}
|
||||||
|
|
||||||
testHelper('password', 'Test McTestington <test@example.com>', rString);
|
var encrypted = openpgp.signAndEncryptMessage([pubKey], privKey, message);
|
||||||
|
|
||||||
if (console.profileEnd) {
|
if (console.profileEnd) {
|
||||||
console.profileEnd();
|
console.profileEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var msg = openpgp.message.readArmored(encrypted);
|
||||||
|
|
||||||
|
var keyids = msg.getEncryptionKeyIds();
|
||||||
|
|
||||||
|
expect(keyids).to.exist;
|
||||||
|
|
||||||
|
var decrypted = openpgp.decryptAndVerifyMessage(privKey, [pubKey], msg);
|
||||||
|
|
||||||
|
expect(decrypted).to.exist;
|
||||||
|
expect(decrypted.signatures[0].valid).to.be.true;
|
||||||
|
expect(decrypted.text).to.equal(message);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user