X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/28e192c519c59d97d70aea6fabe18927e1aff42a..d0dae4e064ce2b41e4e6fcde786eec6e179656d6:/src/main/java/cli/JsonAxolotlStore.java diff --git a/src/main/java/cli/JsonAxolotlStore.java b/src/main/java/cli/JsonAxolotlStore.java index d260b6b0..e7eb054c 100644 --- a/src/main/java/cli/JsonAxolotlStore.java +++ b/src/main/java/cli/JsonAxolotlStore.java @@ -1,27 +1,49 @@ package cli; -import org.json.JSONObject; -import org.whispersystems.libaxolotl.*; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.whispersystems.libaxolotl.AxolotlAddress; +import org.whispersystems.libaxolotl.IdentityKey; +import org.whispersystems.libaxolotl.IdentityKeyPair; +import org.whispersystems.libaxolotl.InvalidKeyIdException; import org.whispersystems.libaxolotl.state.AxolotlStore; import org.whispersystems.libaxolotl.state.PreKeyRecord; import org.whispersystems.libaxolotl.state.SessionRecord; 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 +53,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();