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;
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,