mirror of
https://github.com/aljazceru/signal-cli.git
synced 2026-01-02 05:44:35 +01:00
151 lines
5.1 KiB
Java
151 lines
5.1 KiB
Java
package org.asamk.textsecure;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
import org.whispersystems.libsignal.IdentityKey;
|
|
import org.whispersystems.libsignal.IdentityKeyPair;
|
|
import org.whispersystems.libsignal.InvalidKeyIdException;
|
|
import org.whispersystems.libsignal.SignalProtocolAddress;
|
|
import org.whispersystems.libsignal.state.PreKeyRecord;
|
|
import org.whispersystems.libsignal.state.SessionRecord;
|
|
import org.whispersystems.libsignal.state.SignalProtocolStore;
|
|
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
|
|
|
import java.util.List;
|
|
|
|
class JsonAxolotlStore implements SignalProtocolStore {
|
|
|
|
@JsonProperty("preKeys")
|
|
@JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class)
|
|
@JsonSerialize(using = JsonPreKeyStore.JsonPreKeyStoreSerializer.class)
|
|
protected JsonPreKeyStore preKeyStore;
|
|
|
|
@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) {
|
|
preKeyStore = new JsonPreKeyStore();
|
|
sessionStore = new JsonSessionStore();
|
|
signedPreKeyStore = new JsonSignedPreKeyStore();
|
|
this.identityKeyStore = new JsonIdentityKeyStore(identityKeyPair, registrationId);
|
|
}
|
|
|
|
@Override
|
|
public IdentityKeyPair getIdentityKeyPair() {
|
|
return identityKeyStore.getIdentityKeyPair();
|
|
}
|
|
|
|
@Override
|
|
public int getLocalRegistrationId() {
|
|
return identityKeyStore.getLocalRegistrationId();
|
|
}
|
|
|
|
@Override
|
|
public void saveIdentity(String name, IdentityKey identityKey) {
|
|
identityKeyStore.saveIdentity(name, identityKey);
|
|
}
|
|
|
|
@Override
|
|
public boolean isTrustedIdentity(String name, IdentityKey identityKey) {
|
|
return identityKeyStore.isTrustedIdentity(name, identityKey);
|
|
}
|
|
|
|
@Override
|
|
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
|
|
return preKeyStore.loadPreKey(preKeyId);
|
|
}
|
|
|
|
@Override
|
|
public void storePreKey(int preKeyId, PreKeyRecord record) {
|
|
preKeyStore.storePreKey(preKeyId, record);
|
|
}
|
|
|
|
@Override
|
|
public boolean containsPreKey(int preKeyId) {
|
|
return preKeyStore.containsPreKey(preKeyId);
|
|
}
|
|
|
|
@Override
|
|
public void removePreKey(int preKeyId) {
|
|
preKeyStore.removePreKey(preKeyId);
|
|
}
|
|
|
|
@Override
|
|
public SessionRecord loadSession(SignalProtocolAddress address) {
|
|
return sessionStore.loadSession(address);
|
|
}
|
|
|
|
@Override
|
|
public List<Integer> getSubDeviceSessions(String name) {
|
|
return sessionStore.getSubDeviceSessions(name);
|
|
}
|
|
|
|
@Override
|
|
public void storeSession(SignalProtocolAddress address, SessionRecord record) {
|
|
sessionStore.storeSession(address, record);
|
|
}
|
|
|
|
@Override
|
|
public boolean containsSession(SignalProtocolAddress address) {
|
|
return sessionStore.containsSession(address);
|
|
}
|
|
|
|
@Override
|
|
public void deleteSession(SignalProtocolAddress address) {
|
|
sessionStore.deleteSession(address);
|
|
}
|
|
|
|
@Override
|
|
public void deleteAllSessions(String name) {
|
|
sessionStore.deleteAllSessions(name);
|
|
}
|
|
|
|
@Override
|
|
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException {
|
|
return signedPreKeyStore.loadSignedPreKey(signedPreKeyId);
|
|
}
|
|
|
|
@Override
|
|
public List<SignedPreKeyRecord> loadSignedPreKeys() {
|
|
return signedPreKeyStore.loadSignedPreKeys();
|
|
}
|
|
|
|
@Override
|
|
public void storeSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record) {
|
|
signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record);
|
|
}
|
|
|
|
@Override
|
|
public boolean containsSignedPreKey(int signedPreKeyId) {
|
|
return signedPreKeyStore.containsSignedPreKey(signedPreKeyId);
|
|
}
|
|
|
|
@Override
|
|
public void removeSignedPreKey(int signedPreKeyId) {
|
|
signedPreKeyStore.removeSignedPreKey(signedPreKeyId);
|
|
}
|
|
}
|