OpenPGP Key Storage (Settings) (#53)

Import, Delete, Generate, View
This commit is contained in:
RainLoop Team 2014-03-13 02:29:33 +04:00
parent 5a5c6af2c6
commit 5ece4cc0ec
47 changed files with 1333 additions and 539 deletions

View file

@ -12,7 +12,6 @@ LocalStorageDriver.supported = function ()
return !!window.localStorage;
};
/**
* @param {string} sKey
* @param {*} mData
@ -21,14 +20,14 @@ LocalStorageDriver.supported = function ()
LocalStorageDriver.prototype.set = function (sKey, mData)
{
var
mCokieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null,
mCookieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null,
bResult = false,
mResult = null
;
try
{
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue);
mResult = null === mCookieValue ? null : JSON.parse(mCookieValue);
if (!mResult)
{
mResult = {};

View file

@ -0,0 +1,60 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
*/
function OpenPgpLocalStorageDriver()
{
}
/*
* Declare the localstore itemname
*/
OpenPgpLocalStorageDriver.prototype.item = 'armoredRainLoopKeys';
/**
* Load the keyring from HTML5 local storage and initializes this instance.
* @return {Array<module:key~Key>} array of keys retrieved from localstore
*/
OpenPgpLocalStorageDriver.prototype.load = function ()
{
var
iIndex = 0,
iLen = 0,
aKeys = [],
aArmoredKeys = JSON.parse(window.localStorage.getItem(this.item))
;
if (aArmoredKeys && 0 < aArmoredKeys.length)
{
for (iLen = aArmoredKeys.length; iIndex < iLen; iIndex++)
{
aKeys.push(
window.openpgp.key.readArmored(aArmoredKeys[iIndex]).keys[0]
);
}
}
return aKeys;
};
/**
* Saves the current state of the keyring to HTML5 local storage.
* The privateKeys array and publicKeys array gets Stringified using JSON
* @param {Array<module:key~Key>} aKeys array of keys to save in localstore
*/
OpenPgpLocalStorageDriver.prototype.store = function (aKeys)
{
var
iIndex = 0,
iLen = aKeys.length,
aArmoredKeys = []
;
for (; iIndex < iLen; iIndex++)
{
aArmoredKeys.push(aKeys[iIndex].armor());
}
window.localStorage.setItem(this.item, JSON.stringify(aArmoredKeys));
};

View file

@ -343,6 +343,9 @@ function WebMailDataStorage()
// other
this.useKeyboardShortcuts = ko.observable(true);
this.openpgpkeys = ko.observableArray([]);
this.openpgpKeyring = null;
// google
this.googleActions = ko.observable(false);