1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -05:00

integrated crypto lib changes into device storage dao

This commit is contained in:
Tankred Hase 2013-05-23 22:33:44 +02:00
parent 1e27297013
commit bdab0e19c1
2 changed files with 8 additions and 4 deletions

View File

@ -43,13 +43,13 @@ app.dao.DeviceStorage = function(util, crypto, jsonDao, sqlcipherDao) {
* @param offset [Number] The offset of items to fetch (0 is the last stored item)
* @param num [Number] The number of items to fetch (null means fetch all)
*/
this.listItems = function(type, offset, num, callback) {
this.listItems = function(type, offset, num, senderPubkeys, callback) {
// fetch all items of a certain type from the data-store
jsonDao.list(crypto.emailAddress + '_' + type, offset, num, function(encryptedList) {
// decrypt list
crypto.decryptListForUser(encryptedList, null, function(err, decryptedList) {
crypto.decryptListForUser(encryptedList, senderPubkeys, function(err, decryptedList) {
callback(err, decryptedList);
});
});

View File

@ -39,7 +39,9 @@ asyncTest("Init", 3, function() {
});
asyncTest("Encrypt list for user", 2, function() {
devicestorage_test.crypto.encryptListForUser(devicestorage_test.list, null, function(err, encryptedList) {
var receiverPubkeys = [devicestorage_test.crypto.getPublicKey()];
devicestorage_test.crypto.encryptListForUser(devicestorage_test.list, receiverPubkeys, function(err, encryptedList) {
ok(!err);
equal(encryptedList.length, devicestorage_test.list.length, 'Encrypt list');
@ -58,11 +60,13 @@ asyncTest("Store encrypted list", 1, function() {
asyncTest("List items", 3, function() {
var senderPubkeys = [devicestorage_test.crypto.getPublicKey()];
var offset = 2,
num = 6;
// list items from storage (decrypted)
devicestorage_test.storage.listItems('email_inbox_5', offset, num, function(err, decryptedList) {
devicestorage_test.storage.listItems('email_inbox_5', offset, num, senderPubkeys, function(err, decryptedList) {
ok(!err);
equal(decryptedList.length, num, 'Found ' + decryptedList.length + ' items in store (and decrypted)');