]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/cli/JsonAxolotlStore.java
Make Json store use Jackson instead of Gson (as it's already linked)
[signal-cli] / src / main / java / cli / JsonAxolotlStore.java
index d260b6b07ba2a02fa38f7b3a861d236d2b5e96b9..57282f129d1bc5a87f11cc1957b28f534dd49769 100644 (file)
@@ -1,5 +1,8 @@
 package cli;
 
 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;
 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;
 
 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) {
     }
 
     public JsonAxolotlStore(IdentityKeyPair identityKeyPair, int registrationId) {
@@ -31,13 +52,6 @@ public class JsonAxolotlStore implements AxolotlStore {
         this.identityKeyStore = new JsonIdentityKeyStore(identityKeyPair, registrationId);
     }
 
         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();
     @Override
     public IdentityKeyPair getIdentityKeyPair() {
         return identityKeyStore.getIdentityKeyPair();