]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/util/Utils.java
Key tables on serviceId instead of recipientId
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / util / Utils.java
index 2226c92e62c7c4f3be64d55b0d300d654b43040a..97adb69d1013933561b8315e7acbdab2cf00d3cb 100644 (file)
@@ -1,12 +1,12 @@
 package org.asamk.signal.manager.util;
 
 import org.asamk.signal.manager.api.Pair;
+import org.asamk.signal.manager.storage.recipients.RecipientAddress;
 import org.signal.libsignal.protocol.IdentityKey;
 import org.signal.libsignal.protocol.fingerprint.Fingerprint;
 import org.signal.libsignal.protocol.fingerprint.NumericFingerprintGenerator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.whispersystems.signalservice.api.push.SignalServiceAddress;
 import org.whispersystems.signalservice.api.util.StreamDetails;
 
 import java.io.BufferedInputStream;
@@ -73,28 +73,27 @@ public class Utils {
 
     public static Fingerprint computeSafetyNumber(
             boolean isUuidCapable,
-            SignalServiceAddress ownAddress,
+            RecipientAddress ownAddress,
             IdentityKey ownIdentityKey,
-            SignalServiceAddress theirAddress,
+            RecipientAddress theirAddress,
             IdentityKey theirIdentityKey
     ) {
         int version;
         byte[] ownId;
         byte[] theirId;
 
-        if (isUuidCapable) {
+        if (!isUuidCapable && ownAddress.number().isPresent() && theirAddress.number().isPresent()) {
+            // Version 1: E164 user
+            version = 1;
+            ownId = ownAddress.number().get().getBytes();
+            theirId = theirAddress.number().get().getBytes();
+        } else if (isUuidCapable && theirAddress.uuid().isPresent()) {
             // Version 2: UUID user
             version = 2;
             ownId = ownAddress.getServiceId().toByteArray();
             theirId = theirAddress.getServiceId().toByteArray();
         } else {
-            // Version 1: E164 user
-            version = 1;
-            if (ownAddress.getNumber().isEmpty() || theirAddress.getNumber().isEmpty()) {
-                return null;
-            }
-            ownId = ownAddress.getNumber().get().getBytes();
-            theirId = theirAddress.getNumber().get().getBytes();
+            return null;
         }
 
         return new NumericFingerprintGenerator(5200).createFor(version,