org.whispersystems.signalservice.internal.push.IdentityCheckRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-service-java Show documentation
Show all versions of signal-service-java Show documentation
Signal Service communication library for Java, unofficial fork
package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.signal.libsignal.protocol.IdentityKey;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.internal.util.JsonUtil;
import org.signal.core.util.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import javax.annotation.Nonnull;
public class IdentityCheckRequest {
@JsonProperty("elements")
private final List serviceIdFingerprintPairs;
public IdentityCheckRequest(@Nonnull List serviceIdKeyPairs) {
this.serviceIdFingerprintPairs = serviceIdKeyPairs;
}
public List getServiceIdFingerprintPairs() {
return serviceIdFingerprintPairs;
}
public static final class ServiceIdFingerprintPair {
@JsonProperty("uuid")
@JsonSerialize(using = JsonUtil.ServiceIdSerializer.class)
private final ServiceId serviceId;
@JsonProperty
private final String fingerprint;
public ServiceIdFingerprintPair(@Nonnull ServiceId serviceId, @Nonnull IdentityKey identityKey) {
this.serviceId = serviceId;
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
this.fingerprint = Base64.encodeWithPadding(messageDigest.digest(identityKey.serialize()), 0, 4);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
public ServiceId getServiceId() {
return serviceId;
}
public String getFingerprint() {
return fingerprint;
}
}
}