Merge branch 'nodejs-fixes' into standalone

Conflicts:
	src/crypto/random.js
This commit is contained in:
Robert Nelson 2014-01-09 08:04:21 -08:00
commit c951b64741

View File

@ -25,6 +25,11 @@ module.exports = LocalStore;
var openpgp = require('openpgp');
function LocalStore() {
if (typeof window != 'undefined' && window.localStorage) {
this.storage = window.localStorage;
} else {
this.storage = new (require('node-localstorage').LocalStorage)(openpgp.config.node_store);
}
}
/**
@ -32,16 +37,7 @@ function LocalStore() {
* @return {Array<module:key~Key>} array of keys retrieved from localstore
*/
LocalStore.prototype.load = function () {
var storage = null;
try {
storage = window.localStorage;
} catch (e) {
}
if (storage === null) {
storage = new (require('node-localstorage').LocalStorage)(openpgp.config.node_store);
}
var armoredKeys = JSON.parse(storage.getItem("armoredKeys"));
var armoredKeys = JSON.parse(this.storage.getItem('armoredKeys'));
var keys = [];
if (armoredKeys !== null && armoredKeys.length !== 0) {
var key;
@ -63,5 +59,5 @@ LocalStore.prototype.store = function (keys) {
for (var i = 0; i < keys.length; i++) {
armoredKeys.push(keys[i].armor());
}
window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
this.storage.setItem('armoredKeys', JSON.stringify(armoredKeys));
};