Update libsignal-client to 0.14.0

This commit is contained in:
Greyson Parrelli
2022-03-14 15:49:46 -04:00
committed by Cody Henthorne
parent 749bbf428d
commit 057231b9c3
650 changed files with 2154 additions and 2384 deletions
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- It's a bummer, but Android Studio doesn't seem to be smart enough to recognize Optional and stream() are available to us in this lib -->
<issue id="NewApi" severity="ignore" />
</lint>
@@ -1,6 +1,7 @@
package org.whispersystems.signalservice.api;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
/**
* An exception thrown when something about the proto is malformed. e.g. one of the fields has an invalid value.
@@ -12,26 +13,26 @@ public final class InvalidMessageStructureException extends Exception {
public InvalidMessageStructureException(String message) {
super(message);
this.sender = Optional.absent();
this.device = Optional.absent();
this.sender = Optional.empty();
this.device = Optional.empty();
}
public InvalidMessageStructureException(String message, String sender, int device) {
super(message);
this.sender = Optional.fromNullable(sender);
this.sender = Optional.ofNullable(sender);
this.device = Optional.of(device);
}
public InvalidMessageStructureException(Exception e, String sender, int device) {
super(e);
this.sender = Optional.fromNullable(sender);
this.sender = Optional.ofNullable(sender);
this.device = Optional.of(device);
}
public InvalidMessageStructureException(Exception e) {
super(e);
this.sender = Optional.absent();
this.device = Optional.absent();
this.sender = Optional.empty();
this.device = Optional.empty();
}
public Optional<String> getSender() {
@@ -18,7 +18,6 @@ import org.whispersystems.signalservice.internal.keybackup.protos.BackupResponse
import org.whispersystems.signalservice.internal.keybackup.protos.RestoreResponse;
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import org.whispersystems.signalservice.internal.push.RemoteAttestationUtil;
import org.whispersystems.signalservice.internal.util.Hex;
import org.whispersystems.signalservice.internal.util.Util;
import java.io.IOException;
@@ -2,8 +2,6 @@ package org.whispersystems.signalservice.api;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import java.io.Closeable;
/**
* And extension of the normal protocol store interface that has additional methods that are needed
* in the service layer, but not the protocol layer.
@@ -18,8 +18,6 @@ import org.whispersystems.libsignal.ecc.ECPublicKey;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.account.AccountAttributes;
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
import org.whispersystems.signalservice.api.crypto.ProfileCipher;
@@ -36,8 +34,8 @@ import org.whispersystems.signalservice.api.profiles.AvatarUploadParams;
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.PNI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceIdType;
import org.whispersystems.signalservice.api.push.SignedPreKeyEntity;
import org.whispersystems.signalservice.api.push.exceptions.NoContentException;
@@ -54,6 +52,7 @@ import org.whispersystems.signalservice.api.storage.StorageId;
import org.whispersystems.signalservice.api.storage.StorageKey;
import org.whispersystems.signalservice.api.storage.StorageManifestKey;
import org.whispersystems.signalservice.api.util.CredentialsProvider;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.signalservice.internal.ServiceResponse;
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
import org.whispersystems.signalservice.internal.contacts.crypto.ContactDiscoveryCipher;
@@ -100,6 +99,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
@@ -566,7 +566,7 @@ public class SignalServiceAccountManager {
return Optional.of(SignalStorageModels.remoteToLocalStorageManifest(storageManifest, storageKey));
} catch (InvalidKeyException | NotFoundException e) {
Log.w(TAG, "Error while fetching manifest.", e);
return Optional.absent();
return Optional.empty();
}
}
@@ -588,12 +588,12 @@ public class SignalServiceAccountManager {
if (storageManifest.getValue().isEmpty()) {
Log.w(TAG, "Got an empty storage manifest!");
return Optional.absent();
return Optional.empty();
}
return Optional.of(SignalStorageModels.remoteToLocalStorageManifest(storageManifest, storageKey));
} catch (NoContentException e) {
return Optional.absent();
return Optional.empty();
}
}
@@ -725,7 +725,7 @@ public class SignalServiceAccountManager {
return Optional.of(conflictManifest);
} else {
return Optional.absent();
return Optional.empty();
}
}
@@ -821,7 +821,7 @@ public class SignalServiceAccountManager {
byte[] ciphertextName = profileCipher.encryptString(name, ProfileCipher.getTargetNameLength(name));
byte[] ciphertextAbout = profileCipher.encryptString(about, ProfileCipher.getTargetAboutLength(about));
byte[] ciphertextEmoji = profileCipher.encryptString(aboutEmoji, ProfileCipher.EMOJI_PADDED_LENGTH);
byte[] ciphertextMobileCoinAddress = paymentsAddress.transform(address -> profileCipher.encryptWithLength(address.toByteArray(), ProfileCipher.PAYMENTS_ADDRESS_CONTENT_SIZE)).orNull();
byte[] ciphertextMobileCoinAddress = paymentsAddress.map(address -> profileCipher.encryptWithLength(address.toByteArray(), ProfileCipher.PAYMENTS_ADDRESS_CONTENT_SIZE)).orElse(null);
ProfileAvatarData profileAvatarData = null;
if (avatar.stream != null && !avatar.keepTheSame) {
@@ -847,7 +847,7 @@ public class SignalServiceAccountManager {
throws NonSuccessfulResponseCodeException, PushNetworkException
{
try {
ProfileAndCredential credential = this.pushServiceSocket.retrieveVersionedProfileAndCredential(serviceId.uuid(), profileKey, Optional.absent(), locale).get(10, TimeUnit.SECONDS);
ProfileAndCredential credential = this.pushServiceSocket.retrieveVersionedProfileAndCredential(serviceId.uuid(), profileKey, Optional.empty(), locale).get(10, TimeUnit.SECONDS);
return credential.getProfileKeyCredential();
} catch (InterruptedException | TimeoutException e) {
throw new PushNetworkException(e);
@@ -9,7 +9,6 @@ package org.whispersystems.signalservice.api;
import org.signal.zkgroup.profiles.ClientZkProfileOperations;
import org.signal.zkgroup.profiles.ProfileKey;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream;
import org.whispersystems.signalservice.api.crypto.ProfileCipherInputStream;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
@@ -42,6 +41,7 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
/**
* The primary interface for receiving Signal Service messages.
@@ -98,14 +98,14 @@ public class SignalServiceMessageReceiver {
return FutureTransformers.map(socket.retrieveVersionedProfile(serviceId.uuid(), profileKey.get(), unidentifiedAccess, locale), profile -> {
return new ProfileAndCredential(profile,
SignalServiceProfile.RequestType.PROFILE,
Optional.absent());
Optional.empty());
});
}
} else {
return FutureTransformers.map(socket.retrieveProfile(address, unidentifiedAccess, locale), profile -> {
return new ProfileAndCredential(profile,
SignalServiceProfile.RequestType.PROFILE,
Optional.absent());
Optional.empty());
});
}
}
@@ -148,7 +148,7 @@ public class SignalServiceMessageReceiver {
if (!pointer.getDigest().isPresent()) throw new InvalidMessageException("No attachment digest!");
socket.retrieveAttachment(pointer.getCdnNumber(), pointer.getRemoteId(), destination, maxSizeBytes, listener);
return AttachmentCipherInputStream.createForAttachment(destination, pointer.getSize().or(0), pointer.getKey(), pointer.getDigest().get());
return AttachmentCipherInputStream.createForAttachment(destination, pointer.getSize().orElse(0), pointer.getKey(), pointer.getDigest().get());
}
public InputStream retrieveSticker(byte[] packId, byte[] packKey, int stickerId)
@@ -21,8 +21,6 @@ import org.whispersystems.libsignal.protocol.PlaintextContent;
import org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage;
import org.whispersystems.libsignal.state.PreKeyBundle;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.crypto.AttachmentCipherOutputStream;
import org.whispersystems.signalservice.api.crypto.ContentHint;
import org.whispersystems.signalservice.api.crypto.EnvelopeContent;
@@ -65,7 +63,6 @@ import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage
import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.DistributionId;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@@ -82,6 +79,7 @@ import org.whispersystems.signalservice.api.services.AttachmentService;
import org.whispersystems.signalservice.api.services.MessagingService;
import org.whispersystems.signalservice.api.util.AttachmentPointerUtil;
import org.whispersystems.signalservice.api.util.CredentialsProvider;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.signalservice.api.util.Uint64RangeException;
import org.whispersystems.signalservice.api.util.Uint64Util;
import org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException;
@@ -137,6 +135,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -159,8 +158,8 @@ public class SignalServiceMessageSender {
private final SignalServiceAccountDataStore store;
private final SignalSessionLock sessionLock;
private final SignalServiceAddress localAddress;
private final int localDeviceId;
private final Optional<EventListener> eventListener;
private final int localDeviceId;
private final Optional<EventListener> eventListener;
private final AttachmentService attachmentService;
private final MessagingService messagingService;
@@ -204,7 +203,7 @@ public class SignalServiceMessageSender {
throws IOException, UntrustedIdentityException
{
Content content = createReceiptContent(message);
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.empty());
return sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getWhen(), envelopeContent, false, null);
}
@@ -235,7 +234,7 @@ public class SignalServiceMessageSender {
throws IOException
{
Content content = createTypingContent(message);
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.empty());
sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), envelopeContent, true, null, cancelationSignal);
}
@@ -260,7 +259,7 @@ public class SignalServiceMessageSender {
throws IOException, UntrustedIdentityException
{
Content content = createStoryContent(message);
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.RESENDABLE, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.RESENDABLE, Optional.empty());
return sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, envelopeContent, false, null, null);
}
@@ -295,7 +294,7 @@ public class SignalServiceMessageSender {
throws IOException, UntrustedIdentityException
{
Content content = createCallContent(message);
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.DEFAULT, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.DEFAULT, Optional.empty());
sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), System.currentTimeMillis(), envelopeContent, false, null);
}
@@ -306,7 +305,7 @@ public class SignalServiceMessageSender {
throws IOException
{
Content content = createCallContent(message);
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.DEFAULT, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.DEFAULT, Optional.empty());
return sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), System.currentTimeMillis(), envelopeContent, false, null, null);
}
@@ -364,9 +363,9 @@ public class SignalServiceMessageSender {
if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) {
Content syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.of(recipient), timestamp, Collections.singletonList(result), false);
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.empty());
sendMessage(localAddress, Optional.absent(), timestamp, syncMessageContent, false, null);
sendMessage(localAddress, Optional.empty(), timestamp, syncMessageContent, false, null);
}
sendEvents.onSyncMessageSent();
@@ -421,7 +420,7 @@ public class SignalServiceMessageSender {
throws UntrustedIdentityException, IOException
{
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, contentHint, groupId);
Optional<UnidentifiedAccess> access = unidentifiedAccess.isPresent() ? unidentifiedAccess.get().getTargetUnidentifiedAccess() : Optional.absent();
Optional<UnidentifiedAccess> access = unidentifiedAccess.isPresent() ? unidentifiedAccess.get().getTargetUnidentifiedAccess() : Optional.empty();
return sendMessage(address, access, timestamp, envelopeContent, false, null);
}
@@ -447,10 +446,10 @@ public class SignalServiceMessageSender {
sendEvents.onMessageSent();
if (store.isMultiDevice()) {
Content syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.absent(), message.getTimestamp(), results, isRecipientUpdate);
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.absent());
Content syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.empty(), message.getTimestamp(), results, isRecipientUpdate);
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.empty());
sendMessage(localAddress, Optional.absent(), message.getTimestamp(), syncMessageContent, false, null);
sendMessage(localAddress, Optional.empty(), message.getTimestamp(), syncMessageContent, false, null);
}
sendEvents.onSyncMessageSent();
@@ -492,15 +491,15 @@ public class SignalServiceMessageSender {
}
if (needsSyncInResults || store.isMultiDevice()) {
Optional<SignalServiceAddress> recipient = Optional.absent();
Optional<SignalServiceAddress> recipient = Optional.empty();
if (!message.getGroupContext().isPresent() && recipients.size() == 1) {
recipient = Optional.of(recipients.get(0));
}
Content syncMessage = createMultiDeviceSentTranscriptContent(content, recipient, timestamp, results, isRecipientUpdate);
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.empty());
sendMessage(localAddress, Optional.absent(), timestamp, syncMessageContent, false, null);
sendMessage(localAddress, Optional.empty(), timestamp, syncMessageContent, false, null);
}
sendEvents.onSyncMessageSent();
@@ -511,7 +510,7 @@ public class SignalServiceMessageSender {
public SendMessageResult sendSyncMessage(SignalServiceDataMessage dataMessage)
throws IOException, UntrustedIdentityException
{
return sendSyncMessage(createSelfSendSyncMessage(dataMessage), Optional.absent());
return sendSyncMessage(createSelfSendSyncMessage(dataMessage), Optional.empty());
}
public SendMessageResult sendSyncMessage(SignalServiceSyncMessage message, Optional<UnidentifiedAccessPair> unidentifiedAccess)
@@ -557,9 +556,9 @@ public class SignalServiceMessageSender {
long timestamp = message.getSent().isPresent() ? message.getSent().get().getTimestamp()
: System.currentTimeMillis();
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.empty());
return sendMessage(localAddress, Optional.absent(), timestamp, envelopeContent, false, null);
return sendMessage(localAddress, Optional.empty(), timestamp, envelopeContent, false, null);
}
public void setSoTimeoutMillis(long soTimeoutMillis) {
@@ -571,8 +570,8 @@ public class SignalServiceMessageSender {
}
public SignalServiceAttachmentPointer uploadAttachment(SignalServiceAttachmentStream attachment) throws IOException {
byte[] attachmentKey = attachment.getResumableUploadSpec().transform(ResumableUploadSpec::getSecretKey).or(() -> Util.getSecretBytes(64));
byte[] attachmentIV = attachment.getResumableUploadSpec().transform(ResumableUploadSpec::getIV).or(() -> Util.getSecretBytes(16));
byte[] attachmentKey = attachment.getResumableUploadSpec().map(ResumableUploadSpec::getSecretKey).orElseGet(() -> Util.getSecretBytes(64));
byte[] attachmentIV = attachment.getResumableUploadSpec().map(ResumableUploadSpec::getIV).orElseGet(() -> Util.getSecretBytes(16));
long paddedLength = PaddingInputStream.getPaddedSize(attachment.getLength());
InputStream dataStream = new PaddingInputStream(attachment.getInputStream(), attachment.getLength());
long ciphertextLength = AttachmentCipherOutputStream.getCiphertextLength(paddedLength);
@@ -582,7 +581,7 @@ public class SignalServiceMessageSender {
new AttachmentCipherOutputStreamFactory(attachmentKey, attachmentIV),
attachment.getListener(),
attachment.getCancelationSignal(),
attachment.getResumableUploadSpec().orNull());
attachment.getResumableUploadSpec().orElse(null));
if (attachment.getResumableUploadSpec().isPresent()) {
return uploadAttachmentV3(attachment, attachmentKey, attachmentData);
@@ -694,15 +693,15 @@ public class SignalServiceMessageSender {
.setNullMessage(nullMessage)
.build();
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.empty());
SendMessageResult result = sendMessage(message.getDestination(), Optional.absent(), message.getTimestamp(), envelopeContent, false, null);
SendMessageResult result = sendMessage(message.getDestination(), Optional.empty(), message.getTimestamp(), envelopeContent, false, null);
if (result.getSuccess().isNeedsSync()) {
Content syncMessage = createMultiDeviceVerifiedContent(message, nullMessage.toByteArray());
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.empty());
sendMessage(localAddress, Optional.absent(), message.getTimestamp(), syncMessageContent, false, null);
sendMessage(localAddress, Optional.empty(), message.getTimestamp(), syncMessageContent, false, null);
}
return result;
@@ -724,7 +723,7 @@ public class SignalServiceMessageSender {
.setNullMessage(nullMessage)
.build();
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.absent());
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, ContentHint.IMPLICIT, Optional.empty());
return sendMessage(address, getTargetUnidentifiedAccess(unidentifiedAccess), System.currentTimeMillis(), envelopeContent, false, null);
}
@@ -770,7 +769,7 @@ public class SignalServiceMessageSender {
builder.setTextAttachment(createTextAttachment(message.getTextAttachment().get()));
}
builder.setAllowsReplies(message.getAllowsReplies().or(true));
builder.setAllowsReplies(message.getAllowsReplies().orElse(true));
return container.setStoryMessage(builder).build();
}
@@ -1689,7 +1688,7 @@ public class SignalServiceMessageSender {
if (!unidentifiedAccess.isPresent()) {
try {
SendMessageResponse response = new MessagingService.SendResponseProcessor<>(messagingService.send(messages, Optional.absent()).blockingGet()).getResultOrThrow();
SendMessageResponse response = new MessagingService.SendResponseProcessor<>(messagingService.send(messages, Optional.empty()).blockingGet()).getResultOrThrow();
return SendMessageResult.success(recipient, messages.getDevices(), response.sentUnidentified(), response.getNeedsSync() || store.isMultiDevice(), System.currentTimeMillis() - startTime, content.getContent());
} catch (InvalidUnidentifiedAccessHeaderException | UnregisteredUserException | MismatchedDevicesException | StaleDevicesException e) {
// Non-technical failures shouldn't be retried with socket
@@ -1725,11 +1724,11 @@ public class SignalServiceMessageSender {
} catch (InvalidKeyException ike) {
Log.w(TAG, ike);
unidentifiedAccess = Optional.absent();
unidentifiedAccess = Optional.empty();
} catch (AuthorizationFailedException afe) {
Log.w(TAG, afe);
if (unidentifiedAccess.isPresent()) {
unidentifiedAccess = Optional.absent();
unidentifiedAccess = Optional.empty();
} else {
throw afe;
}
@@ -1874,13 +1873,13 @@ public class SignalServiceMessageSender {
} catch (GroupMismatchedDevicesException e) {
Log.w(TAG, "[sendGroupMessage][" + timestamp + "] Handling mismatched devices. (" + e.getMessage() + ")");
for (GroupMismatchedDevices mismatched : e.getMismatchedDevices()) {
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(mismatched.getUuid()), Optional.absent());
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(mismatched.getUuid()), Optional.empty());
handleMismatchedDevices(socket, address, mismatched.getDevices());
}
} catch (GroupStaleDevicesException e) {
Log.w(TAG, "[sendGroupMessage][" + timestamp + "] Handling stale devices. (" + e.getMessage() + ")");
for (GroupStaleDevices stale : e.getStaleDevices()) {
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(stale.getUuid()), Optional.absent());
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(stale.getUuid()), Optional.empty());
handleStaleDevices(address, stale.getDevices());
}
}
@@ -2151,7 +2150,7 @@ public class SignalServiceMessageSender {
return unidentifiedAccess.get().getTargetUnidentifiedAccess();
}
return Optional.absent();
return Optional.empty();
}
private List<Optional<UnidentifiedAccess>> getTargetUnidentifiedAccess(List<Optional<UnidentifiedAccessPair>> unidentifiedAccess) {
@@ -2159,7 +2158,7 @@ public class SignalServiceMessageSender {
for (Optional<UnidentifiedAccessPair> item : unidentifiedAccess) {
if (item.isPresent()) results.add(item.get().getTargetUnidentifiedAccess());
else results.add(Optional.<UnidentifiedAccess>absent());
else results.add(Optional.empty());
}
return results;
@@ -1,7 +1,6 @@
package org.whispersystems.signalservice.api;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState;
@@ -14,6 +13,7 @@ import org.whispersystems.signalservice.internal.websocket.WebsocketResponse;
import org.whispersystems.util.Base64;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.TimeoutException;
import io.reactivex.rxjava3.core.Observable;
@@ -261,7 +261,7 @@ public final class SignalWebSocket {
callback.onMessage(envelope);
return Optional.of(envelope);
} else if (isSocketEmptyRequest(request)) {
return Optional.absent();
return Optional.empty();
}
} finally {
getWebSocket().sendResponse(response);
@@ -295,7 +295,7 @@ public final class SignalWebSocket {
private static Optional<String> findHeader(WebSocketRequestMessage message) {
if (message.getHeadersCount() == 0) {
return Optional.absent();
return Optional.empty();
}
for (String header : message.getHeadersList()) {
@@ -307,7 +307,7 @@ public final class SignalWebSocket {
}
}
return Optional.absent();
return Optional.empty();
}
/**
@@ -8,13 +8,14 @@ import org.whispersystems.libsignal.UntrustedIdentityException;
import org.whispersystems.libsignal.protocol.CiphertextMessage;
import org.whispersystems.libsignal.protocol.DecryptionErrorMessage;
import org.whispersystems.libsignal.protocol.PlaintextContent;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.push.OutgoingPushMessage;
import org.whispersystems.signalservice.internal.push.PushTransportDetails;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Envelope.Type;
import org.whispersystems.util.Base64;
import java.util.Optional;
/**
* An abstraction over the different types of message contents we can have.
*/
@@ -165,7 +166,7 @@ public interface EnvelopeContent {
@Override
public Optional<Content> getContent() {
return Optional.absent();
return Optional.empty();
}
}
}
@@ -4,10 +4,10 @@ import org.whispersystems.util.StringUtil;
import java.util.Arrays;
import static java.util.Arrays.copyOfRange;
import static org.whispersystems.signalservice.api.crypto.CryptoUtil.hmacSha256;
import static org.whispersystems.util.ByteArrayUtil.concat;
import static org.whispersystems.util.ByteArrayUtil.xor;
import static java.util.Arrays.copyOfRange;
/**
* Encrypts or decrypts with a Synthetic IV.
@@ -13,7 +13,6 @@ import org.signal.libsignal.metadata.ProtocolUntrustedIdentityException;
import org.signal.libsignal.metadata.SealedSessionCipher;
import org.signal.libsignal.metadata.SelfSendException;
import org.signal.libsignal.metadata.certificate.CertificateValidator;
import org.signal.libsignal.metadata.certificate.SenderCertificate;
import org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.InvalidRegistrationIdException;
@@ -41,7 +41,6 @@ import org.whispersystems.libsignal.protocol.CiphertextMessage;
import org.whispersystems.libsignal.protocol.PlaintextContent;
import org.whispersystems.libsignal.protocol.PreKeySignalMessage;
import org.whispersystems.libsignal.protocol.SignalMessage;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.InvalidMessageStructureException;
import org.whispersystems.signalservice.api.SignalServiceAccountDataStore;
import org.whispersystems.signalservice.api.SignalSessionLock;
@@ -61,6 +60,7 @@ import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceC
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* This is used to encrypt + decrypt received {@link SignalServiceEnvelope}s.
@@ -100,7 +100,7 @@ public class SignalServiceCipher {
PushTransportDetails transport = new PushTransportDetails();
SignalProtocolAddress localProtocolAddress = new SignalProtocolAddress(localAddress.getIdentifier(), localDeviceId);
SignalGroupCipher groupCipher = new SignalGroupCipher(sessionLock, new GroupCipher(signalProtocolStore, localProtocolAddress));
SignalSealedSessionCipher sessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orNull(), localDeviceId));
SignalSealedSessionCipher sessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orElse(null), localDeviceId));
CiphertextMessage message = groupCipher.encrypt(distributionId.asUuid(), transport.getPaddedMessageBody(unpaddedMessage));
UnidentifiedSenderMessageContent messageContent = new UnidentifiedSenderMessageContent(message,
senderCertificate,
@@ -117,7 +117,7 @@ public class SignalServiceCipher {
{
if (unidentifiedAccess.isPresent()) {
SignalSessionCipher sessionCipher = new SignalSessionCipher(sessionLock, new SessionCipher(signalProtocolStore, destination));
SignalSealedSessionCipher sealedSessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orNull(), localDeviceId));
SignalSealedSessionCipher sealedSessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orElse(null), localDeviceId));
return content.processSealedSender(sessionCipher, sealedSessionCipher, destination, unidentifiedAccess.get().getUnidentifiedCertificate());
} else {
@@ -195,7 +195,7 @@ public class SignalServiceCipher {
SignalSessionCipher sessionCipher = new SignalSessionCipher(sessionLock, new SessionCipher(signalProtocolStore, sourceAddress));
paddedMessage = sessionCipher.decrypt(new PreKeySignalMessage(ciphertext));
metadata = new SignalServiceMetadata(envelope.getSourceAddress(), envelope.getSourceDevice(), envelope.getTimestamp(), envelope.getServerReceivedTimestamp(), envelope.getServerDeliveredTimestamp(), false, envelope.getServerGuid(), Optional.absent());
metadata = new SignalServiceMetadata(envelope.getSourceAddress(), envelope.getSourceDevice(), envelope.getTimestamp(), envelope.getServerReceivedTimestamp(), envelope.getServerDeliveredTimestamp(), false, envelope.getServerGuid(), Optional.empty());
signalProtocolStore.clearSenderKeySharedWith(Collections.singleton(sourceAddress));
} else if (envelope.isSignalMessage()) {
@@ -203,12 +203,12 @@ public class SignalServiceCipher {
SignalSessionCipher sessionCipher = new SignalSessionCipher(sessionLock, new SessionCipher(signalProtocolStore, sourceAddress));
paddedMessage = sessionCipher.decrypt(new SignalMessage(ciphertext));
metadata = new SignalServiceMetadata(envelope.getSourceAddress(), envelope.getSourceDevice(), envelope.getTimestamp(), envelope.getServerReceivedTimestamp(), envelope.getServerDeliveredTimestamp(), false, envelope.getServerGuid(), Optional.absent());
metadata = new SignalServiceMetadata(envelope.getSourceAddress(), envelope.getSourceDevice(), envelope.getTimestamp(), envelope.getServerReceivedTimestamp(), envelope.getServerDeliveredTimestamp(), false, envelope.getServerGuid(), Optional.empty());
} else if (envelope.isPlaintextContent()) {
paddedMessage = new PlaintextContent(ciphertext).getBody();
metadata = new SignalServiceMetadata(envelope.getSourceAddress(), envelope.getSourceDevice(), envelope.getTimestamp(), envelope.getServerReceivedTimestamp(), envelope.getServerDeliveredTimestamp(), false, envelope.getServerGuid(), Optional.absent());
metadata = new SignalServiceMetadata(envelope.getSourceAddress(), envelope.getSourceDevice(), envelope.getTimestamp(), envelope.getServerReceivedTimestamp(), envelope.getServerDeliveredTimestamp(), false, envelope.getServerGuid(), Optional.empty());
} else if (envelope.isUnidentifiedSender()) {
SignalSealedSessionCipher sealedSessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orNull(), localDeviceId));
SignalSealedSessionCipher sealedSessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orElse(null), localDeviceId));
DecryptionResult result = sealedSessionCipher.decrypt(certificateValidator, ciphertext, envelope.getServerReceivedTimestamp());
SignalServiceAddress resultAddress = new SignalServiceAddress(ACI.parseOrThrow(result.getSenderUuid()), result.getSenderE164());
Optional<byte[]> groupId = result.getGroupId();
@@ -3,7 +3,6 @@ package org.whispersystems.signalservice.api.crypto;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
/**
* SkippingOutputStream will skip a number of bytes being written as specified by toSkip and then
@@ -1,7 +1,7 @@
package org.whispersystems.signalservice.api.crypto;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class UnidentifiedAccessPair {
@@ -2,7 +2,9 @@ package org.whispersystems.signalservice.api.groupsv2;
import org.signal.storageservice.protos.groups.local.DecryptedGroup;
import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
/**
* Pair of a {@link DecryptedGroup} and the {@link DecryptedGroupChange} for that version.
@@ -15,7 +15,6 @@ import org.signal.storageservice.protos.groups.local.DecryptedPendingMemberRemov
import org.signal.storageservice.protos.groups.local.DecryptedRequestingMember;
import org.signal.storageservice.protos.groups.local.EnabledState;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.util.ArrayList;
@@ -24,6 +23,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -148,7 +148,7 @@ public final class DecryptedGroupUtil {
* The UUID of the member that made the change.
*/
public static Optional<UUID> editorUuid(DecryptedGroupChange change) {
return Optional.fromNullable(change != null ? UuidUtil.fromByteStringOrNull(change.getEditor()) : null);
return Optional.ofNullable(change != null ? UuidUtil.fromByteStringOrNull(change.getEditor()) : null);
}
public static Optional<DecryptedMember> findMemberByUuid(Collection<DecryptedMember> members, UUID uuid) {
@@ -160,7 +160,7 @@ public final class DecryptedGroupUtil {
}
}
return Optional.absent();
return Optional.empty();
}
public static Optional<DecryptedPendingMember> findPendingByUuid(Collection<DecryptedPendingMember> members, UUID uuid) {
@@ -172,7 +172,7 @@ public final class DecryptedGroupUtil {
}
}
return Optional.absent();
return Optional.empty();
}
private static int findPendingIndexByUuidCipherText(List<DecryptedPendingMember> members, ByteString cipherText) {
@@ -206,7 +206,7 @@ public final class DecryptedGroupUtil {
}
}
return Optional.absent();
return Optional.empty();
}
public static boolean isPendingOrRequesting(DecryptedGroup group, UUID uuid) {
@@ -617,9 +617,9 @@ public final class DecryptedGroupUtil {
}
public static Optional<UUID> findInviter(List<DecryptedPendingMember> pendingMembersList, UUID uuid) {
return Optional.fromNullable(findPendingByUuid(pendingMembersList, uuid).transform(DecryptedPendingMember::getAddedByUuid)
.transform(UuidUtil::fromByteStringOrNull)
.orNull());
return Optional.ofNullable(findPendingByUuid(pendingMembersList, uuid).map(DecryptedPendingMember::getAddedByUuid)
.map(UuidUtil::fromByteStringOrNull)
.orElse(null));
}
public static boolean changeIsEmpty(DecryptedGroupChange change) {
@@ -1,12 +1,12 @@
package org.whispersystems.signalservice.api.groupsv2;
import org.signal.zkgroup.profiles.ProfileKeyCredential;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -52,7 +52,7 @@ public final class GroupCandidate {
}
public GroupCandidate withoutProfileKeyCredential() {
return hasProfileKeyCredential() ? new GroupCandidate(uuid, Optional.absent())
return hasProfileKeyCredential() ? new GroupCandidate(uuid, Optional.empty())
: this;
}
@@ -12,7 +12,6 @@ import org.signal.storageservice.protos.groups.local.DecryptedModifyMemberRole;
import org.signal.storageservice.protos.groups.local.DecryptedPendingMember;
import org.signal.storageservice.protos.groups.local.DecryptedPendingMemberRemoval;
import org.signal.storageservice.protos.groups.local.DecryptedRequestingMember;
import org.signal.storageservice.protos.groups.local.EnabledState;
import java.util.HashMap;
import java.util.List;
@@ -1,6 +1,7 @@
package org.whispersystems.signalservice.api.groupsv2;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
/**
* Thrown when a group link:
@@ -20,7 +20,6 @@ import org.signal.zkgroup.auth.AuthCredentialResponse;
import org.signal.zkgroup.auth.ClientZkAuthOperations;
import org.signal.zkgroup.groups.ClientZkGroupCipher;
import org.signal.zkgroup.groups.GroupSecretParams;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import org.whispersystems.signalservice.internal.push.exceptions.ForbiddenException;
@@ -30,6 +29,7 @@ import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
public class GroupsV2Api {
@@ -114,8 +114,8 @@ public class GroupsV2Api {
GroupsV2Operations.GroupOperations groupOperations = groupsOperations.forGroup(groupSecretParams);
for (GroupChanges.GroupChangeState change : group.getGroupChanges().getGroupChangesList()) {
Optional<DecryptedGroup> decryptedGroup = change.hasGroupState() ? Optional.of(groupOperations.decryptGroup(change.getGroupState())) : Optional.absent();
Optional<DecryptedGroupChange> decryptedChange = change.hasGroupChange() ? groupOperations.decryptChange(change.getGroupChange(), false) : Optional.absent();
Optional<DecryptedGroup> decryptedGroup = change.hasGroupState() ? Optional.of(groupOperations.decryptGroup(change.getGroupState())) : Optional.empty();
Optional<DecryptedGroupChange> decryptedChange = change.hasGroupChange() ? groupOperations.decryptChange(change.getGroupChange(), false) : Optional.empty();
result.add(new DecryptedGroupHistoryEntry(decryptedGroup, decryptedChange));
}
@@ -39,7 +39,6 @@ import org.signal.zkgroup.profiles.ProfileKey;
import org.signal.zkgroup.profiles.ProfileKeyCredential;
import org.signal.zkgroup.profiles.ProfileKeyCredentialPresentation;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.security.SecureRandom;
@@ -47,6 +46,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -109,7 +109,7 @@ public final class GroupsV2Operations {
group.addMembers(groupOperations.member(self.getProfileKeyCredential().get(), Member.Role.ADMINISTRATOR));
for (GroupCandidate credential : members) {
ProfileKeyCredential profileKeyCredential = credential.getProfileKeyCredential().orNull();
ProfileKeyCredential profileKeyCredential = credential.getProfileKeyCredential().orElse(null);
if (profileKeyCredential != null) {
group.addMembers(groupOperations.member(profileKeyCredential, memberRole));
@@ -167,7 +167,7 @@ public final class GroupsV2Operations {
for (GroupCandidate credential : membersToAdd) {
Member.Role newMemberRole = Member.Role.DEFAULT;
ProfileKeyCredential profileKeyCredential = credential.getProfileKeyCredential().orNull();
ProfileKeyCredential profileKeyCredential = credential.getProfileKeyCredential().orElse(null);
if (profileKeyCredential != null) {
actions.addAddMembers(GroupChange.Actions.AddMemberAction
@@ -486,7 +486,7 @@ public final class GroupsV2Operations {
{
if (groupChange.getChangeEpoch() > HIGHEST_KNOWN_EPOCH) {
Log.w(TAG, String.format(Locale.US, "Ignoring change from Epoch %d. Highest known Epoch is %d", groupChange.getChangeEpoch(), HIGHEST_KNOWN_EPOCH));
return Optional.absent();
return Optional.empty();
}
GroupChange.Actions actions = verifySignature ? getVerifiedActions(groupChange) : getActions(groupChange);
@@ -2,13 +2,13 @@ package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException;
import org.whispersystems.signalservice.api.push.exceptions.RateLimitException;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content;
import java.util.List;
import java.util.Optional;
public class SendMessageResult {
@@ -6,12 +6,13 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.push.http.CancelationSignal;
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Optional;
public abstract class SignalServiceAttachment {
@@ -41,7 +42,7 @@ public abstract class SignalServiceAttachment {
}
public static SignalServiceAttachmentStream emptyStream(String contentType) {
return new SignalServiceAttachmentStream(new ByteArrayInputStream(new byte[0]), contentType, 0, Optional.absent(), false, false, false, null, null);
return new SignalServiceAttachmentStream(new ByteArrayInputStream(new byte[0]), contentType, 0, Optional.empty(), false, false, false, null, null);
}
public static class Builder {
@@ -147,19 +148,19 @@ public abstract class SignalServiceAttachment {
return new SignalServiceAttachmentStream(inputStream,
contentType,
length,
Optional.fromNullable(fileName),
Optional.ofNullable(fileName),
voiceNote,
borderless,
gif,
Optional.<byte[]>absent(),
Optional.empty(),
width,
height,
uploadTimestamp,
Optional.fromNullable(caption),
Optional.fromNullable(blurHash),
Optional.ofNullable(caption),
Optional.ofNullable(blurHash),
listener,
cancelationSignal,
Optional.fromNullable(resumableUploadSpec));
Optional.ofNullable(resumableUploadSpec));
}
}
@@ -6,9 +6,10 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
import java.util.Optional;
/**
* Represents a received SignalServiceAttachment "handle." This
* is a pointer to the actual attachment content, which needs to be
@@ -1,11 +1,10 @@
package org.whispersystems.signalservice.api.messages;
import org.signal.libsignal.metadata.ProtocolInvalidMessageException;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.InvalidMessageStructureException;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer;
import java.util.Optional;
/**
* Represents a signal service attachment identifier. This can be either a CDN key or a long, but
* not both at once. Attachments V2 used a long as an attachment identifier. This lacks sufficient
@@ -19,11 +18,11 @@ public final class SignalServiceAttachmentRemoteId {
public SignalServiceAttachmentRemoteId(long v2) {
this.v2 = Optional.of(v2);
this.v3 = Optional.absent();
this.v3 = Optional.empty();
}
public SignalServiceAttachmentRemoteId(String v3) {
this.v2 = Optional.absent();
this.v2 = Optional.empty();
this.v3 = Optional.of(v3);
}
@@ -6,32 +6,33 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.push.http.CancelationSignal;
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
import java.io.InputStream;
import java.util.Optional;
/**
* Represents a local SignalServiceAttachment to be sent.
*/
public class SignalServiceAttachmentStream extends SignalServiceAttachment {
private final InputStream inputStream;
private final long length;
private final Optional<String> fileName;
private final ProgressListener listener;
private final CancelationSignal cancelationSignal;
private final Optional<byte[]> preview;
private final boolean voiceNote;
private final boolean borderless;
private final boolean gif;
private final int width;
private final int height;
private final long uploadTimestamp;
private final Optional<String> caption;
private final Optional<String> blurHash;
private final Optional<ResumableUploadSpec> resumableUploadSpec;
private final InputStream inputStream;
private final long length;
private final Optional<String> fileName;
private final ProgressListener listener;
private final CancelationSignal cancelationSignal;
private final Optional<byte[]> preview;
private final boolean voiceNote;
private final boolean borderless;
private final boolean gif;
private final int width;
private final int height;
private final long uploadTimestamp;
private final Optional<String> caption;
private final Optional<String> blurHash;
private final Optional<ResumableUploadSpec> resumableUploadSpec;
public SignalServiceAttachmentStream(InputStream inputStream,
String contentType,
@@ -43,7 +44,7 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment {
ProgressListener listener,
CancelationSignal cancelationSignal)
{
this(inputStream, contentType, length, fileName, voiceNote, borderless, gif, Optional.<byte[]>absent(), 0, 0, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), listener, cancelationSignal, Optional.absent());
this(inputStream, contentType, length, fileName, voiceNote, borderless, gif, Optional.empty(), 0, 0, System.currentTimeMillis(), Optional.empty(), Optional.empty(), listener, cancelationSignal, Optional.empty());
}
public SignalServiceAttachmentStream(InputStream inputStream,
@@ -20,7 +20,6 @@ import org.whispersystems.libsignal.LegacyMessageException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.protocol.DecryptionErrorMessage;
import org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.InvalidMessageStructureException;
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
import org.whispersystems.signalservice.api.messages.calls.BusyMessage;
@@ -45,7 +44,6 @@ import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMes
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.payments.Money;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.storage.StorageKey;
@@ -62,6 +60,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public final class SignalServiceContent {
@@ -108,14 +107,14 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.fromNullable(message);
this.synchronizeMessage = Optional.absent();
this.callMessage = Optional.absent();
this.readMessage = Optional.absent();
this.typingMessage = Optional.absent();
this.message = Optional.ofNullable(message);
this.synchronizeMessage = Optional.empty();
this.callMessage = Optional.empty();
this.readMessage = Optional.empty();
this.typingMessage = Optional.empty();
this.senderKeyDistributionMessage = senderKeyDistributionMessage;
this.decryptionErrorMessage = Optional.absent();
this.storyMessage = Optional.absent();
this.decryptionErrorMessage = Optional.empty();
this.storyMessage = Optional.empty();
}
private SignalServiceContent(SignalServiceSyncMessage synchronizeMessage,
@@ -140,14 +139,14 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.absent();
this.synchronizeMessage = Optional.fromNullable(synchronizeMessage);
this.callMessage = Optional.absent();
this.readMessage = Optional.absent();
this.typingMessage = Optional.absent();
this.message = Optional.empty();
this.synchronizeMessage = Optional.ofNullable(synchronizeMessage);
this.callMessage = Optional.empty();
this.readMessage = Optional.empty();
this.typingMessage = Optional.empty();
this.senderKeyDistributionMessage = senderKeyDistributionMessage;
this.decryptionErrorMessage = Optional.absent();
this.storyMessage = Optional.absent();
this.decryptionErrorMessage = Optional.empty();
this.storyMessage = Optional.empty();
}
private SignalServiceContent(SignalServiceCallMessage callMessage,
@@ -172,14 +171,14 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.absent();
this.synchronizeMessage = Optional.absent();
this.message = Optional.empty();
this.synchronizeMessage = Optional.empty();
this.callMessage = Optional.of(callMessage);
this.readMessage = Optional.absent();
this.typingMessage = Optional.absent();
this.readMessage = Optional.empty();
this.typingMessage = Optional.empty();
this.senderKeyDistributionMessage = senderKeyDistributionMessage;
this.decryptionErrorMessage = Optional.absent();
this.storyMessage = Optional.absent();
this.decryptionErrorMessage = Optional.empty();
this.storyMessage = Optional.empty();
}
private SignalServiceContent(SignalServiceReceiptMessage receiptMessage,
@@ -204,14 +203,14 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.absent();
this.synchronizeMessage = Optional.absent();
this.callMessage = Optional.absent();
this.message = Optional.empty();
this.synchronizeMessage = Optional.empty();
this.callMessage = Optional.empty();
this.readMessage = Optional.of(receiptMessage);
this.typingMessage = Optional.absent();
this.typingMessage = Optional.empty();
this.senderKeyDistributionMessage = senderKeyDistributionMessage;
this.decryptionErrorMessage = Optional.absent();
this.storyMessage = Optional.absent();
this.decryptionErrorMessage = Optional.empty();
this.storyMessage = Optional.empty();
}
private SignalServiceContent(DecryptionErrorMessage errorMessage,
@@ -236,14 +235,14 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.absent();
this.synchronizeMessage = Optional.absent();
this.callMessage = Optional.absent();
this.readMessage = Optional.absent();
this.typingMessage = Optional.absent();
this.message = Optional.empty();
this.synchronizeMessage = Optional.empty();
this.callMessage = Optional.empty();
this.readMessage = Optional.empty();
this.typingMessage = Optional.empty();
this.senderKeyDistributionMessage = senderKeyDistributionMessage;
this.decryptionErrorMessage = Optional.of(errorMessage);
this.storyMessage = Optional.absent();
this.storyMessage = Optional.empty();
}
private SignalServiceContent(SignalServiceTypingMessage typingMessage,
@@ -268,14 +267,14 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.absent();
this.synchronizeMessage = Optional.absent();
this.callMessage = Optional.absent();
this.readMessage = Optional.absent();
this.message = Optional.empty();
this.synchronizeMessage = Optional.empty();
this.callMessage = Optional.empty();
this.readMessage = Optional.empty();
this.typingMessage = Optional.of(typingMessage);
this.senderKeyDistributionMessage = senderKeyDistributionMessage;
this.decryptionErrorMessage = Optional.absent();
this.storyMessage = Optional.absent();
this.decryptionErrorMessage = Optional.empty();
this.storyMessage = Optional.empty();
}
private SignalServiceContent(SenderKeyDistributionMessage senderKeyDistributionMessage,
@@ -299,14 +298,14 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.absent();
this.synchronizeMessage = Optional.absent();
this.callMessage = Optional.absent();
this.readMessage = Optional.absent();
this.typingMessage = Optional.absent();
this.message = Optional.empty();
this.synchronizeMessage = Optional.empty();
this.callMessage = Optional.empty();
this.readMessage = Optional.empty();
this.typingMessage = Optional.empty();
this.senderKeyDistributionMessage = Optional.of(senderKeyDistributionMessage);
this.decryptionErrorMessage = Optional.absent();
this.storyMessage = Optional.absent();
this.decryptionErrorMessage = Optional.empty();
this.storyMessage = Optional.empty();
}
private SignalServiceContent(SignalServiceStoryMessage storyMessage,
@@ -330,13 +329,13 @@ public final class SignalServiceContent {
this.groupId = groupId;
this.serializedState = serializedState;
this.message = Optional.absent();
this.synchronizeMessage = Optional.absent();
this.callMessage = Optional.absent();
this.readMessage = Optional.absent();
this.typingMessage = Optional.absent();
this.senderKeyDistributionMessage = Optional.absent();
this.decryptionErrorMessage = Optional.absent();
this.message = Optional.empty();
this.synchronizeMessage = Optional.empty();
this.callMessage = Optional.empty();
this.readMessage = Optional.empty();
this.typingMessage = Optional.empty();
this.senderKeyDistributionMessage = Optional.empty();
this.decryptionErrorMessage = Optional.empty();
this.storyMessage = Optional.of(storyMessage);
}
@@ -434,7 +433,7 @@ public final class SignalServiceContent {
SignalServiceProtos.DataMessage message = serviceContentProto.getLegacyDataMessage();
return new SignalServiceContent(createSignalServiceMessage(metadata, message),
Optional.absent(),
Optional.empty(),
metadata.getSender(),
metadata.getSenderDevice(),
metadata.getTimestamp(),
@@ -446,7 +445,7 @@ public final class SignalServiceContent {
serviceContentProto);
} else if (serviceContentProto.getDataCase() == SignalServiceContentProto.DataCase.CONTENT) {
SignalServiceProtos.Content message = serviceContentProto.getContent();
Optional<SenderKeyDistributionMessage> senderKeyDistributionMessage = Optional.absent();
Optional<SenderKeyDistributionMessage> senderKeyDistributionMessage = Optional.empty();
if (message.hasSenderKeyDistributionMessage()) {
try {
@@ -646,7 +645,7 @@ public final class SignalServiceContent {
SignalServiceDataMessage dataMessage = createSignalServiceMessage(metadata, sentContent.getMessage());
Optional<SignalServiceAddress> address = SignalServiceAddress.isValidAddress(sentContent.getDestinationUuid())
? Optional.of(new SignalServiceAddress(ServiceId.parseOrThrow(sentContent.getDestinationUuid())))
: Optional.<SignalServiceAddress>absent();
: Optional.empty();
if (!address.isPresent() && !dataMessage.getGroupContext().isPresent()) {
throw new InvalidMessageStructureException("SyncMessage missing both destination and group ID!");
@@ -789,10 +788,10 @@ public final class SignalServiceContent {
Boolean typingIndicators = content.getConfiguration().hasTypingIndicators() ? content.getConfiguration().getTypingIndicators() : null;
Boolean linkPreviews = content.getConfiguration().hasLinkPreviews() ? content.getConfiguration().getLinkPreviews() : null;
return SignalServiceSyncMessage.forConfiguration(new ConfigurationMessage(Optional.fromNullable(readReceipts),
Optional.fromNullable(unidentifiedDeliveryIndicators),
Optional.fromNullable(typingIndicators),
Optional.fromNullable(linkPreviews)));
return SignalServiceSyncMessage.forConfiguration(new ConfigurationMessage(Optional.ofNullable(readReceipts),
Optional.ofNullable(unidentifiedDeliveryIndicators),
Optional.ofNullable(typingIndicators),
Optional.ofNullable(linkPreviews)));
}
if (content.hasFetchLatest() && content.getFetchLatest().hasType()) {
@@ -857,7 +856,7 @@ public final class SignalServiceContent {
mobileCoin.getReceipt(),
mobileCoin.getLedgerBlockIndex(),
mobileCoin.getLedgerBlockTimestamp(),
address.isEmpty() ? Optional.absent() : Optional.of(address.toByteArray()),
address.isEmpty() ? Optional.empty() : Optional.of(address.toByteArray()),
Optional.of(outgoingPayment.getNote()),
mobileCoin.getOutputPublicKeysList(),
mobileCoin.getSpentKeyImagesList()));
@@ -949,7 +948,7 @@ public final class SignalServiceContent {
return new SignalServiceTypingMessage(action, content.getTimestamp(),
content.hasGroupId() ? Optional.of(content.getGroupId().toByteArray()) :
Optional.absent());
Optional.empty());
}
private static SignalServiceStoryMessage createStoryMessage(SignalServiceProtos.StoryMessage content) throws InvalidMessageStructureException {
@@ -1018,7 +1017,7 @@ public final class SignalServiceContent {
preview.getTitle(),
preview.getDescription(),
preview.getDate(),
Optional.fromNullable(attachment));
Optional.ofNullable(attachment));
}
private static List<SignalServiceDataMessage.Mention> createMentions(List<SignalServiceProtos.DataMessage.BodyRange> bodyRanges, String body, boolean isGroupV2)
@@ -1274,10 +1273,10 @@ public final class SignalServiceContent {
}
}
Optional<String> text = Optional.fromNullable(attachment.hasText() ? attachment.getText() : null);
Optional<Integer> textForegroundColor = Optional.fromNullable(attachment.hasTextForegroundColor() ? attachment.getTextForegroundColor() : null);
Optional<Integer> textBackgroundColor = Optional.fromNullable(attachment.hasTextBackgroundColor() ? attachment.getTextBackgroundColor() : null);
Optional<SignalServicePreview> preview = Optional.fromNullable(attachment.hasPreview() ? createPreview(attachment.getPreview()) : null);
Optional<String> text = Optional.ofNullable(attachment.hasText() ? attachment.getText() : null);
Optional<Integer> textForegroundColor = Optional.ofNullable(attachment.hasTextForegroundColor() ? attachment.getTextForegroundColor() : null);
Optional<Integer> textBackgroundColor = Optional.ofNullable(attachment.hasTextBackgroundColor() ? attachment.getTextBackgroundColor() : null);
Optional<SignalServicePreview> preview = Optional.ofNullable(attachment.hasPreview() ? createPreview(attachment.getPreview()) : null);
if (attachment.hasGradient()) {
SignalServiceProtos.TextAttachment.Gradient attachmentGradient = attachment.getGradient();
@@ -1285,13 +1284,13 @@ public final class SignalServiceContent {
Integer startColor = attachmentGradient.hasStartColor() ? attachmentGradient.getStartColor() : null;
Integer endColor = attachmentGradient.hasEndColor() ? attachmentGradient.getEndColor() : null;
Integer angle = attachmentGradient.hasAngle() ? attachmentGradient.getAngle() : null;
SignalServiceTextAttachment.Gradient gradient = new SignalServiceTextAttachment.Gradient(Optional.fromNullable(startColor),
Optional.fromNullable(endColor),
Optional.fromNullable(angle));
SignalServiceTextAttachment.Gradient gradient = new SignalServiceTextAttachment.Gradient(Optional.ofNullable(startColor),
Optional.ofNullable(endColor),
Optional.ofNullable(angle));
return SignalServiceTextAttachment.forGradientBackground(text, Optional.fromNullable(style), textForegroundColor, textBackgroundColor, preview, gradient);
return SignalServiceTextAttachment.forGradientBackground(text, Optional.ofNullable(style), textForegroundColor, textBackgroundColor, preview, gradient);
} else {
return SignalServiceTextAttachment.forSolidBackground(text, Optional.fromNullable(style), textForegroundColor, textBackgroundColor, preview, attachment.getColor());
return SignalServiceTextAttachment.forSolidBackground(text, Optional.ofNullable(style), textForegroundColor, textBackgroundColor, preview, attachment.getColor());
}
}
@@ -8,7 +8,6 @@ package org.whispersystems.signalservice.api.messages;
import org.signal.zkgroup.groups.GroupSecretParams;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@@ -16,6 +15,7 @@ import org.whispersystems.signalservice.api.util.OptionalUtil;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
/**
* Represents a decrypted Signal Service data message.
@@ -87,39 +87,39 @@ public class SignalServiceDataMessage {
this.endSession = endSession;
this.expiresInSeconds = expiresInSeconds;
this.expirationUpdate = expirationUpdate;
this.profileKey = Optional.fromNullable(profileKey);
this.profileKey = Optional.ofNullable(profileKey);
this.profileKeyUpdate = profileKeyUpdate;
this.quote = Optional.fromNullable(quote);
this.sticker = Optional.fromNullable(sticker);
this.quote = Optional.ofNullable(quote);
this.sticker = Optional.ofNullable(sticker);
this.viewOnce = viewOnce;
this.reaction = Optional.fromNullable(reaction);
this.remoteDelete = Optional.fromNullable(remoteDelete);
this.groupCallUpdate = Optional.fromNullable(groupCallUpdate);
this.payment = Optional.fromNullable(payment);
this.storyContext = Optional.fromNullable(storyContext);
this.reaction = Optional.ofNullable(reaction);
this.remoteDelete = Optional.ofNullable(remoteDelete);
this.groupCallUpdate = Optional.ofNullable(groupCallUpdate);
this.payment = Optional.ofNullable(payment);
this.storyContext = Optional.ofNullable(storyContext);
if (attachments != null && !attachments.isEmpty()) {
this.attachments = Optional.of(attachments);
} else {
this.attachments = Optional.absent();
this.attachments = Optional.empty();
}
if (sharedContacts != null && !sharedContacts.isEmpty()) {
this.contacts = Optional.of(sharedContacts);
} else {
this.contacts = Optional.absent();
this.contacts = Optional.empty();
}
if (previews != null && !previews.isEmpty()) {
this.previews = Optional.of(previews);
} else {
this.previews = Optional.absent();
this.previews = Optional.empty();
}
if (mentions != null && !mentions.isEmpty()) {
this.mentions = Optional.of(mentions);
} else {
this.mentions = Optional.absent();
this.mentions = Optional.empty();
}
}
@@ -264,7 +264,7 @@ public class SignalServiceDataMessage {
.serialize();
}
return Optional.fromNullable(groupId);
return Optional.ofNullable(groupId);
}
public static class Builder {
@@ -9,14 +9,15 @@ package org.whispersystems.signalservice.api.messages;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.OptionalUtil;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.Envelope;
import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceEnvelopeProto;
import org.whispersystems.util.Base64;
import java.io.IOException;
import java.util.Optional;
/**
* This class represents an encrypted Signal Service envelope.
@@ -131,18 +132,18 @@ public class SignalServiceEnvelope {
* @return The envelope's sender as an E164 number.
*/
public Optional<String> getSourceE164() {
return Optional.fromNullable(envelope.getSourceE164());
return Optional.ofNullable(envelope.getSourceE164());
}
/**
* @return The envelope's sender as a UUID.
*/
public Optional<String> getSourceUuid() {
return Optional.fromNullable(envelope.getSourceUuid());
return Optional.ofNullable(envelope.getSourceUuid());
}
public String getSourceIdentifier() {
return getSourceUuid().or(getSourceE164()).orNull();
return OptionalUtil.or(getSourceUuid(), getSourceE164()).orElse(null);
}
public boolean hasSourceDevice() {
@@ -6,10 +6,11 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.List;
import java.util.Optional;
/**
* Group information to include in SignalServiceMessages destined to groups.
@@ -63,9 +64,9 @@ public class SignalServiceGroup {
{
this.type = type;
this.groupId = groupId;
this.name = Optional.fromNullable(name);
this.members = Optional.fromNullable(members);
this.avatar = Optional.fromNullable(avatar);
this.name = Optional.ofNullable(name);
this.members = Optional.ofNullable(members);
this.avatar = Optional.ofNullable(avatar);
}
public byte[] getGroupId() {
@@ -1,7 +1,9 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public final class SignalServiceGroupContext {
@@ -10,11 +12,11 @@ public final class SignalServiceGroupContext {
private SignalServiceGroupContext(SignalServiceGroup groupV1) {
this.groupV1 = Optional.of(groupV1);
this.groupV2 = Optional.absent();
this.groupV2 = Optional.empty();
}
private SignalServiceGroupContext(SignalServiceGroupV2 groupV2) {
this.groupV1 = Optional.absent();
this.groupV1 = Optional.empty();
this.groupV2 = Optional.of(groupV2);
}
@@ -29,7 +31,7 @@ public final class SignalServiceGroupContext {
static Optional<SignalServiceGroupContext> createOptional(SignalServiceGroup groupV1, SignalServiceGroupV2 groupV2)
throws InvalidMessageException
{
return Optional.fromNullable(create(groupV1, groupV2));
return Optional.ofNullable(create(groupV1, groupV2));
}
public static SignalServiceGroupContext create(SignalServiceGroup groupV1, SignalServiceGroupV2 groupV2)
@@ -1,8 +1,10 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Optional;
public final class SignalServiceMetadata {
private final SignalServiceAddress sender;
private final int senderDevice;
@@ -1,6 +1,7 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class SignalServicePreview {
private final String url;
@@ -1,10 +1,11 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class SignalServiceStickerManifest {
@@ -14,9 +15,9 @@ public class SignalServiceStickerManifest {
private final List<StickerInfo> stickers;
public SignalServiceStickerManifest(String title, String author, StickerInfo cover, List<StickerInfo> stickers) {
this.title = Optional.fromNullable(title);
this.author = Optional.fromNullable(author);
this.cover = Optional.fromNullable(cover);
this.title = Optional.ofNullable(title);
this.author = Optional.ofNullable(author);
this.cover = Optional.ofNullable(cover);
this.stickers = (stickers == null) ? Collections.<StickerInfo>emptyList() : new ArrayList<>(stickers);
}
@@ -1,11 +1,12 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class SignalServiceStoryMessage {
private final Optional<byte[]> profileKey;
private final Optional<SignalServiceGroupV2> groupContext;
private final Optional<SignalServiceAttachment> fileAttachment;
private final Optional<byte[]> profileKey;
private final Optional<SignalServiceGroupV2> groupContext;
private final Optional<SignalServiceAttachment> fileAttachment;
private final Optional<SignalServiceTextAttachment> textAttachment;
private final Optional<Boolean> allowsReplies;
@@ -14,10 +15,10 @@ public class SignalServiceStoryMessage {
SignalServiceAttachment fileAttachment,
SignalServiceTextAttachment textAttachment,
boolean allowsReplies) {
this.profileKey = Optional.fromNullable(profileKey);
this.groupContext = Optional.fromNullable(groupContext);
this.fileAttachment = Optional.fromNullable(fileAttachment);
this.textAttachment = Optional.fromNullable(textAttachment);
this.profileKey = Optional.ofNullable(profileKey);
this.groupContext = Optional.ofNullable(groupContext);
this.fileAttachment = Optional.ofNullable(fileAttachment);
this.textAttachment = Optional.ofNullable(textAttachment);
this.allowsReplies = Optional.of(allowsReplies);
}
@@ -1,12 +1,13 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class SignalServiceTextAttachment {
private final Optional<String> text;
private final Optional<Style> style;
private final Optional<Integer> textForegroundColor;
private final Optional<String> text;
private final Optional<Style> style;
private final Optional<Integer> textForegroundColor;
private final Optional<Integer> textBackgroundColor;
private final Optional<SignalServicePreview> preview;
private final Optional<Gradient> backgroundGradient;
@@ -40,7 +41,7 @@ public class SignalServiceTextAttachment {
textBackgroundColor,
preview,
Optional.of(backgroundGradient),
Optional.absent());
Optional.empty());
}
public static SignalServiceTextAttachment forSolidBackground(Optional<String> text,
@@ -54,7 +55,7 @@ public class SignalServiceTextAttachment {
textForegroundColor,
textBackgroundColor,
preview,
Optional.absent(),
Optional.empty(),
Optional.of(backgroundColor));
}
@@ -1,6 +1,7 @@
package org.whispersystems.signalservice.api.messages;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class SignalServiceTypingMessage {
@@ -1,9 +1,10 @@
package org.whispersystems.signalservice.api.messages.calls;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
public class SignalServiceCallMessage {
@@ -27,7 +28,7 @@ public class SignalServiceCallMessage {
boolean isMultiRing,
Optional<Integer> destinationDeviceId)
{
this(offerMessage, answerMessage, iceUpdateMessages, hangupMessage, busyMessage, opaqueMessage, isMultiRing, destinationDeviceId, Optional.absent(), Optional.absent());
this(offerMessage, answerMessage, iceUpdateMessages, hangupMessage, busyMessage, opaqueMessage, isMultiRing, destinationDeviceId, Optional.empty(), Optional.empty());
}
private SignalServiceCallMessage(Optional<OfferMessage> offerMessage,
@@ -55,107 +56,107 @@ public class SignalServiceCallMessage {
public static SignalServiceCallMessage forOffer(OfferMessage offerMessage, boolean isMultiRing, Integer destinationDeviceId) {
return new SignalServiceCallMessage(Optional.of(offerMessage),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
isMultiRing,
Optional.fromNullable(destinationDeviceId));
Optional.ofNullable(destinationDeviceId));
}
public static SignalServiceCallMessage forAnswer(AnswerMessage answerMessage, boolean isMultiRing, Integer destinationDeviceId) {
return new SignalServiceCallMessage(Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.of(answerMessage),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
isMultiRing,
Optional.fromNullable(destinationDeviceId));
Optional.ofNullable(destinationDeviceId));
}
public static SignalServiceCallMessage forIceUpdates(List<IceUpdateMessage> iceUpdateMessages, boolean isMultiRing, Integer destinationDeviceId) {
return new SignalServiceCallMessage(Optional.absent(),
Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.empty(),
Optional.of(iceUpdateMessages),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
isMultiRing,
Optional.fromNullable(destinationDeviceId));
Optional.ofNullable(destinationDeviceId));
}
public static SignalServiceCallMessage forIceUpdate(final IceUpdateMessage iceUpdateMessage, boolean isMultiRing, Integer destinationDeviceId) {
List<IceUpdateMessage> iceUpdateMessages = new LinkedList<>();
iceUpdateMessages.add(iceUpdateMessage);
return new SignalServiceCallMessage(Optional.absent(),
Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.empty(),
Optional.of(iceUpdateMessages),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
isMultiRing,
Optional.fromNullable(destinationDeviceId));
Optional.ofNullable(destinationDeviceId));
}
public static SignalServiceCallMessage forHangup(HangupMessage hangupMessage, boolean isMultiRing, Integer destinationDeviceId) {
return new SignalServiceCallMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(hangupMessage),
Optional.absent(),
Optional.absent(),
Optional.empty(),
Optional.empty(),
isMultiRing,
Optional.fromNullable(destinationDeviceId));
Optional.ofNullable(destinationDeviceId));
}
public static SignalServiceCallMessage forBusy(BusyMessage busyMessage, boolean isMultiRing, Integer destinationDeviceId) {
return new SignalServiceCallMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(busyMessage),
Optional.absent(),
Optional.empty(),
isMultiRing,
Optional.fromNullable(destinationDeviceId));
Optional.ofNullable(destinationDeviceId));
}
public static SignalServiceCallMessage forOpaque(OpaqueMessage opaqueMessage, boolean isMultiRing, Integer destinationDeviceId) {
return new SignalServiceCallMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(opaqueMessage),
isMultiRing,
Optional.fromNullable(destinationDeviceId));
Optional.ofNullable(destinationDeviceId));
}
public static SignalServiceCallMessage forOutgoingGroupOpaque(byte[] groupId, long timestamp, OpaqueMessage opaqueMessage, boolean isMultiRing, Integer destinationDeviceId) {
return new SignalServiceCallMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(opaqueMessage),
isMultiRing,
Optional.fromNullable(destinationDeviceId),
Optional.ofNullable(destinationDeviceId),
Optional.of(groupId),
Optional.of(timestamp));
}
public static SignalServiceCallMessage empty() {
return new SignalServiceCallMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceCallMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
false,
Optional.absent());
Optional.empty());
}
public Optional<List<IceUpdateMessage>> getIceUpdateMessages() {
@@ -1,6 +1,5 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -1,7 +1,7 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class ConfigurationMessage {
@@ -7,10 +7,11 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.signal.zkgroup.profiles.ProfileKey;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Optional;
public class DeviceContact {
private final SignalServiceAddress address;
@@ -12,7 +12,6 @@ import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@@ -21,6 +20,7 @@ import org.whispersystems.signalservice.internal.util.Util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
public class DeviceContactsInputStream extends ChunkedInputStream {
@@ -46,14 +46,14 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
}
SignalServiceAddress address = new SignalServiceAddress(ServiceId.parseOrThrow(details.getUuid()), details.getNumber());
Optional<String> name = Optional.fromNullable(details.getName());
Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
Optional<String> color = details.hasColor() ? Optional.of(details.getColor()) : Optional.<String>absent();
Optional<VerifiedMessage> verified = Optional.absent();
Optional<ProfileKey> profileKey = Optional.absent();
Optional<String> name = Optional.ofNullable(details.getName());
Optional<SignalServiceAttachmentStream> avatar = Optional.empty();
Optional<String> color = details.hasColor() ? Optional.of(details.getColor()) : Optional.empty();
Optional<VerifiedMessage> verified = Optional.empty();
Optional<ProfileKey> profileKey = Optional.empty();
boolean blocked = false;
Optional<Integer> expireTimer = Optional.absent();
Optional<Integer> inboxPosition = Optional.absent();
Optional<Integer> expireTimer = Optional.empty();
Optional<Integer> inboxPosition = Optional.empty();
boolean archived = false;
if (details.hasAvatar()) {
@@ -61,7 +61,7 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
InputStream avatarStream = new LimitedInputStream(in, avatarLength);
String avatarContentType = details.getAvatar().getContentType();
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, false, false, null, null));
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.empty(), false, false, false, null, null));
}
if (details.hasVerified()) {
@@ -84,13 +84,13 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
verified = Optional.of(new VerifiedMessage(destination, identityKey, state, System.currentTimeMillis()));
} catch (InvalidKeyException | InvalidMessageException e) {
Log.w(TAG, e);
verified = Optional.absent();
verified = Optional.empty();
}
}
if (details.hasProfileKey()) {
try {
profileKey = Optional.fromNullable(new ProfileKey(details.getProfileKey().toByteArray()));
profileKey = Optional.ofNullable(new ProfileKey(details.getProfileKey().toByteArray()));
} catch (InvalidInputException e) {
Log.w(TAG, "Invalid profile key ignored", e);
}
@@ -6,11 +6,12 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.List;
import java.util.Optional;
public class DeviceGroup {
@@ -9,7 +9,6 @@ package org.whispersystems.signalservice.api.messages.multidevice;
import com.google.protobuf.ByteString;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupDetails;
import java.io.IOException;
@@ -1,9 +1,11 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.storage.StorageKey;
import java.util.Optional;
public class KeysMessage {
private final Optional<StorageKey> storageService;
@@ -1,9 +1,11 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Optional;
public class MessageRequestResponseMessage {
private final Optional<SignalServiceAddress> person;
@@ -11,11 +13,11 @@ public class MessageRequestResponseMessage {
private final Type type;
public static MessageRequestResponseMessage forIndividual(SignalServiceAddress address, Type type) {
return new MessageRequestResponseMessage(Optional.of(address), Optional.<byte[]>absent(), type);
return new MessageRequestResponseMessage(Optional.of(address), Optional.empty(), type);
}
public static MessageRequestResponseMessage forGroup(byte[] groupId, Type type) {
return new MessageRequestResponseMessage(Optional.<SignalServiceAddress>absent(), Optional.of(groupId), type);
return new MessageRequestResponseMessage(Optional.empty(), Optional.of(groupId), type);
}
private MessageRequestResponseMessage(Optional<SignalServiceAddress> person,
@@ -2,12 +2,11 @@ package org.whispersystems.signalservice.api.messages.multidevice;
import com.google.protobuf.ByteString;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.payments.Money;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.List;
import java.util.UUID;
import java.util.Optional;
public final class OutgoingPaymentMessage {
@@ -6,13 +6,14 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
public class SentTranscriptMessage {
@@ -6,12 +6,13 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage.PniIdentity;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
public class SignalServiceSyncMessage {
@@ -69,347 +70,347 @@ public class SignalServiceSyncMessage {
public static SignalServiceSyncMessage forSentTranscript(SentTranscriptMessage sent) {
return new SignalServiceSyncMessage(Optional.of(sent),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forContacts(ContactsMessage contacts) {
return new SignalServiceSyncMessage(Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.of(contacts),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forGroups(SignalServiceAttachment groups) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.of(groups),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forRequest(RequestMessage request) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(request),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forRead(List<ReadMessage> reads) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(reads),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forViewed(List<ViewedMessage> views) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(views),
Optional.absent());
Optional.empty());
}
public static SignalServiceSyncMessage forViewOnceOpen(ViewOnceOpenMessage timerRead) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(timerRead),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forRead(ReadMessage read) {
List<ReadMessage> reads = new LinkedList<>();
reads.add(read);
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(reads),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forVerified(VerifiedMessage verifiedMessage) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(verifiedMessage),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forBlocked(BlockedListMessage blocked) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(blocked),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forConfiguration(ConfigurationMessage configuration) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(configuration),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forStickerPackOperations(List<StickerPackOperationMessage> stickerPackOperations) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(stickerPackOperations),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forFetchLatest(FetchType fetchType) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(fetchType),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forKeys(KeysMessage keys) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(keys),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forMessageRequestResponse(MessageRequestResponseMessage messageRequestResponse) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(messageRequestResponse),
Optional.absent(),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forOutgoingPayment(OutgoingPaymentMessage outgoingPaymentMessage) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(outgoingPaymentMessage),
Optional.absent(),
Optional.absent());
Optional.empty(),
Optional.empty());
}
public static SignalServiceSyncMessage forPniIdentity(PniIdentity pniIdentity) {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(pniIdentity));
}
public static SignalServiceSyncMessage empty() {
return new SignalServiceSyncMessage(Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent());
return new SignalServiceSyncMessage(Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty());
}
public Optional<SentTranscriptMessage> getSent() {
@@ -1,6 +1,7 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class StickerPackOperationMessage {
@@ -9,9 +10,9 @@ public class StickerPackOperationMessage {
private final Optional<Type> type;
public StickerPackOperationMessage(byte[] packId, byte[] packKey, Type type) {
this.packId = Optional.fromNullable(packId);
this.packKey = Optional.fromNullable(packKey);
this.type = Optional.fromNullable(type);
this.packId = Optional.ofNullable(packId);
this.packKey = Optional.ofNullable(packKey);
this.type = Optional.ofNullable(type);
}
public Optional<byte[]> getPackId() {
@@ -1,18 +1,19 @@
package org.whispersystems.signalservice.api.messages.shared;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
public class SharedContact {
private final Name name;
private final Optional<Avatar> avatar;
private final Optional<List<Phone>> phone;
private final Optional<List<Email>> email;
private final Optional<Avatar> avatar;
private final Optional<List<Phone>> phone;
private final Optional<List<Email>> email;
private final Optional<List<PostalAddress>> address;
private final Optional<String> organization;
@@ -185,12 +186,12 @@ public class SharedContact {
}
public Name build() {
return new Name(Optional.fromNullable(display),
Optional.fromNullable(given),
Optional.fromNullable(family),
Optional.fromNullable(prefix),
Optional.fromNullable(suffix),
Optional.fromNullable(middle));
return new Name(Optional.ofNullable(display),
Optional.ofNullable(given),
Optional.ofNullable(family),
Optional.ofNullable(prefix),
Optional.ofNullable(suffix),
Optional.ofNullable(middle));
}
}
}
@@ -248,7 +249,7 @@ public class SharedContact {
}
public Phone build() {
return new Phone(value, type, Optional.fromNullable(label));
return new Phone(value, type, Optional.ofNullable(label));
}
}
}
@@ -306,7 +307,7 @@ public class SharedContact {
}
public Email build() {
return new Email(value, type, Optional.fromNullable(label));
return new Email(value, type, Optional.ofNullable(label));
}
}
}
@@ -440,10 +441,10 @@ public class SharedContact {
}
public PostalAddress build() {
return new PostalAddress(type, Optional.fromNullable(label), Optional.fromNullable(street),
Optional.fromNullable(pobox), Optional.fromNullable(neighborhood),
Optional.fromNullable(city), Optional.fromNullable(region),
Optional.fromNullable(postcode), Optional.fromNullable(country));
return new PostalAddress(type, Optional.ofNullable(label), Optional.ofNullable(street),
Optional.ofNullable(pobox), Optional.ofNullable(neighborhood),
Optional.ofNullable(city), Optional.ofNullable(region),
Optional.ofNullable(postcode), Optional.ofNullable(country));
}
}
}
@@ -503,11 +504,11 @@ public class SharedContact {
}
public SharedContact build() {
return new SharedContact(name, Optional.fromNullable(avatar),
phone.isEmpty() ? Optional.<List<Phone>>absent() : Optional.of(phone),
email.isEmpty() ? Optional.<List<Email>>absent() : Optional.of(email),
address.isEmpty() ? Optional.<List<PostalAddress>>absent() : Optional.of(address),
Optional.fromNullable(organization));
return new SharedContact(name, Optional.ofNullable(avatar),
phone.isEmpty() ? Optional.empty() : Optional.of(phone),
email.isEmpty() ? Optional.empty() : Optional.of(email),
address.isEmpty() ? Optional.empty() : Optional.of(address),
Optional.ofNullable(organization));
}
}
}
@@ -1,7 +1,9 @@
package org.whispersystems.signalservice.api.profiles;
import org.signal.zkgroup.profiles.ProfileKeyCredential;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public final class ProfileAndCredential {
@@ -2,7 +2,6 @@ package org.whispersystems.signalservice.api.profiles;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -11,13 +10,11 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.profiles.ProfileKeyCredentialResponse;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.internal.util.JsonUtil;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
public class SignalServiceProfile {
@@ -3,7 +3,6 @@ package org.whispersystems.signalservice.api.push;
import com.google.protobuf.ByteString;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.util.Collection;
@@ -6,12 +6,12 @@
package org.whispersystems.signalservice.api.push;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.util.OptionalUtil;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.util.Objects;
import java.util.Optional;
/**
* A class representing a message destination or origin.
@@ -34,9 +34,9 @@ public class SignalServiceAddress {
this.e164 = e164;
}
public SignalServiceAddress(ServiceId serviceId) {
@SuppressWarnings("NewApi") public SignalServiceAddress(ServiceId serviceId) {
this.serviceId = Preconditions.checkNotNull(serviceId);
this.e164 = Optional.absent();
this.e164 = Optional.empty();
}
/**
@@ -78,7 +78,7 @@ public class SignalServiceAddress {
if (isValidAddress(rawUuid, e164)) {
return Optional.of(new SignalServiceAddress(ServiceId.parseOrThrow(rawUuid), e164));
} else {
return Optional.absent();
return Optional.empty();
}
}
@@ -4,8 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.signalservice.internal.util.JsonUtil;
import java.io.IOException;
import io.reactivex.rxjava3.annotations.NonNull;
/**
@@ -6,13 +6,14 @@
package org.whispersystems.signalservice.api.push.exceptions;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public class RateLimitException extends NonSuccessfulResponseCodeException {
private final Optional<Long> retryAfterMilliseconds;
public RateLimitException(int status, String message) {
this(status, message, Optional.absent());
this(status, message, Optional.empty());
}
public RateLimitException(int status, String message, Optional<Long> retryAfterMilliseconds) {
@@ -10,7 +10,6 @@ import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulRespons
import org.whispersystems.signalservice.internal.ServiceResponse;
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -6,7 +6,6 @@ import org.signal.cds.ClientRequest;
import org.signal.cds.ClientResponse;
import org.signal.zkgroup.profiles.ProfileKey;
import org.whispersystems.libsignal.util.ByteUtil;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.PNI;
@@ -23,6 +22,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -89,7 +89,7 @@ public final class CdshV2Service {
if (!pniUuid.equals(EMPTY_UUID)) {
PNI pni = PNI.from(pniUuid);
ACI aci = aciUuid.equals(EMPTY_UUID) ? null : ACI.from(aciUuid);
results.put(e164, new ResponseItem(pni, Optional.fromNullable(aci)));
results.put(e164, new ResponseItem(pni, Optional.ofNullable(aci)));
}
}
@@ -2,7 +2,6 @@ package org.whispersystems.signalservice.api.services;
import com.google.protobuf.ByteString;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalWebSocket;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
import org.whispersystems.signalservice.api.push.exceptions.NotFoundException;
@@ -28,6 +27,7 @@ import java.security.SecureRandom;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import io.reactivex.rxjava3.core.Single;
@@ -8,14 +8,11 @@ import org.signal.zkgroup.profiles.ProfileKeyCredentialRequest;
import org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext;
import org.signal.zkgroup.profiles.ProfileKeyVersion;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Function;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
import org.whispersystems.signalservice.api.SignalWebSocket;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
@@ -30,7 +27,9 @@ import org.whispersystems.signalservice.internal.websocket.WebSocketProtos;
import java.security.SecureRandom;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import io.reactivex.rxjava3.core.Single;
@@ -108,7 +107,7 @@ public final class ProfileService {
Locale locale)
{
return Single.fromFuture(receiver.retrieveProfile(address, profileKey, unidentifiedAccess, requestType, locale), 10, TimeUnit.SECONDS)
.onErrorResumeNext(t -> Single.fromFuture(receiver.retrieveProfile(address, profileKey, Optional.absent(), requestType, locale), 10, TimeUnit.SECONDS))
.onErrorResumeNext(t -> Single.fromFuture(receiver.retrieveProfile(address, profileKey, Optional.empty(), requestType, locale), 10, TimeUnit.SECONDS))
.map(p -> ServiceResponse.forResult(p, 0, null));
}
@@ -135,7 +134,7 @@ public final class ProfileService {
profileKeyCredential = clientZkProfileOperations.receiveProfileKeyCredential(requestContext, signalServiceProfile.getProfileKeyCredentialResponse());
}
return ServiceResponse.forResult(new ProfileAndCredential(signalServiceProfile, requestType, Optional.fromNullable(profileKeyCredential)), status, body);
return ServiceResponse.forResult(new ProfileAndCredential(signalServiceProfile, requestType, Optional.ofNullable(profileKeyCredential)), status, body);
} catch (VerificationFailedException e) {
return ServiceResponse.forApplicationError(e, status, body);
}
@@ -4,7 +4,6 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.payments.PaymentsConstants;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@@ -17,6 +16,7 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
public final class SignalAccountRecord implements SignalRecord {
@@ -298,19 +298,19 @@ public final class SignalAccountRecord implements SignalRecord {
}
public static PinnedConversation forContact(SignalServiceAddress address) {
return new PinnedConversation(Optional.of(address), Optional.absent(), Optional.absent());
return new PinnedConversation(Optional.of(address), Optional.empty(), Optional.empty());
}
public static PinnedConversation forGroupV1(byte[] groupId) {
return new PinnedConversation(Optional.absent(), Optional.of(groupId), Optional.absent());
return new PinnedConversation(Optional.empty(), Optional.of(groupId), Optional.empty());
}
public static PinnedConversation forGroupV2(byte[] masterKey) {
return new PinnedConversation(Optional.absent(), Optional.absent(), Optional.of(masterKey));
return new PinnedConversation(Optional.empty(), Optional.empty(), Optional.of(masterKey));
}
private static PinnedConversation forEmpty() {
return new PinnedConversation(Optional.absent(), Optional.absent(), Optional.absent());
return new PinnedConversation(Optional.empty(), Optional.empty(), Optional.empty());
}
static PinnedConversation fromRemote(AccountRecord.PinnedConversation remote) {
@@ -391,8 +391,8 @@ public final class SignalAccountRecord implements SignalRecord {
this.currencyCode = Optional.of(currencyCode);
this.id = Optional.of(id);
} else {
this.currencyCode = Optional.absent();
this.id = Optional.absent();
this.currencyCode = Optional.empty();
this.id = Optional.empty();
}
}
@@ -425,12 +425,12 @@ public final class SignalAccountRecord implements SignalRecord {
private final Optional<byte[]> entropy;
public Payments(boolean enabled, Optional<byte[]> entropy) {
byte[] entropyBytes = entropy.orNull();
byte[] entropyBytes = entropy.orElse(null);
if (entropyBytes != null && entropyBytes.length != PaymentsConstants.PAYMENTS_ENTROPY_LENGTH) {
Log.w(TAG, "Blocked entropy of length " + entropyBytes.length);
entropyBytes = null;
}
this.entropy = Optional.fromNullable(entropyBytes);
this.entropy = Optional.ofNullable(entropyBytes);
this.enabled = enabled && this.entropy.isPresent();
}
@@ -4,8 +4,6 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.OptionalUtil;
@@ -17,6 +15,7 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
public final class SignalContactRecord implements SignalRecord {
@@ -224,7 +223,7 @@ public final class SignalContactRecord implements SignalRecord {
}
builder.setServiceUuid(address.getServiceId().toString());
builder.setServiceE164(address.getNumber().or(""));
builder.setServiceE164(address.getNumber().orElse(""));
}
public Builder setGivenName(String givenName) {
@@ -6,7 +6,6 @@ import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.signalservice.api.util.ProtoUtil;
import org.whispersystems.signalservice.internal.storage.protos.GroupV1Record;
import org.whispersystems.signalservice.internal.storage.protos.GroupV2Record;
import java.util.Arrays;
import java.util.LinkedList;
@@ -3,16 +3,15 @@ package org.whispersystems.signalservice.api.storage;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.storage.protos.ManifestRecord;
import org.whispersystems.signalservice.internal.storage.protos.StorageManifest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class SignalStorageManifest {
public static final SignalStorageManifest EMPTY = new SignalStorageManifest(0, Collections.emptyList());
@@ -66,7 +65,7 @@ public class SignalStorageManifest {
if (list != null && list.size() > 0) {
return Optional.of(list.get(0));
} else {
return Optional.absent();
return Optional.empty();
}
}
@@ -1,9 +1,8 @@
package org.whispersystems.signalservice.api.storage;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.storage.protos.AccountRecord;
import java.util.Objects;
import java.util.Optional;
public class SignalStorageRecord implements SignalRecord {
@@ -18,7 +17,7 @@ public class SignalStorageRecord implements SignalRecord {
}
public static SignalStorageRecord forContact(StorageId key, SignalContactRecord contact) {
return new SignalStorageRecord(key, Optional.of(contact), Optional.<SignalGroupV1Record>absent(), Optional.<SignalGroupV2Record>absent(), Optional.<SignalAccountRecord>absent());
return new SignalStorageRecord(key, Optional.of(contact), Optional.empty(), Optional.empty(), Optional.empty());
}
public static SignalStorageRecord forGroupV1(SignalGroupV1Record groupV1) {
@@ -26,7 +25,7 @@ public class SignalStorageRecord implements SignalRecord {
}
public static SignalStorageRecord forGroupV1(StorageId key, SignalGroupV1Record groupV1) {
return new SignalStorageRecord(key, Optional.<SignalContactRecord>absent(), Optional.of(groupV1), Optional.<SignalGroupV2Record>absent(), Optional.<SignalAccountRecord>absent());
return new SignalStorageRecord(key, Optional.empty(), Optional.of(groupV1), Optional.empty(), Optional.empty());
}
public static SignalStorageRecord forGroupV2(SignalGroupV2Record groupV2) {
@@ -34,7 +33,7 @@ public class SignalStorageRecord implements SignalRecord {
}
public static SignalStorageRecord forGroupV2(StorageId key, SignalGroupV2Record groupV2) {
return new SignalStorageRecord(key, Optional.<SignalContactRecord>absent(), Optional.<SignalGroupV1Record>absent(), Optional.of(groupV2), Optional.<SignalAccountRecord>absent());
return new SignalStorageRecord(key, Optional.empty(), Optional.empty(), Optional.of(groupV2), Optional.empty());
}
public static SignalStorageRecord forAccount(SignalAccountRecord account) {
@@ -42,11 +41,11 @@ public class SignalStorageRecord implements SignalRecord {
}
public static SignalStorageRecord forAccount(StorageId key, SignalAccountRecord account) {
return new SignalStorageRecord(key, Optional.<SignalContactRecord>absent(), Optional.<SignalGroupV1Record>absent(), Optional.<SignalGroupV2Record>absent(), Optional.of(account));
return new SignalStorageRecord(key, Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(account));
}
public static SignalStorageRecord forUnknown(StorageId key) {
return new SignalStorageRecord(key,Optional.<SignalContactRecord>absent(), Optional.<SignalGroupV1Record>absent(), Optional.<SignalGroupV2Record>absent(), Optional.<SignalAccountRecord>absent());
return new SignalStorageRecord(key, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
}
private SignalStorageRecord(StorageId id,
@@ -1,6 +1,7 @@
package org.whispersystems.signalservice.api.storage;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.signalservice.internal.storage.protos.ManifestRecord;
import java.util.Arrays;
@@ -1,7 +1,6 @@
package org.whispersystems.signalservice.api.storage;
import org.whispersystems.signalservice.api.kbs.MasterKey;
import org.whispersystems.signalservice.internal.util.Hex;
import org.whispersystems.util.Base64;
import org.whispersystems.util.StringUtil;
@@ -1,7 +1,7 @@
package org.whispersystems.signalservice.api.subscriptions;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.util.Base64;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.util.Base64UrlSafe;
import java.security.SecureRandom;
@@ -1,7 +1,7 @@
package org.whispersystems.signalservice.api.subscriptions;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.util.Base64;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.util.Base64UrlSafe;
import java.security.SecureRandom;
@@ -3,13 +3,14 @@ package org.whispersystems.signalservice.api.util;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.InvalidMessageStructureException;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
import org.whispersystems.util.FlagUtil;
import java.util.Optional;
public final class AttachmentPointerUtil {
public static SignalServiceAttachmentPointer createSignalAttachmentPointer(byte[] pointer) throws InvalidMessageStructureException, InvalidProtocolBufferException {
return createSignalAttachmentPointer(SignalServiceProtos.AttachmentPointer.parseFrom(pointer));
@@ -20,16 +21,16 @@ public final class AttachmentPointerUtil {
SignalServiceAttachmentRemoteId.from(pointer),
pointer.getContentType(),
pointer.getKey().toByteArray(),
pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.<Integer>absent(),
pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.<byte[]>absent(),
pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.empty(),
pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.empty(),
pointer.getWidth(), pointer.getHeight(),
pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.empty(),
pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.empty(),
(pointer.getFlags() & FlagUtil.toBinaryFlag(SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE)) != 0,
(pointer.getFlags() & FlagUtil.toBinaryFlag(SignalServiceProtos.AttachmentPointer.Flags.BORDERLESS_VALUE)) != 0,
(pointer.getFlags() & FlagUtil.toBinaryFlag(SignalServiceProtos.AttachmentPointer.Flags.GIF_VALUE)) != 0,
pointer.hasCaption() ? Optional.of(pointer.getCaption()) : Optional.<String>absent(),
pointer.hasBlurHash() ? Optional.of(pointer.getBlurHash()) : Optional.<String>absent(),
pointer.hasCaption() ? Optional.of(pointer.getCaption()) : Optional.empty(),
pointer.hasBlurHash() ? Optional.of(pointer.getBlurHash()) : Optional.empty(),
pointer.hasUploadTimestamp() ? pointer.getUploadTimestamp() : 0);
}
@@ -2,45 +2,42 @@ package org.whispersystems.signalservice.api.util;
import com.google.protobuf.ByteString;
import org.whispersystems.libsignal.util.guava.Function;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Arrays;
import java.util.Optional;
public final class OptionalUtil {
private OptionalUtil() {
}
private OptionalUtil() { }
public static <T, R> Optional<R> flatMap(Optional<T> input, Function<T, Optional<R>> flatMapFunction) {
Optional<Optional<R>> output = input.transform(flatMapFunction);
if (output.isPresent()) {
return output.get();
} else {
return Optional.absent();
}
@SafeVarargs
public static <E> Optional<E> or(Optional<E>... optionals) {
return Arrays.stream(optionals)
.filter(Optional::isPresent)
.findFirst()
.orElse(Optional.empty());
}
public static boolean byteArrayEquals(Optional<byte[]> a, Optional<byte[]> b) {
if (a.isPresent() != b.isPresent()) {
return false;
}
if (a.isPresent()) {
} else if (a.isPresent()) {
return Arrays.equals(a.get(), b.get());
} else {
return true;
}
return true;
}
public static int byteArrayHashCode(Optional<byte[]> bytes) {
return bytes.isPresent() ? Arrays.hashCode(bytes.get()) : 0;
if (bytes.isPresent()) {
return Arrays.hashCode(bytes.get());
} else {
return 0;
}
}
public static Optional<String> absentIfEmpty(String value) {
if (value == null || value.length() == 0) {
return Optional.absent();
return Optional.empty();
} else {
return Optional.of(value);
}
@@ -48,7 +45,7 @@ public final class OptionalUtil {
public static Optional<byte[]> absentIfEmpty(ByteString value) {
if (value == null || value.isEmpty()) {
return Optional.absent();
return Optional.empty();
} else {
return Optional.of(value.toByteArray());
}
@@ -12,10 +12,10 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.util.Util;
import java.util.Locale;
import java.util.Optional;
import java.util.regex.Pattern;
/**
@@ -120,7 +120,7 @@ public class PhoneNumberFormatter {
*/
@Deprecated
public static String getRegionDisplayNameLegacy(String regionCode) {
return getRegionDisplayName(regionCode).or("Unknown country");
return getRegionDisplayName(regionCode).orElse("Unknown country");
}
public static Optional<String> getRegionDisplayName(String regionCode) {
@@ -130,7 +130,7 @@ public class PhoneNumberFormatter {
return Optional.of(displayCountry);
}
}
return Optional.absent();
return Optional.empty();
}
public static String formatE164(String countryCode, String number) {
@@ -0,0 +1,37 @@
package org.whispersystems.signalservice.api.util;
/**
* Convenient ways to assert expected state.
*/
public final class Preconditions {
private Preconditions() {}
public static void checkArgument(boolean state) {
checkArgument(state, "Condition must be true!");
}
public static void checkArgument(boolean state, String message) {
if (!state) {
throw new IllegalArgumentException(message);
}
}
public static void checkState(boolean state, String message) {
if (!state) {
throw new IllegalStateException(message);
}
}
public static <E> E checkNotNull(E object) {
return checkNotNull(object, "Must not be null!");
}
public static <E> E checkNotNull(E object, String message) {
if (object == null) {
throw new NullPointerException(message);
} else {
return object;
}
}
}
@@ -1,16 +1,11 @@
package org.whispersystems.signalservice.api.util;
import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.GeneratedMessageLite;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.UnknownFieldSetLite;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.ByteUtil;
import org.whispersystems.signalservice.api.InvalidMessageStructureException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;
@@ -1,6 +1,6 @@
package org.whispersystems.signalservice.api.util;
import org.whispersystems.libsignal.util.guava.Optional;
import java.io.IOException;
import java.io.InputStream;
@@ -14,6 +14,7 @@ import java.nio.channels.SocketChannel;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Optional;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
@@ -1,7 +1,5 @@
package org.whispersystems.signalservice.api.util;
import org.whispersystems.signalservice.api.util.SleepTimer;
/**
* A simle sleep timer. Since Thread.sleep is based on uptime
* this will not work properly in low-power sleep modes, when
@@ -2,12 +2,11 @@ package org.whispersystems.signalservice.api.util;
import com.google.protobuf.ByteString;
import org.whispersystems.libsignal.util.guava.Optional;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.regex.Pattern;
@@ -20,7 +19,7 @@ public final class UuidUtil {
private UuidUtil() { }
public static Optional<UUID> parse(String uuid) {
return Optional.fromNullable(parseOrNull(uuid));
return Optional.ofNullable(parseOrNull(uuid));
}
public static UUID parseOrNull(String uuid) {
@@ -1,11 +1,13 @@
package org.whispersystems.signalservice.internal;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.signalservice.internal.websocket.WebsocketResponse;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import io.reactivex.rxjava3.core.Single;
@@ -17,9 +19,9 @@ import io.reactivex.rxjava3.core.Single;
*/
public final class ServiceResponse<Result> {
private final int status;
private final Optional<String> body;
private final Optional<Result> result;
private final int status;
private final Optional<String> body;
private final Optional<Result> result;
private final Optional<Throwable> applicationError;
private final Optional<Throwable> executionError;
@@ -44,10 +46,10 @@ public final class ServiceResponse<Result> {
}
this.status = status;
this.body = Optional.fromNullable(body);
this.result = Optional.fromNullable(result);
this.applicationError = Optional.fromNullable(applicationError);
this.executionError = Optional.fromNullable(executionError);
this.body = Optional.ofNullable(body);
this.result = Optional.ofNullable(result);
this.applicationError = Optional.ofNullable(applicationError);
this.executionError = Optional.ofNullable(executionError);
}
public int getStatus() {
@@ -116,8 +118,8 @@ public final class ServiceResponse<Result> {
public static <T, I> ServiceResponse<T> coerceError(ServiceResponse<I> response) {
if (response.applicationError.isPresent()) {
return ServiceResponse.forApplicationError(response.applicationError.get(), response.status, response.body.orNull());
return ServiceResponse.forApplicationError(response.applicationError.get(), response.status, response.body.orElse(null));
}
return ServiceResponse.forExecutionError(response.executionError.orNull());
return ServiceResponse.forExecutionError(response.executionError.orElse(null));
}
}
@@ -1,7 +1,9 @@
package org.whispersystems.signalservice.internal;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
import org.whispersystems.signalservice.api.util.OptionalUtil;
import org.whispersystems.signalservice.api.util.Preconditions;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
@@ -58,7 +60,7 @@ public abstract class ServiceResponseProcessor<T> {
}
protected Throwable getError() {
return response.getApplicationError().or(response.getExecutionError()).orNull();
return OptionalUtil.or(response.getApplicationError(), response.getExecutionError()).orElse(null);
}
protected boolean authorizationFailed() {
@@ -1,9 +1,10 @@
package org.whispersystems.signalservice.internal.configuration;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import okhttp3.Dns;
import okhttp3.Interceptor;
@@ -1,14 +1,12 @@
package org.whispersystems.signalservice.internal.configuration;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.TrustStore;
import org.whispersystems.signalservice.internal.util.BlacklistingTrustManager;
import java.util.Collections;
import java.util.List;
import javax.net.ssl.TrustManager;
import java.util.Optional;
import okhttp3.ConnectionSpec;
@@ -28,9 +26,9 @@ public class SignalUrl {
ConnectionSpec connectionSpec)
{
this.url = url;
this.hostHeader = Optional.fromNullable(hostHeader);
this.hostHeader = Optional.ofNullable(hostHeader);
this.trustStore = trustStore;
this.connectionSpec = Optional.fromNullable(connectionSpec);
this.connectionSpec = Optional.ofNullable(connectionSpec);
}
@@ -47,7 +45,7 @@ public class SignalUrl {
}
public Optional<List<ConnectionSpec>> getConnectionSpecs() {
return connectionSpec.isPresent() ? Optional.of(Collections.singletonList(connectionSpec.get())) : Optional.<List<ConnectionSpec>>absent();
return connectionSpec.isPresent() ? Optional.of(Collections.singletonList(connectionSpec.get())) : Optional.empty();
}
}
@@ -11,7 +11,6 @@ import org.whispersystems.signalservice.internal.util.Util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -3,7 +3,6 @@ package org.whispersystems.signalservice.internal.contacts.crypto;
import org.whispersystems.util.Base64;
import java.io.ByteArrayInputStream;
import java.net.URLDecoder;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
@@ -18,7 +18,6 @@ package org.whispersystems.signalservice.internal.contacts.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
public class DiscoveryRequest {
@@ -2,7 +2,6 @@ package org.whispersystems.signalservice.internal.contacts.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
public class MultiRemoteAttestationResponse {
@@ -1,7 +1,8 @@
package org.whispersystems.signalservice.internal.push;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -26,7 +27,7 @@ public final class ContentRange {
}
}
return Optional.absent();
return Optional.empty();
}
private ContentRange(int rangeStart, int rangeEnd, int totalSize) {
@@ -36,8 +36,6 @@ import org.whispersystems.libsignal.state.PreKeyBundle;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Function;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.account.AccountAttributes;
import org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
@@ -125,7 +123,6 @@ import org.whispersystems.signalservice.internal.util.Util;
import org.whispersystems.signalservice.internal.util.concurrent.FutureTransformers;
import org.whispersystems.signalservice.internal.util.concurrent.ListenableFuture;
import org.whispersystems.signalservice.internal.util.concurrent.SettableFuture;
import org.whispersystems.signalservice.internal.websocket.DefaultErrorMapper;
import org.whispersystems.util.Base64;
import org.whispersystems.util.Base64UrlSafe;
@@ -148,10 +145,11 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@@ -530,7 +528,7 @@ public class PushServiceSocket {
}
public SignalServiceMessagesResult getMessages() throws IOException {
try (Response response = makeServiceRequest(String.format(MESSAGE_PATH, ""), "GET", (RequestBody) null, NO_HEADERS, NO_HANDLER, Optional.absent())) {
try (Response response = makeServiceRequest(String.format(MESSAGE_PATH, ""), "GET", (RequestBody) null, NO_HEADERS, NO_HANDLER, Optional.empty())) {
validateServiceResponse(response);
List<SignalServiceEnvelopeEntity> envelopes = readBodyJson(response.body(), SignalServiceEnvelopeEntityList.class).getMessages();
@@ -782,10 +780,10 @@ public class PushServiceSocket {
ProfileKeyCredential profileKeyCredential = signalServiceProfile.getProfileKeyCredentialResponse() != null
? clientZkProfileOperations.receiveProfileKeyCredential(requestContext, signalServiceProfile.getProfileKeyCredentialResponse())
: null;
return new ProfileAndCredential(signalServiceProfile, SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL, Optional.fromNullable(profileKeyCredential));
return new ProfileAndCredential(signalServiceProfile, SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL, Optional.ofNullable(profileKeyCredential));
} catch (VerificationFailedException e) {
Log.w(TAG, "Failed to verify credential.", e);
return new ProfileAndCredential(signalServiceProfile, SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL, Optional.absent());
return new ProfileAndCredential(signalServiceProfile, SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL, Optional.empty());
}
} catch (IOException e) {
Log.w(TAG, e);
@@ -834,7 +832,7 @@ public class PushServiceSocket {
requestBody,
NO_HEADERS,
PaymentsRegionException::responseCodeHandler,
Optional.absent());
Optional.empty());
if (signalServiceProfileWrite.hasAvatar() && profileAvatar != null) {
try {
@@ -854,7 +852,7 @@ public class PushServiceSocket {
return Optional.of(formAttributes.getKey());
}
return Optional.absent();
return Optional.empty();
}
public void setUsername(String username) throws IOException {
@@ -863,7 +861,7 @@ public class PushServiceSocket {
case 400: throw new UsernameMalformedException();
case 409: throw new UsernameTakenException();
}
}, Optional.<UnidentifiedAccess>absent());
}, Optional.empty());
}
public void deleteUsername() throws IOException {
@@ -1081,7 +1079,7 @@ public class PushServiceSocket {
public Optional<StorageManifest> writeStorageContacts(String authToken, WriteOperation writeOperation) throws IOException {
try {
makeAndCloseStorageRequest(authToken, "/v1/storage", "PUT", protobufRequestBody(writeOperation));
return Optional.absent();
return Optional.empty();
} catch (ContactManifestMismatchException e) {
return Optional.of(StorageManifest.parseFrom(e.getResponseBody()));
}
@@ -1536,7 +1534,7 @@ public class PushServiceSocket {
private String makeServiceRequestWithoutAuthentication(String urlFragment, String method, String jsonBody, Map<String, String> headers, ResponseCodeHandler responseCodeHandler)
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
{
ResponseBody responseBody = makeServiceRequest(urlFragment, method, jsonRequestBody(jsonBody), headers, responseCodeHandler, Optional.absent(), true).body();
ResponseBody responseBody = makeServiceRequest(urlFragment, method, jsonRequestBody(jsonBody), headers, responseCodeHandler, Optional.empty(), true).body();
try {
return responseBody.string();
} catch (IOException e) {
@@ -1547,19 +1545,19 @@ public class PushServiceSocket {
private String makeServiceRequest(String urlFragment, String method, String jsonBody)
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
{
return makeServiceRequest(urlFragment, method, jsonBody, NO_HEADERS, NO_HANDLER, Optional.<UnidentifiedAccess>absent());
return makeServiceRequest(urlFragment, method, jsonBody, NO_HEADERS, NO_HANDLER, Optional.empty());
}
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers)
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
{
return makeServiceRequest(urlFragment, method, jsonBody, headers, NO_HANDLER, Optional.<UnidentifiedAccess>absent());
return makeServiceRequest(urlFragment, method, jsonBody, headers, NO_HANDLER, Optional.empty());
}
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers, ResponseCodeHandler responseCodeHandler)
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
{
return makeServiceRequest(urlFragment, method, jsonBody, headers, responseCodeHandler, Optional.<UnidentifiedAccess>absent());
return makeServiceRequest(urlFragment, method, jsonBody, headers, responseCodeHandler, Optional.empty());
}
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers, Optional<UnidentifiedAccess> unidentifiedAccessKey)
@@ -1682,7 +1680,7 @@ public class PushServiceSocket {
case 413:
case 429: {
long retryAfterLong = Util.parseLong(response.header("Retry-After"), -1);
Optional<Long> retryAfter = retryAfterLong != -1 ? Optional.of(TimeUnit.SECONDS.toMillis(retryAfterLong)) : Optional.absent();
Optional<Long> retryAfter = retryAfterLong != -1 ? Optional.of(TimeUnit.SECONDS.toMillis(retryAfterLong)) : Optional.empty();
throw new RateLimitException(responseCode, "Rate limit exceeded: " + responseCode, retryAfter);
}
case 401:
@@ -2104,15 +2102,15 @@ public class PushServiceSocket {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager)trustManagers[0])
.connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS)))
.dns(dns.or(Dns.SYSTEM));
.connectionSpecs(url.getConnectionSpecs().orElse(Util.immutableList(ConnectionSpec.RESTRICTED_TLS)))
.dns(dns.orElse(Dns.SYSTEM));
if (proxy.isPresent()) {
builder.socketFactory(new TlsProxySocketFactory(proxy.get().getHost(), proxy.get().getPort(), dns));
}
builder.sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager)trustManagers[0])
.connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS)))
.connectionSpecs(url.getConnectionSpecs().orElse(Util.immutableList(ConnectionSpec.RESTRICTED_TLS)))
.build();
builder.connectionPool(new ConnectionPool(5, 45, TimeUnit.SECONDS));
@@ -2315,7 +2313,7 @@ public class PushServiceSocket {
"GET",
null,
NO_HEADERS,
Optional.absent());
Optional.empty());
return JsonUtil.fromJson(response, CredentialResponse.class);
}
@@ -2342,7 +2340,7 @@ public class PushServiceSocket {
@Override
public void handle(int responseCode, ResponseBody body, Function<String, String> getHeader) throws NonSuccessfulResponseCodeException {
if (responseCode == 403) {
throw new ForbiddenException(Optional.fromNullable(getHeader.apply("X-Signal-Forbidden-Reason")));
throw new ForbiddenException(Optional.ofNullable(getHeader.apply("X-Signal-Forbidden-Reason")));
}
}
};
@@ -2434,13 +2432,13 @@ public class PushServiceSocket {
}
}
return new GroupHistory(groupChanges, Optional.absent());
return new GroupHistory(groupChanges, Optional.empty());
}
public GroupJoinInfo getGroupJoinInfo(Optional<byte[]> groupLinkPassword, GroupsV2AuthorizationString authorization)
throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException
{
String passwordParam = groupLinkPassword.transform(Base64UrlSafe::encodeBytesWithoutPadding).or("");
String passwordParam = groupLinkPassword.map(Base64UrlSafe::encodeBytesWithoutPadding).orElse("");
ResponseBody response = makeStorageRequest(authorization.toString(),
String.format(GROUPSV2_GROUP_JOIN, passwordParam),
"GET",
@@ -3,7 +3,6 @@ package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.receipts.ReceiptCredentialRequest;
import org.signal.zkgroup.receipts.ReceiptCredentialResponse;
import org.whispersystems.util.Base64;
@@ -5,7 +5,6 @@ import org.whispersystems.libsignal.ecc.Curve;
import org.whispersystems.libsignal.ecc.ECKeyPair;
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
import org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException;
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
import org.whispersystems.signalservice.internal.contacts.crypto.Quote;
import org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation;
import org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestationCipher;
@@ -19,7 +18,6 @@ import org.whispersystems.signalservice.internal.util.JsonUtil;
import java.io.IOException;
import java.security.KeyStore;
import java.security.SignatureException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -1,7 +1,7 @@
package org.whispersystems.signalservice.internal.push;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Optional;
public final class RequestVerificationCodeResponse {
private final Optional<String> fcmToken;
@@ -3,14 +3,10 @@ package org.whispersystems.signalservice.internal.push;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class SendGroupMessageResponse {
@@ -1,8 +1,10 @@
package org.whispersystems.signalservice.internal.push;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
import java.util.Optional;
/**
* Exception that indicates that the data message contains something that is not supported by this
* version of the application. Subclasses provide more specific information about what data was
@@ -20,9 +22,9 @@ public abstract class UnsupportedDataMessageException extends Exception {
Optional<SignalServiceGroupContext> group)
{
super(message);
this.sender = sender;
this.senderDevice = senderDevice;
this.group = group;
this.sender = sender;
this.senderDevice = senderDevice;
this.group = group;
}
public String getSender() {
@@ -1,8 +1,10 @@
package org.whispersystems.signalservice.internal.push;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
import java.util.Optional;
/**
* Exception that indicates that the data message has a higher required protocol version than the
* current client is capable of interpreting.
@@ -1,13 +1,15 @@
package org.whispersystems.signalservice.internal.push.exceptions;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
import java.util.Optional;
public final class ForbiddenException extends NonSuccessfulResponseCodeException {
private Optional<String> reason;
public ForbiddenException() {
this(Optional.absent());
this(Optional.empty());
}
public ForbiddenException(Optional<String> reason) {
@@ -1,10 +1,11 @@
package org.whispersystems.signalservice.internal.push.http;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.crypto.DigestingOutputStream;
import org.whispersystems.signalservice.api.crypto.SkippingOutputStream;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener;
import org.whispersystems.signalservice.api.util.Preconditions;
import java.io.IOException;
import java.io.InputStream;
@@ -3,8 +3,6 @@ package org.whispersystems.signalservice.internal.push.http;
import com.google.protobuf.ByteString;
import org.signal.protos.resumableuploads.ResumableUploads;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.libsignal.util.guava.Preconditions;
import org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvalidException;
import org.whispersystems.util.Base64;
@@ -1,10 +1,5 @@
package org.whispersystems.signalservice.internal.registrationpin;
import org.whispersystems.signalservice.api.kbs.HashedPin;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
final class PinString {
static boolean allNumeric(CharSequence pin) {
@@ -1,11 +1,12 @@
package org.whispersystems.signalservice.internal.serialize;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.internal.serialize.protos.AddressProto;
import java.util.Optional;
public final class SignalServiceAddressProtobufSerializer {
private SignalServiceAddressProtobufSerializer() {
@@ -25,7 +26,7 @@ public final class SignalServiceAddressProtobufSerializer {
public static SignalServiceAddress fromProtobuf(AddressProto addressProto) {
ServiceId serviceId = ServiceId.parseOrThrow(addressProto.getUuid().toByteArray());
Optional<String> number = addressProto.hasE164() ? Optional.of(addressProto.getE164()) : Optional.absent();
Optional<String> number = addressProto.hasE164() ? Optional.of(addressProto.getE164()) : Optional.empty();
return new SignalServiceAddress(serviceId, number);
}
@@ -2,10 +2,11 @@ package org.whispersystems.signalservice.internal.serialize;
import com.google.protobuf.ByteString;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceMetadata;
import org.whispersystems.signalservice.internal.serialize.protos.MetadataProto;
import java.util.Optional;
public final class SignalServiceMetadataProtobufSerializer {
private SignalServiceMetadataProtobufSerializer() {
@@ -36,6 +37,6 @@ public final class SignalServiceMetadataProtobufSerializer {
metadata.getServerDeliveredTimestamp(),
metadata.getNeedsReceipt(),
metadata.getServerGuid(),
Optional.fromNullable(metadata.getGroupId()).transform(ByteString::toByteArray));
Optional.ofNullable(metadata.getGroupId()).map(ByteString::toByteArray));
}
}

Some files were not shown because too many files have changed in this diff Show More