From 0f16fc4be4a2d002bd44b9e6794d50fb519510ef Mon Sep 17 00:00:00 2001 From: Lars Olzem Date: Wed, 5 Feb 2014 13:14:23 +0100 Subject: [PATCH] add variable item name in localstore --- src/keyring/localstore.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/keyring/localstore.js b/src/keyring/localstore.js index 587a0430..e3877431 100644 --- a/src/keyring/localstore.js +++ b/src/keyring/localstore.js @@ -19,25 +19,31 @@ * The class that deals with storage of the keyring. Currently the only option is to use HTML5 local storage. * @requires openpgp * @module keyring/localstore + * @param {String} item itemname in localstore */ module.exports = LocalStore; var openpgp = require('../'); -function LocalStore() { +function LocalStore(item) { if (typeof window != 'undefined' && window.localStorage) { this.storage = window.localStorage; } else { this.storage = new (require('node-localstorage').LocalStorage)(openpgp.config.node_store); } + if(typeof item == 'string') { + this.item = item; + } } +LocalStore.item = 'armoredKeys'; + /** * Load the keyring from HTML5 local storage and initializes this instance. * @return {Array} array of keys retrieved from localstore */ LocalStore.prototype.load = function () { - var armoredKeys = JSON.parse(this.storage.getItem('armoredKeys')); + var armoredKeys = JSON.parse(this.storage.getItem(this.item)); var keys = []; if (armoredKeys !== null && armoredKeys.length !== 0) { var key; @@ -59,5 +65,5 @@ LocalStore.prototype.store = function (keys) { for (var i = 0; i < keys.length; i++) { armoredKeys.push(keys[i].armor()); } - this.storage.setItem('armoredKeys', JSON.stringify(armoredKeys)); + this.storage.setItem(this.item, JSON.stringify(armoredKeys)); };