mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 05:46:47 +00:00
serialize account current profile version as base64
This commit is contained in:
1 parent
90b280d6a0
commit
22656396dc
2 files changed
+28
-9
No files matched your search
@@ -93,7 +93,6 @@ public class Account {
|
||||
private IdentityKey phoneNumberIdentityKey;
|
||||
|
||||
@JsonProperty("cpv")
|
||||
@JsonSerialize(using = ProfileVersionAdapter.Serializing.class)
|
||||
@JsonDeserialize(using = ProfileVersionAdapter.Deserializing.class)
|
||||
private byte[] currentProfileVersion;
|
||||
|
||||
@@ -595,13 +594,5 @@ public class Account {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// after deploying this once we can get rid of it in favor of the default base64
|
||||
private static class Serializing extends JsonSerializer<byte[]> {
|
||||
@Override
|
||||
public void serialize(byte[] bytes, JsonGenerator jsonGenerator, SerializerProvider serializaterProvider) throws IOException {
|
||||
jsonGenerator.writeString(HexFormat.of().formatHex(bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@ import java.lang.annotation.Annotation;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@@ -29,7 +31,9 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AccountsHelper;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
import org.whispersystems.textsecuregcm.util.TestClock;
|
||||
import org.whispersystems.textsecuregcm.util.TestRandomUtil;
|
||||
|
||||
class AccountTest {
|
||||
|
||||
@@ -229,4 +233,28 @@ class AccountTest {
|
||||
final JsonFilter jsonFilterAnnotation = (JsonFilter) maybeJsonFilterAnnotation.get();
|
||||
assertEquals(Account.class.getSimpleName(), jsonFilterAnnotation.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProfileVersionRoundTrip() throws Exception {
|
||||
final Account account = AccountsHelper.generateTestAccount("+12345678901", UUID.randomUUID(), UUID.randomUUID(), List.of(createDevice(Device.PRIMARY_ID)), new byte[0]);
|
||||
final byte[] version = TestRandomUtil.nextBytes(32);
|
||||
account.setCurrentProfileVersion(version);
|
||||
|
||||
final String json = SystemMapper.jsonMapper().writeValueAsString(account);
|
||||
final Account deserialized = SystemMapper.jsonMapper().readValue(json, Account.class);
|
||||
assertThat(deserialized.getCurrentProfileVersion()).isPresent().hasValue(version);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProfileVersionDeserialization() throws Exception {
|
||||
final byte[] version = TestRandomUtil.nextBytes(32);
|
||||
final String jsonTemplate = """
|
||||
{"cpv": "%s"}
|
||||
""";
|
||||
|
||||
final Account deserializedHexCpv = SystemMapper.jsonMapper().readValue(String.format(jsonTemplate, HexFormat.of().formatHex(version)), Account.class);
|
||||
assertThat(deserializedHexCpv.getCurrentProfileVersion()).isPresent().hasValue(version);
|
||||
final Account deserializedBase64Cpv = SystemMapper.jsonMapper().readValue(String.format(jsonTemplate, Base64.getEncoder().encodeToString(version)), Account.class);
|
||||
assertThat(deserializedBase64Cpv.getCurrentProfileVersion()).isPresent().hasValue(version);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user