mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Create a new manage profile screen.
This commit is contained in:
@@ -7,9 +7,11 @@ import org.conscrypt.Conscrypt;
|
||||
import org.signal.zkgroup.InvalidInputException;
|
||||
import org.signal.zkgroup.profiles.ProfileKey;
|
||||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
import org.whispersystems.util.Base64;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Security;
|
||||
|
||||
public class ProfileCipherTest extends TestCase {
|
||||
@@ -21,7 +23,7 @@ public class ProfileCipherTest extends TestCase {
|
||||
public void testEncryptDecrypt() throws InvalidCiphertextException, InvalidInputException {
|
||||
ProfileKey key = new ProfileKey(Util.getSecretBytes(32));
|
||||
ProfileCipher cipher = new ProfileCipher(key);
|
||||
byte[] name = cipher.encryptName("Clement\0Duval".getBytes(), ProfileCipher.NAME_PADDED_LENGTH);
|
||||
byte[] name = cipher.encryptName("Clement\0Duval".getBytes(), 53);
|
||||
byte[] plaintext = cipher.decryptName(name);
|
||||
assertEquals(new String(plaintext), "Clement\0Duval");
|
||||
}
|
||||
@@ -59,4 +61,29 @@ public class ProfileCipherTest extends TestCase {
|
||||
assertEquals(new String(result.toByteArray()), "This is an avatar");
|
||||
}
|
||||
|
||||
public void testEncryptLengthBucket1() throws InvalidInputException {
|
||||
ProfileKey key = new ProfileKey(Util.getSecretBytes(32));
|
||||
ProfileCipher cipher = new ProfileCipher(key);
|
||||
byte[] name = cipher.encryptName("Peter\0Parker".getBytes(), 53);
|
||||
|
||||
String encoded = Base64.encodeBytes(name);
|
||||
|
||||
assertEquals(108, encoded.length());
|
||||
}
|
||||
|
||||
public void testEncryptLengthBucket2() throws InvalidInputException {
|
||||
ProfileKey key = new ProfileKey(Util.getSecretBytes(32));
|
||||
ProfileCipher cipher = new ProfileCipher(key);
|
||||
byte[] name = cipher.encryptName("Peter\0Parker".getBytes(), 257);
|
||||
|
||||
String encoded = Base64.encodeBytes(name);
|
||||
|
||||
assertEquals(380, encoded.length());
|
||||
}
|
||||
|
||||
public void testTargetNameLength() {
|
||||
assertEquals(53, ProfileCipher.getTargetNameLength("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
||||
assertEquals(53, ProfileCipher.getTargetNameLength("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1"));
|
||||
assertEquals(257, ProfileCipher.getTargetNameLength("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user