3 import com
.fasterxml
.jackson
.annotation
.JsonProperty
;
4 import com
.fasterxml
.jackson
.databind
.annotation
.JsonDeserialize
;
5 import com
.fasterxml
.jackson
.databind
.annotation
.JsonSerialize
;
6 import org
.json
.JSONObject
;
7 import org
.whispersystems
.libaxolotl
.*;
8 import org
.whispersystems
.libaxolotl
.state
.AxolotlStore
;
9 import org
.whispersystems
.libaxolotl
.state
.PreKeyRecord
;
10 import org
.whispersystems
.libaxolotl
.state
.SessionRecord
;
11 import org
.whispersystems
.libaxolotl
.state
.SignedPreKeyRecord
;
13 import java
.io
.IOException
;
14 import java
.util
.List
;
16 class JsonAxolotlStore
implements AxolotlStore
{
18 @JsonProperty("preKeys")
19 @JsonDeserialize(using
= JsonPreKeyStore
.JsonPreKeyStoreDeserializer
.class)
20 @JsonSerialize(using
= JsonPreKeyStore
.JsonPreKeyStoreSerializer
.class)
21 protected JsonPreKeyStore preKeyStore
;
23 @JsonProperty("sessionStore")
24 @JsonDeserialize(using
= JsonSessionStore
.JsonSessionStoreDeserializer
.class)
25 @JsonSerialize(using
= JsonSessionStore
.JsonPreKeyStoreSerializer
.class)
26 protected JsonSessionStore sessionStore
;
28 @JsonProperty("signedPreKeyStore")
29 @JsonDeserialize(using
= JsonSignedPreKeyStore
.JsonSignedPreKeyStoreDeserializer
.class)
30 @JsonSerialize(using
= JsonSignedPreKeyStore
.JsonSignedPreKeyStoreSerializer
.class)
31 protected JsonSignedPreKeyStore signedPreKeyStore
;
33 @JsonProperty("identityKeyStore")
34 @JsonDeserialize(using
= JsonIdentityKeyStore
.JsonIdentityKeyStoreDeserializer
.class)
35 @JsonSerialize(using
= JsonIdentityKeyStore
.JsonIdentityKeyStoreSerializer
.class)
36 protected JsonIdentityKeyStore identityKeyStore
;
38 public JsonAxolotlStore() {
41 public JsonAxolotlStore(JsonPreKeyStore preKeyStore
, JsonSessionStore sessionStore
, JsonSignedPreKeyStore signedPreKeyStore
, JsonIdentityKeyStore identityKeyStore
) {
42 this.preKeyStore
= preKeyStore
;
43 this.sessionStore
= sessionStore
;
44 this.signedPreKeyStore
= signedPreKeyStore
;
45 this.identityKeyStore
= identityKeyStore
;
48 public JsonAxolotlStore(IdentityKeyPair identityKeyPair
, int registrationId
) {
49 preKeyStore
= new JsonPreKeyStore();
50 sessionStore
= new JsonSessionStore();
51 signedPreKeyStore
= new JsonSignedPreKeyStore();
52 this.identityKeyStore
= new JsonIdentityKeyStore(identityKeyPair
, registrationId
);
56 public IdentityKeyPair
getIdentityKeyPair() {
57 return identityKeyStore
.getIdentityKeyPair();
61 public int getLocalRegistrationId() {
62 return identityKeyStore
.getLocalRegistrationId();
66 public void saveIdentity(String name
, IdentityKey identityKey
) {
67 identityKeyStore
.saveIdentity(name
, identityKey
);
71 public boolean isTrustedIdentity(String name
, IdentityKey identityKey
) {
72 return identityKeyStore
.isTrustedIdentity(name
, identityKey
);
76 public PreKeyRecord
loadPreKey(int preKeyId
) throws InvalidKeyIdException
{
77 return preKeyStore
.loadPreKey(preKeyId
);
81 public void storePreKey(int preKeyId
, PreKeyRecord
record) {
82 preKeyStore
.storePreKey(preKeyId
, record);
86 public boolean containsPreKey(int preKeyId
) {
87 return preKeyStore
.containsPreKey(preKeyId
);
91 public void removePreKey(int preKeyId
) {
92 preKeyStore
.removePreKey(preKeyId
);
96 public SessionRecord
loadSession(AxolotlAddress address
) {
97 return sessionStore
.loadSession(address
);
101 public List
<Integer
> getSubDeviceSessions(String name
) {
102 return sessionStore
.getSubDeviceSessions(name
);
106 public void storeSession(AxolotlAddress address
, SessionRecord
record) {
107 sessionStore
.storeSession(address
, record);
111 public boolean containsSession(AxolotlAddress address
) {
112 return sessionStore
.containsSession(address
);
116 public void deleteSession(AxolotlAddress address
) {
117 sessionStore
.deleteSession(address
);
121 public void deleteAllSessions(String name
) {
122 sessionStore
.deleteAllSessions(name
);
126 public SignedPreKeyRecord
loadSignedPreKey(int signedPreKeyId
) throws InvalidKeyIdException
{
127 return signedPreKeyStore
.loadSignedPreKey(signedPreKeyId
);
131 public List
<SignedPreKeyRecord
> loadSignedPreKeys() {
132 return signedPreKeyStore
.loadSignedPreKeys();
136 public void storeSignedPreKey(int signedPreKeyId
, SignedPreKeyRecord
record) {
137 signedPreKeyStore
.storeSignedPreKey(signedPreKeyId
, record);
141 public boolean containsSignedPreKey(int signedPreKeyId
) {
142 return signedPreKeyStore
.containsSignedPreKey(signedPreKeyId
);
146 public void removeSignedPreKey(int signedPreKeyId
) {
147 signedPreKeyStore
.removeSignedPreKey(signedPreKeyId
);