X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/28e192c519c59d97d70aea6fabe18927e1aff42a..4d83d2168ae78fd414a4dcce5aa630df240aedb8:/src/main/java/cli/JsonAxolotlStore.java diff --git a/src/main/java/cli/JsonAxolotlStore.java b/src/main/java/cli/JsonAxolotlStore.java index d260b6b0..57282f12 100644 --- a/src/main/java/cli/JsonAxolotlStore.java +++ b/src/main/java/cli/JsonAxolotlStore.java @@ -1,5 +1,8 @@ package cli; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.json.JSONObject; import org.whispersystems.libaxolotl.*; import org.whispersystems.libaxolotl.state.AxolotlStore; @@ -10,18 +13,36 @@ import org.whispersystems.libaxolotl.state.SignedPreKeyRecord; import java.io.IOException; import java.util.List; -public class JsonAxolotlStore implements AxolotlStore { - private final JsonPreKeyStore preKeyStore; - private final JsonSessionStore sessionStore; - private final JsonSignedPreKeyStore signedPreKeyStore; +class JsonAxolotlStore implements AxolotlStore { - private final JsonIdentityKeyStore identityKeyStore; + @JsonProperty("preKeys") + @JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class) + @JsonSerialize(using = JsonPreKeyStore.JsonPreKeyStoreSerializer.class) + protected JsonPreKeyStore preKeyStore; - public JsonAxolotlStore(JSONObject jsonAxolotl) throws IOException, InvalidKeyException { - this.preKeyStore = new JsonPreKeyStore(jsonAxolotl.getJSONArray("preKeys")); - this.sessionStore = new JsonSessionStore(jsonAxolotl.getJSONArray("sessionStore")); - this.signedPreKeyStore = new JsonSignedPreKeyStore(jsonAxolotl.getJSONArray("signedPreKeyStore")); - this.identityKeyStore = new JsonIdentityKeyStore(jsonAxolotl.getJSONObject("identityKeyStore")); + @JsonProperty("sessionStore") + @JsonDeserialize(using = JsonSessionStore.JsonSessionStoreDeserializer.class) + @JsonSerialize(using = JsonSessionStore.JsonPreKeyStoreSerializer.class) + protected JsonSessionStore sessionStore; + + @JsonProperty("signedPreKeyStore") + @JsonDeserialize(using = JsonSignedPreKeyStore.JsonSignedPreKeyStoreDeserializer.class) + @JsonSerialize(using = JsonSignedPreKeyStore.JsonSignedPreKeyStoreSerializer.class) + protected JsonSignedPreKeyStore signedPreKeyStore; + + @JsonProperty("identityKeyStore") + @JsonDeserialize(using = JsonIdentityKeyStore.JsonIdentityKeyStoreDeserializer.class) + @JsonSerialize(using = JsonIdentityKeyStore.JsonIdentityKeyStoreSerializer.class) + protected JsonIdentityKeyStore identityKeyStore; + + public JsonAxolotlStore() { + } + + public JsonAxolotlStore(JsonPreKeyStore preKeyStore, JsonSessionStore sessionStore, JsonSignedPreKeyStore signedPreKeyStore, JsonIdentityKeyStore identityKeyStore) { + this.preKeyStore = preKeyStore; + this.sessionStore = sessionStore; + this.signedPreKeyStore = signedPreKeyStore; + this.identityKeyStore = identityKeyStore; } public JsonAxolotlStore(IdentityKeyPair identityKeyPair, int registrationId) { @@ -31,13 +52,6 @@ public class JsonAxolotlStore implements AxolotlStore { this.identityKeyStore = new JsonIdentityKeyStore(identityKeyPair, registrationId); } - public JSONObject getJson() { - return new JSONObject().put("preKeys", preKeyStore.getJson()) - .put("sessionStore", sessionStore.getJson()) - .put("signedPreKeyStore", signedPreKeyStore.getJson()) - .put("identityKeyStore", identityKeyStore.getJson()); - } - @Override public IdentityKeyPair getIdentityKeyPair() { return identityKeyStore.getIdentityKeyPair();