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
.whispersystems
.libaxolotl
.*;
7 import org
.whispersystems
.libaxolotl
.state
.AxolotlStore
;
8 import org
.whispersystems
.libaxolotl
.state
.PreKeyRecord
;
9 import org
.whispersystems
.libaxolotl
.state
.SessionRecord
;
10 import org
.whispersystems
.libaxolotl
.state
.SignedPreKeyRecord
;
12 import java
.io
.IOException
;
13 import java
.util
.List
;
15 class JsonAxolotlStore
implements AxolotlStore
{
17 @JsonProperty("preKeys")
18 @JsonDeserialize(using
= JsonPreKeyStore
.JsonPreKeyStoreDeserializer
.class)
19 @JsonSerialize(using
= JsonPreKeyStore
.JsonPreKeyStoreSerializer
.class)
20 protected JsonPreKeyStore preKeyStore
;
22 @JsonProperty("sessionStore")
23 @JsonDeserialize(using
= JsonSessionStore
.JsonSessionStoreDeserializer
.class)
24 @JsonSerialize(using
= JsonSessionStore
.JsonPreKeyStoreSerializer
.class)
25 protected JsonSessionStore sessionStore
;
27 @JsonProperty("signedPreKeyStore")
28 @JsonDeserialize(using
= JsonSignedPreKeyStore
.JsonSignedPreKeyStoreDeserializer
.class)
29 @JsonSerialize(using
= JsonSignedPreKeyStore
.JsonSignedPreKeyStoreSerializer
.class)
30 protected JsonSignedPreKeyStore signedPreKeyStore
;
32 @JsonProperty("identityKeyStore")
33 @JsonDeserialize(using
= JsonIdentityKeyStore
.JsonIdentityKeyStoreDeserializer
.class)
34 @JsonSerialize(using
= JsonIdentityKeyStore
.JsonIdentityKeyStoreSerializer
.class)
35 protected JsonIdentityKeyStore identityKeyStore
;
37 public JsonAxolotlStore() {
40 public JsonAxolotlStore(JsonPreKeyStore preKeyStore
, JsonSessionStore sessionStore
, JsonSignedPreKeyStore signedPreKeyStore
, JsonIdentityKeyStore identityKeyStore
) {
41 this.preKeyStore
= preKeyStore
;
42 this.sessionStore
= sessionStore
;
43 this.signedPreKeyStore
= signedPreKeyStore
;
44 this.identityKeyStore
= identityKeyStore
;
47 public JsonAxolotlStore(IdentityKeyPair identityKeyPair
, int registrationId
) {
48 preKeyStore
= new JsonPreKeyStore();
49 sessionStore
= new JsonSessionStore();
50 signedPreKeyStore
= new JsonSignedPreKeyStore();
51 this.identityKeyStore
= new JsonIdentityKeyStore(identityKeyPair
, registrationId
);
55 public IdentityKeyPair
getIdentityKeyPair() {
56 return identityKeyStore
.getIdentityKeyPair();
60 public int getLocalRegistrationId() {
61 return identityKeyStore
.getLocalRegistrationId();
65 public void saveIdentity(String name
, IdentityKey identityKey
) {
66 identityKeyStore
.saveIdentity(name
, identityKey
);
70 public boolean isTrustedIdentity(String name
, IdentityKey identityKey
) {
71 return identityKeyStore
.isTrustedIdentity(name
, identityKey
);
75 public PreKeyRecord
loadPreKey(int preKeyId
) throws InvalidKeyIdException
{
76 return preKeyStore
.loadPreKey(preKeyId
);
80 public void storePreKey(int preKeyId
, PreKeyRecord
record) {
81 preKeyStore
.storePreKey(preKeyId
, record);
85 public boolean containsPreKey(int preKeyId
) {
86 return preKeyStore
.containsPreKey(preKeyId
);
90 public void removePreKey(int preKeyId
) {
91 preKeyStore
.removePreKey(preKeyId
);
95 public SessionRecord
loadSession(AxolotlAddress address
) {
96 return sessionStore
.loadSession(address
);
100 public List
<Integer
> getSubDeviceSessions(String name
) {
101 return sessionStore
.getSubDeviceSessions(name
);
105 public void storeSession(AxolotlAddress address
, SessionRecord
record) {
106 sessionStore
.storeSession(address
, record);
110 public boolean containsSession(AxolotlAddress address
) {
111 return sessionStore
.containsSession(address
);
115 public void deleteSession(AxolotlAddress address
) {
116 sessionStore
.deleteSession(address
);
120 public void deleteAllSessions(String name
) {
121 sessionStore
.deleteAllSessions(name
);
125 public SignedPreKeyRecord
loadSignedPreKey(int signedPreKeyId
) throws InvalidKeyIdException
{
126 return signedPreKeyStore
.loadSignedPreKey(signedPreKeyId
);
130 public List
<SignedPreKeyRecord
> loadSignedPreKeys() {
131 return signedPreKeyStore
.loadSignedPreKeys();
135 public void storeSignedPreKey(int signedPreKeyId
, SignedPreKeyRecord
record) {
136 signedPreKeyStore
.storeSignedPreKey(signedPreKeyId
, record);
140 public boolean containsSignedPreKey(int signedPreKeyId
) {
141 return signedPreKeyStore
.containsSignedPreKey(signedPreKeyId
);
145 public void removeSignedPreKey(int signedPreKeyId
) {
146 signedPreKeyStore
.removeSignedPreKey(signedPreKeyId
);