diff options
author | Azul <azul@riseup.net> | 2018-01-31 12:27:55 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2018-01-31 13:32:50 +0100 |
commit | a55cc3653de22d868ade5303918280a38e8e9fe8 (patch) | |
tree | a2c697fa5e5787f4f8905c74554c737cfd76445e /app/models/keyring.rb | |
parent | 0a83272f33b0731ea61e47aec9019a3afeb3e975 (diff) |
keys: store type and rev in hash rather than serialized
Since the old keys used to be strings i started out by
json serializing the new keys with type, value, rev.
However storing serialized json in couch (json) does
not really make sense. So now we do not serialize but
instead have one json document. The lookup for a key of
type pgp may still return a string but for everything
that uses the new api it will return a hash with type
and revision.
This data structure is way easier to handle also on the
nickserver side.
Diffstat (limited to 'app/models/keyring.rb')
-rw-r--r-- | app/models/keyring.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/app/models/keyring.rb b/app/models/keyring.rb index 66f7bfd..a5320c2 100644 --- a/app/models/keyring.rb +++ b/app/models/keyring.rb @@ -20,13 +20,13 @@ class Keyring def create(type, value) raise Error, "key already exists" if storage.keys[type].present? - storage.set_key type, {type: type, value: value, rev: new_rev}.to_json + storage.set_key type, {type: type, value: value, rev: new_rev} storage.save end def update(type, rev:, value:) check_rev type, rev - storage.set_key type, {type: type, value: value, rev: new_rev}.to_json + storage.set_key type, {type: type, value: value, rev: new_rev} storage.save end @@ -37,7 +37,7 @@ class Keyring end def key_of_type(type) - JSON.parse(storage.keys[type]) if storage.keys[type] + storage.keys[type] end protected @@ -46,6 +46,9 @@ class Keyring def check_rev(type, rev) old = key_of_type(type) raise NotFound, type unless old + # We used to store plain strings. It's deprecated now. + # If we happen to run into them do not check their revision. + return if old.is_a? String raise Error, "wrong revision: #{rev}" unless old['rev'] == rev end |