diff options
author | Moxie Marlinspike <moxie@thoughtcrime.org> | 2015-02-10 20:16:27 -0800 |
---|---|---|
committer | Moxie Marlinspike <moxie@thoughtcrime.org> | 2015-02-10 20:16:27 -0800 |
commit | 81e91efb3a07bbacffd258c1fb19be12eea4f68b (patch) | |
tree | d6b9ac7b2100f04fddd8e9127262ef96c3652437 /tests/src/test/java/org/whispersystems/libaxolotl/InMemoryPreKeyStore.java | |
parent | a9c42a3641cedec38b555f032d3206ae84e25463 (diff) |
Fix for tests in Android Studio
Diffstat (limited to 'tests/src/test/java/org/whispersystems/libaxolotl/InMemoryPreKeyStore.java')
-rw-r--r-- | tests/src/test/java/org/whispersystems/libaxolotl/InMemoryPreKeyStore.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/src/test/java/org/whispersystems/libaxolotl/InMemoryPreKeyStore.java b/tests/src/test/java/org/whispersystems/libaxolotl/InMemoryPreKeyStore.java new file mode 100644 index 00000000..a2ea6811 --- /dev/null +++ b/tests/src/test/java/org/whispersystems/libaxolotl/InMemoryPreKeyStore.java @@ -0,0 +1,41 @@ +package org.whispersystems.libaxolotl; + +import org.whispersystems.libaxolotl.state.PreKeyRecord; +import org.whispersystems.libaxolotl.state.PreKeyStore; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class InMemoryPreKeyStore implements PreKeyStore { + + private final Map<Integer, byte[]> store = new HashMap<>(); + + @Override + public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException { + try { + if (!store.containsKey(preKeyId)) { + throw new InvalidKeyIdException("No such prekeyrecord!"); + } + + return new PreKeyRecord(store.get(preKeyId)); + } catch (IOException e) { + throw new AssertionError(e); + } + } + + @Override + public void storePreKey(int preKeyId, PreKeyRecord record) { + store.put(preKeyId, record.serialize()); + } + + @Override + public boolean containsPreKey(int preKeyId) { + return store.containsKey(preKeyId); + } + + @Override + public void removePreKey(int preKeyId) { + store.remove(preKeyId); + } +} |