X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/9e1cd7e3988aff9db1ac72ec5f597dc9a6c0579a..27d9424f1e7f607ac2dfad5b2164d065ffb79ef7:/src/main/java/cli/JsonPreKeyStore.java diff --git a/src/main/java/cli/JsonPreKeyStore.java b/src/main/java/cli/JsonPreKeyStore.java deleted file mode 100644 index a0133ec8..00000000 --- a/src/main/java/cli/JsonPreKeyStore.java +++ /dev/null @@ -1,67 +0,0 @@ -package cli; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.whispersystems.libaxolotl.InvalidKeyIdException; -import org.whispersystems.libaxolotl.state.PreKeyRecord; -import org.whispersystems.libaxolotl.state.PreKeyStore; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -class JsonPreKeyStore implements PreKeyStore { - - private final Map store = new HashMap<>(); - - public JsonPreKeyStore() { - - } - - public JsonPreKeyStore(JSONArray list) { - for (int i = 0; i < list.length(); i++) { - JSONObject k = list.getJSONObject(i); - try { - store.put(k.getInt("id"), Base64.decode(k.getString("record"))); - } catch (IOException e) { - System.out.println("Error while decoding prekey for: " + k.getString("name")); - } - } - } - - public JSONArray getJson() { - JSONArray result = new JSONArray(); - for (Integer id : store.keySet()) { - result.put(new JSONObject().put("id", id.toString()).put("record", Base64.encodeBytes(store.get(id)))); - } - return result; - } - - @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); - } -}