X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/9e1cd7e3988aff9db1ac72ec5f597dc9a6c0579a..2c86b0bd9a7abfd4a751fc1d6ab723d3a2c54c8a:/src/main/java/cli/JsonAxolotlStore.java diff --git a/src/main/java/cli/JsonAxolotlStore.java b/src/main/java/cli/JsonAxolotlStore.java index 02b9cdf1..cfed0cd8 100644 --- a/src/main/java/cli/JsonAxolotlStore.java +++ b/src/main/java/cli/JsonAxolotlStore.java @@ -1,6 +1,8 @@ package cli; -import org.json.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.whispersystems.libaxolotl.*; import org.whispersystems.libaxolotl.state.AxolotlStore; import org.whispersystems.libaxolotl.state.PreKeyRecord; @@ -11,17 +13,35 @@ import java.io.IOException; import java.util.List; class JsonAxolotlStore implements AxolotlStore { - private final JsonPreKeyStore preKeyStore; - private final JsonSessionStore sessionStore; - private final JsonSignedPreKeyStore signedPreKeyStore; - 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 +51,6 @@ 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();