1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 10:52:17 -05:00
mail/test/unit/forge-test.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2013-09-19 12:35:12 -04:00
define(['node-forge', 'cryptoLib/util', 'test/test-data'], function(forge, util, testData) {
2013-06-10 11:57:33 -04:00
'use strict';
module("Forge Crypto");
2013-06-10 16:02:29 -04:00
var forgeRsaTest = {
2013-06-10 11:57:33 -04:00
keySize: 1024,
2013-06-10 16:02:29 -04:00
testMessage: '06a9214036b8a15b512e03d534120006'
2013-06-10 11:57:33 -04:00
};
2013-06-10 16:02:29 -04:00
var forgeAesTest = {
2013-06-10 11:57:33 -04:00
keySize: 128,
2013-06-10 16:02:29 -04:00
testMessage: testData.generateBigString(1000)
2013-06-10 11:57:33 -04:00
};
test("SHA-1 Hash", 1, function() {
var sha1 = forge.md.sha1.create();
2013-06-10 16:02:29 -04:00
sha1.update(forgeAesTest.testMessage);
2013-06-10 11:57:33 -04:00
var digest = sha1.digest().toHex();
ok(digest, digest);
});
test("SHA-256 Hash", 1, function() {
2013-06-10 16:02:29 -04:00
forgeRsaTest.md = forge.md.sha256.create();
forgeRsaTest.md.update(forgeAesTest.testMessage);
var digest = forgeRsaTest.md.digest().toHex();
2013-06-10 11:57:33 -04:00
ok(digest, digest);
});
test("HMAC SHA-256", 1, function() {
2013-06-10 16:02:29 -04:00
var key = util.base642Str(util.random(forgeAesTest.keySize));
var iv = util.base642Str(util.random(forgeAesTest.keySize));
2013-06-10 11:57:33 -04:00
var hmac = forge.hmac.create();
hmac.start('sha256', key);
hmac.update(iv);
2013-06-10 16:02:29 -04:00
hmac.update(forgeAesTest.testMessage);
2013-06-10 11:57:33 -04:00
var digest = hmac.digest().toHex();
ok(digest, digest);
});
});