Remove Storage and Profile, Move folders, add EncryptedInsightStorage
This commit is contained in:
parent
de90f3eec2
commit
61b677498b
20 changed files with 374 additions and 1067 deletions
27
js/plugins/EncryptedInsightStorage.js
Normal file
27
js/plugins/EncryptedInsightStorage.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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) {
|
||||
var key = cryptoUtil.kdf(this.password, this.email);
|
||||
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);
|
||||
}]);
|
||||
};
|
||||
|
||||
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
||||
var key = cryptoUtil.kdf(this.password, this.email);
|
||||
var record = cryptoUtil.encrypt(key, value);
|
||||
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
||||
};
|
||||
|
||||
module.exports = EncryptedInsightStorage;
|
||||
Loading…
Add table
Add a link
Reference in a new issue