1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-10 11:15:01 -05:00
mail/test/unit/crypto/crypto-test.js
2014-11-21 15:06:29 +01:00

55 lines
1.5 KiB
JavaScript

'use strict';
var Crypto = require('../../../src/js/crypto/crypto'),
config = require('../../../src/js/app-config').config,
util = require('crypto-lib').util;
describe('Crypto unit tests', function() {
this.timeout(20000);
var crypto,
password = 'password',
keySize = config.symKeySize,
ivSize = config.symIvSize;
beforeEach(function() {
crypto = new Crypto();
});
afterEach(function() {});
describe('AES encrypt/decrypt', function() {
it('should work', function(done) {
var plaintext = 'Hello, World!';
var key = util.random(keySize);
var iv = util.random(ivSize);
crypto.encrypt(plaintext, key, iv, function(err, ciphertext) {
expect(err).to.not.exist;
expect(ciphertext).to.exist;
crypto.decrypt(ciphertext, key, iv, function(err, decrypted) {
expect(err).to.not.exist;
expect(decrypted).to.equal(plaintext);
done();
});
});
});
});
describe("PBKDF2 (Async/Worker)", function() {
it('should work', function(done) {
var salt = util.random(keySize);
crypto.deriveKey(password, salt, keySize, function(err, key) {
expect(err).to.not.exist;
expect(util.base642Str(key).length * 8).to.equal(keySize);
done();
});
});
});
});