mirror of
https://github.com/oxen-io/session-android.git
synced 2025-11-10 07:18:00 +00:00
Generate SignedPreKey records, improve SignedPreKey cleanup.
This commit is contained in:
@@ -70,6 +70,7 @@ public class PushServiceSocket {
|
||||
private static final String PREKEY_METADATA_PATH = "/v2/keys/";
|
||||
private static final String PREKEY_PATH = "/v2/keys/%s";
|
||||
private static final String PREKEY_DEVICE_PATH = "/v2/keys/%s/%s";
|
||||
private static final String SIGNED_PREKEY_PATH = "/v2/keys/signed";
|
||||
|
||||
private static final String DIRECTORY_TOKENS_PATH = "/v1/directory/tokens";
|
||||
private static final String DIRECTORY_VERIFY_PATH = "/v1/directory/%s";
|
||||
@@ -251,6 +252,23 @@ public class PushServiceSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public SignedPreKeyEntity getCurrentSignedPreKey() throws IOException {
|
||||
try {
|
||||
String responseText = makeRequest(SIGNED_PREKEY_PATH, "GET", null);
|
||||
return SignedPreKeyEntity.fromJson(responseText);
|
||||
} catch (NotFoundException e) {
|
||||
Log.w("PushServiceSocket", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentSignedPreKey(SignedPreKeyRecord signedPreKey) throws IOException {
|
||||
SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(),
|
||||
signedPreKey.getKeyPair().getPublicKey(),
|
||||
signedPreKey.getSignature());
|
||||
makeRequest(SIGNED_PREKEY_PATH, "PUT", SignedPreKeyEntity.toJson(signedPreKeyEntity));
|
||||
}
|
||||
|
||||
public long sendAttachment(PushAttachmentData attachment) throws IOException {
|
||||
String response = makeRequest(String.format(ATTACHMENT_PATH, ""), "GET", null);
|
||||
AttachmentDescriptor attachmentKey = new Gson().fromJson(response, AttachmentDescriptor.class);
|
||||
|
||||
@@ -30,6 +30,16 @@ public class SignedPreKeyEntity extends PreKeyEntity {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public static String toJson(SignedPreKeyEntity entity) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
return forBuilder(builder).create().toJson(entity);
|
||||
}
|
||||
|
||||
public static SignedPreKeyEntity fromJson(String serialized) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
return forBuilder(builder).create().fromJson(serialized, SignedPreKeyEntity.class);
|
||||
}
|
||||
|
||||
public static GsonBuilder forBuilder(GsonBuilder builder) {
|
||||
return PreKeyEntity.forBuilder(builder)
|
||||
.registerTypeAdapter(byte[].class, new ByteArrayJsonAdapter());
|
||||
|
||||
Reference in New Issue
Block a user