2014-10-24 12:24:44 -03:00
|
|
|
var cryptoUtil = require('../util/crypto');
|
|
|
|
|
var InsightStorage = require('./InsightStorage');
|
|
|
|
|
var inherits = require('inherits');
|
|
|
|
|
|
|
|
|
|
function EncryptedInsightStorage(config) {
|
|
|
|
|
InsightStorage.apply(this, [config]);
|
|
|
|
|
}
|
|
|
|
|
inherits(EncryptedInsightStorage, InsightStorage);
|
|
|
|
|
|
|
|
|
|
EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
2014-10-28 12:01:09 -03:00
|
|
|
var key = cryptoUtil.kdfbinary(this.password + this.email);
|
2014-10-27 10:49:25 -03:00
|
|
|
InsightStorage.prototype.getItem.apply(this, [name,
|
|
|
|
|
function(err, body) {
|
|
|
|
|
var decryptedJson = cryptoUtil.decrypt(key, body);
|
|
|
|
|
if (!decryptedJson) {
|
|
|
|
|
return callback('Internal Error');
|
|
|
|
|
}
|
|
|
|
|
return callback(null, decryptedJson);
|
2014-10-24 12:24:44 -03:00
|
|
|
}
|
2014-10-27 10:49:25 -03:00
|
|
|
]);
|
2014-10-24 12:24:44 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
2014-10-28 12:01:09 -03:00
|
|
|
var key = cryptoUtil.kdfbinary(this.password + this.email);
|
2014-10-24 12:24:44 -03:00
|
|
|
var record = cryptoUtil.encrypt(key, value);
|
|
|
|
|
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-27 10:49:25 -03:00
|
|
|
EncryptedInsightStorage.prototype.removeItem = function(name, callback) {
|
2014-10-28 12:01:09 -03:00
|
|
|
var key = cryptoUtil.kdfbinary(this.password + this.email);
|
2014-10-27 10:49:25 -03:00
|
|
|
InsightStorage.prototype.removeItem.apply(this, [name, callback]);
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-24 12:24:44 -03:00
|
|
|
module.exports = EncryptedInsightStorage;
|