mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-14 19:42:05 +01:00
Remove caching from OpenPGP trust store
This commit is contained in:
parent
2c1af41249
commit
77f4273c3a
1 changed files with 0 additions and 27 deletions
|
@ -17,8 +17,6 @@
|
||||||
package org.jivesoftware.smackx.ox.store.abstr;
|
package org.jivesoftware.smackx.ox.store.abstr;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jivesoftware.smackx.ox.store.definition.OpenPgpTrustStore;
|
import org.jivesoftware.smackx.ox.store.definition.OpenPgpTrustStore;
|
||||||
|
|
||||||
|
@ -27,8 +25,6 @@ import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
|
|
||||||
public abstract class AbstractOpenPgpTrustStore implements OpenPgpTrustStore {
|
public abstract class AbstractOpenPgpTrustStore implements OpenPgpTrustStore {
|
||||||
|
|
||||||
private final Map<BareJid, Map<OpenPgpV4Fingerprint, Trust>> trustCache = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the trust record for the key with fingerprint {@code fingerprint} of user {@code owner} from local storage.
|
* Read the trust record for the key with fingerprint {@code fingerprint} of user {@code owner} from local storage.
|
||||||
* This method returns {@link Trust#undecided} in case that no trust record has been found.
|
* This method returns {@link Trust#undecided} in case that no trust record has been found.
|
||||||
|
@ -55,37 +51,14 @@ public abstract class AbstractOpenPgpTrustStore implements OpenPgpTrustStore {
|
||||||
@Override
|
@Override
|
||||||
public Trust getTrust(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException {
|
public Trust getTrust(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException {
|
||||||
Trust trust;
|
Trust trust;
|
||||||
Map<OpenPgpV4Fingerprint, Trust> trustMap = trustCache.get(owner);
|
|
||||||
|
|
||||||
if (trustMap != null) {
|
|
||||||
trust = trustMap.get(fingerprint);
|
|
||||||
if (trust != null) {
|
|
||||||
return trust;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
trustMap = new HashMap<>();
|
|
||||||
trustCache.put(owner, trustMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
trust = readTrust(owner, fingerprint);
|
trust = readTrust(owner, fingerprint);
|
||||||
trustMap.put(fingerprint, trust);
|
|
||||||
|
|
||||||
return trust;
|
return trust;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTrust(BareJid owner, OpenPgpV4Fingerprint fingerprint, Trust trust) throws IOException {
|
public void setTrust(BareJid owner, OpenPgpV4Fingerprint fingerprint, Trust trust) throws IOException {
|
||||||
Map<OpenPgpV4Fingerprint, Trust> trustMap = trustCache.get(owner);
|
|
||||||
if (trustMap == null) {
|
|
||||||
trustMap = new HashMap<>();
|
|
||||||
trustCache.put(owner, trustMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trustMap.get(fingerprint) == trust) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
trustMap.put(fingerprint, trust);
|
|
||||||
writeTrust(owner, fingerprint, trust);
|
writeTrust(owner, fingerprint, trust);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue