Basic client usage of CDSHv2.

This provides a basic (read: useful-for-development-yet-broken) client
usage of CDSHv2.
This commit is contained in:
Greyson Parrelli
2022-04-11 19:59:17 -04:00
parent b0e7b49056
commit d3096c56cb
13 changed files with 457 additions and 17 deletions

View File

@@ -8,8 +8,10 @@ import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredential;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.Util;
import java.io.IOException;
import java.util.Locale;
import java.util.Optional;
@@ -40,6 +42,27 @@ public final class ProfileKeyUtil {
return null;
}
public static @Nullable ProfileKey profileKeyOrNull(@Nullable String base64) {
if (base64 == null) {
return null;
}
byte[] decoded;
try {
decoded = Base64.decode(base64);
} catch (IOException e) {
Log.w(TAG, "Failed to decode profile key.");
return null;
}
try {
return new ProfileKey(decoded);
} catch (InvalidInputException e) {
Log.w(TAG, String.format(Locale.US, "Seen non-null profile key of wrong length %d", decoded.length), e);
return null;
}
}
public static @Nullable ProfileKeyCredential profileKeyCredentialOrNull(@Nullable byte[] profileKeyCredential) {
if (profileKeyCredential != null) {
try {