If you attempt to store an empty keylist then delete the storage key

This commit is contained in:
Matthew Shaylor 2015-08-11 21:59:45 +01:00 committed by evilaliv3
parent 068d38d832
commit 37ce176d42
2 changed files with 22 additions and 3 deletions

View File

@ -97,8 +97,12 @@ LocalStore.prototype.storePrivate = function (keys) {
function storeKeys(storage, itemname, keys) {
var armoredKeys = [];
for (var i = 0; i < keys.length; i++) {
armoredKeys.push(keys[i].armor());
if (keys.length) {
for (var i = 0; i < keys.length; i++) {
armoredKeys.push(keys[i].armor());
}
storage.setItem(itemname, JSON.stringify(armoredKeys));
} else {
storage.removeItem(itemname);
}
storage.setItem(itemname, JSON.stringify(armoredKeys));
}

View File

@ -248,6 +248,21 @@ describe("Keyring", function() {
expect(localstore3.loadPublic()).to.have.length(0);
});
it('emptying keyring and storing removes keys', function() {
var key = openpgp.key.readArmored(pubkey).keys[0];
var localstore = new openpgp.Keyring.localstore('remove-prefix-');
localstore.storePublic([]);
expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.null;
localstore.storePublic([key]);
expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.not.null;
localstore.storePublic([]);
expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.null;
})
it('removeKeysForId() - unknown id', function() {
keyring.publicKeys.importKey(pubkey);
keyring.publicKeys.importKey(pubkey2);