From d7e525d82863f45ca49e96d96d44f54921471647 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Fri, 12 Mar 2021 14:52:59 +1100 Subject: [PATCH] clean --- .../crypto/UnidentifiedAccessUtil.java | 88 ------------------- .../activities/CreateClosedGroupActivity.kt | 3 +- .../activities/EditClosedGroupActivity.kt | 4 +- .../avatars/ContactColorsLegacy.java | 40 --------- .../sending_receiving/MessageSender.kt | 1 - .../MessageSenderClosedGroup.kt | 4 +- .../RecipientFormattingException.java | 12 --- .../recipients/RecipientsFormatter.java | 76 ---------------- .../utilities/UnidentifiedAccessUtil.kt | 63 ------------- .../crypto/InvalidCiphertextException.java | 11 --- .../api/crypto/UnidentifiedAccess.java | 45 ---------- .../crypto/UntrustedIdentityException.java | 30 ------- .../api/messages/SendMessageResult.java | 88 ------------------- 13 files changed, 5 insertions(+), 460 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java delete mode 100644 libsession/src/main/java/org/session/libsession/messaging/avatars/ContactColorsLegacy.java delete mode 100644 libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientsFormatter.java delete mode 100644 libsession/src/main/java/org/session/libsession/messaging/utilities/UnidentifiedAccessUtil.kt delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/crypto/InvalidCiphertextException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/crypto/UnidentifiedAccess.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/crypto/UntrustedIdentityException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/messages/SendMessageResult.java diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java deleted file mode 100644 index 27505c08e0..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.thoughtcrime.securesms.crypto; - - -import android.content.Context; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.WorkerThread; - -import org.session.libsession.utilities.preferences.ProfileKeyUtil; -import org.session.libsignal.metadata.SignalProtos; -import org.session.libsignal.utilities.logging.Log; -import org.session.libsession.messaging.threads.recipients.Recipient; -import org.session.libsession.utilities.TextSecurePreferences; -import org.session.libsession.utilities.Util; -import org.session.libsignal.libsignal.util.guava.Optional; -import org.session.libsignal.service.api.crypto.UnidentifiedAccess; -import org.session.libsignal.service.api.push.SignalServiceAddress; - -public class UnidentifiedAccessUtil { - - private static final String TAG = UnidentifiedAccessUtil.class.getSimpleName(); - - @WorkerThread - public static Optional getAccessFor(@NonNull Context context, - @NonNull Recipient recipient) - { - byte[] theirUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipient); - byte[] ourUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(context); - byte[] ourUnidentifiedAccessCertificate = getUnidentifiedAccessCertificate(context); - - if (TextSecurePreferences.isUniversalUnidentifiedAccess(context)) { - ourUnidentifiedAccessKey = Util.getSecretBytes(16); - } - - Log.i(TAG, "Their access key present? " + (theirUnidentifiedAccessKey != null) + - " | Our access key present? " + (ourUnidentifiedAccessKey != null) + - " | Our certificate present? " + (ourUnidentifiedAccessCertificate != null)); - - if (theirUnidentifiedAccessKey != null && - ourUnidentifiedAccessKey != null && - ourUnidentifiedAccessCertificate != null) - { - return Optional.of(new UnidentifiedAccess(theirUnidentifiedAccessKey)); - } - - return Optional.absent(); - } - - public static Optional getAccessForSync(@NonNull Context context) { - byte[] ourUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(context); - byte[] ourUnidentifiedAccessCertificate = getUnidentifiedAccessCertificate(context); - - if (TextSecurePreferences.isUniversalUnidentifiedAccess(context)) { - ourUnidentifiedAccessKey = Util.getSecretBytes(16); - } - - if (ourUnidentifiedAccessKey != null && ourUnidentifiedAccessCertificate != null) { - return Optional.of(new UnidentifiedAccess(ourUnidentifiedAccessKey)); - } - - return Optional.absent(); - } - - public static @NonNull byte[] getSelfUnidentifiedAccessKey(@NonNull Context context) { - return UnidentifiedAccess.deriveAccessKeyFrom(ProfileKeyUtil.getProfileKey(context)); - } - - private static @Nullable byte[] getTargetUnidentifiedAccessKey(@NonNull Recipient recipient) { - byte[] theirProfileKey = recipient.resolve().getProfileKey(); - - if (theirProfileKey == null) return Util.getSecretBytes(16); - else return UnidentifiedAccess.deriveAccessKeyFrom(theirProfileKey); - - } - - private static @Nullable byte[] getUnidentifiedAccessCertificate(Context context) { - String ourNumber = TextSecurePreferences.getLocalNumber(context); - if (ourNumber != null) { - SignalProtos.SenderCertificate certificate = SignalProtos.SenderCertificate.newBuilder() - .setSender(ourNumber) - .setSenderDevice(SignalServiceAddress.DEFAULT_DEVICE_ID) - .build(); - return certificate.toByteArray(); - } - - return null; - } -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt index 5f63e6ec4e..2ad317bdba 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt @@ -14,6 +14,7 @@ import kotlinx.android.synthetic.main.activity_create_closed_group.* import network.loki.messenger.R import nl.komponents.kovenant.ui.successUi import org.session.libsession.messaging.sending_receiving.MessageSender +import org.session.libsession.messaging.sending_receiving.groupSizeLimit import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.conversation.ConversationActivity import org.session.libsession.messaging.threads.Address @@ -103,7 +104,7 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM if (selectedMembers.count() < 1) { return Toast.makeText(this, R.string.activity_create_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show() } - if (selectedMembers.count() >= MessageSender.groupSizeLimit) { // Minus one because we're going to include self later + if (selectedMembers.count() >= groupSizeLimit) { // Minus one because we're going to include self later return Toast.makeText(this, R.string.activity_create_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show() } val userPublicKey = TextSecurePreferences.getLocalNumber(this)!! diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt index c3bc837b25..2a319c514f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt @@ -20,10 +20,10 @@ import nl.komponents.kovenant.task import nl.komponents.kovenant.ui.failUi import nl.komponents.kovenant.ui.successUi import org.session.libsession.messaging.sending_receiving.MessageSender +import org.session.libsession.messaging.sending_receiving.groupSizeLimit import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.session.libsession.messaging.threads.Address import org.thoughtcrime.securesms.database.DatabaseFactory -import org.thoughtcrime.securesms.groups.GroupManager import org.thoughtcrime.securesms.loki.dialogs.ClosedGroupEditingOptionsBottomSheet import org.thoughtcrime.securesms.loki.utilities.fadeIn import org.thoughtcrime.securesms.loki.utilities.fadeOut @@ -260,7 +260,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() { return Toast.makeText(this, R.string.activity_edit_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show() } - val maxGroupMembers = if (isClosedGroup) MessageSender.groupSizeLimit else legacyGroupSizeLimit + val maxGroupMembers = if (isClosedGroup) groupSizeLimit else legacyGroupSizeLimit if (members.size >= maxGroupMembers) { return Toast.makeText(this, R.string.activity_create_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show() } diff --git a/libsession/src/main/java/org/session/libsession/messaging/avatars/ContactColorsLegacy.java b/libsession/src/main/java/org/session/libsession/messaging/avatars/ContactColorsLegacy.java deleted file mode 100644 index b605c24fcb..0000000000 --- a/libsession/src/main/java/org/session/libsession/messaging/avatars/ContactColorsLegacy.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.session.libsession.messaging.avatars; - -import androidx.annotation.NonNull; - -import org.session.libsession.utilities.color.MaterialColor; - - -/** - * Used for migrating legacy colors to modern colors. For normal color generation, use - * {@link ContactColors}. - */ -public class ContactColorsLegacy { - - private static final String[] LEGACY_PALETTE = new String[] { - "red", - "pink", - "purple", - "deep_purple", - "indigo", - "blue", - "light_blue", - "cyan", - "teal", - "green", - "light_green", - "orange", - "deep_orange", - "amber", - "blue_grey" - }; - - public static MaterialColor generateFor(@NonNull String name) { - String serialized = LEGACY_PALETTE[Math.abs(name.hashCode()) % LEGACY_PALETTE.length]; - try { - return MaterialColor.fromSerialized(serialized); - } catch (MaterialColor.UnknownColorException e) { - return ContactColors.generateFor(name); - } - } -} diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 5fae947a38..d54fdc6f15 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -32,7 +32,6 @@ import org.session.libsignal.utilities.logging.Log object MessageSender { - const val groupSizeLimit = 100 // Error sealed class Error(val description: String) : Exception() { diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt index fc541aace8..5fbfc9a891 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt @@ -2,9 +2,7 @@ package org.session.libsession.messaging.sending_receiving -import android.content.Context import com.google.protobuf.ByteString -import com.google.protobuf.Message import nl.komponents.kovenant.Promise import nl.komponents.kovenant.deferred @@ -13,7 +11,6 @@ import org.session.libsession.messaging.messages.control.ClosedGroupControlMessa import org.session.libsession.messaging.sending_receiving.notifications.PushNotificationAPI import org.session.libsession.messaging.sending_receiving.MessageSender.Error import org.session.libsession.messaging.threads.Address -import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.utilities.Hex @@ -29,6 +26,7 @@ import org.session.libsignal.utilities.logging.Log import java.util.* import java.util.concurrent.ConcurrentHashMap +const val groupSizeLimit = 100 val pendingKeyPair = ConcurrentHashMap>() fun MessageSender.create(name: String, members: Collection): Promise { diff --git a/libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientFormattingException.java b/libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientFormattingException.java index 7a97811d9d..2bf8910f3c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientFormattingException.java +++ b/libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientFormattingException.java @@ -17,19 +17,7 @@ package org.session.libsession.messaging.threads.recipients; public class RecipientFormattingException extends Exception { - public RecipientFormattingException() { - super(); - } - public RecipientFormattingException(String message) { super(message); } - - public RecipientFormattingException(String message, Throwable nested) { - super(message, nested); - } - - public RecipientFormattingException(Throwable nested) { - super(nested); - } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientsFormatter.java b/libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientsFormatter.java deleted file mode 100644 index bdce30b69c..0000000000 --- a/libsession/src/main/java/org/session/libsession/messaging/threads/recipients/RecipientsFormatter.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2011 Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.session.libsession.messaging.threads.recipients; - -import android.telephony.PhoneNumberUtils; -import android.text.TextUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -public class RecipientsFormatter { - - private static String parseBracketedNumber(String recipient) throws RecipientFormattingException { - int begin = recipient.indexOf('<'); - int end = recipient.indexOf('>'); - String value = recipient.substring(begin + 1, end); - - if (PhoneNumberUtils.isWellFormedSmsAddress(value)) - return value; - else - throw new RecipientFormattingException("Bracketed value: " + value + " is not valid."); - } - - private static String parseRecipient(String recipient) throws RecipientFormattingException { - recipient = recipient.trim(); - - if ((recipient.indexOf('<') != -1) && (recipient.indexOf('>') != -1)) - return parseBracketedNumber(recipient); - - if (PhoneNumberUtils.isWellFormedSmsAddress(recipient)) - return recipient; - - throw new RecipientFormattingException("Recipient: " + recipient + " is badly formatted."); - } - - public static List getRecipients(String rawText) throws RecipientFormattingException { - ArrayList results = new ArrayList(); - StringTokenizer tokenizer = new StringTokenizer(rawText, ","); - - while (tokenizer.hasMoreTokens()) { - results.add(parseRecipient(tokenizer.nextToken())); - } - - return results; - } - - public static String formatNameAndNumber(String name, String number) { - // Format like this: Mike Cleron <(650) 555-1234> - // Erick Tseng <(650) 555-1212> - // Tutankhamun - // (408) 555-1289 - String formattedNumber = PhoneNumberUtils.formatNumber(number); - if (!TextUtils.isEmpty(name) && !name.equals(number)) { - return name + " <" + formattedNumber + ">"; - } else { - return formattedNumber; - } - } - - -} diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/UnidentifiedAccessUtil.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/UnidentifiedAccessUtil.kt deleted file mode 100644 index 31a9a0bc01..0000000000 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/UnidentifiedAccessUtil.kt +++ /dev/null @@ -1,63 +0,0 @@ -package org.session.libsession.messaging.utilities - -import android.content.Context -import com.goterl.lazycode.lazysodium.LazySodiumAndroid -import com.goterl.lazycode.lazysodium.SodiumAndroid -import org.session.libsession.messaging.MessagingConfiguration -import org.session.libsession.utilities.TextSecurePreferences.isUniversalUnidentifiedAccess -import org.session.libsession.utilities.Util.getSecretBytes -import org.session.libsignal.metadata.SignalProtos -import org.session.libsignal.service.api.crypto.UnidentifiedAccess -import org.session.libsignal.utilities.logging.Log - -object UnidentifiedAccessUtil { - private val TAG = UnidentifiedAccessUtil::class.simpleName - private val sodium by lazy { LazySodiumAndroid(SodiumAndroid()) } - - fun getAccessFor(recipientPublicKey: String): UnidentifiedAccess? { - val theirUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipientPublicKey) - val ourUnidentifiedAccessKey = getSelfUnidentifiedAccessKey() - val ourUnidentifiedAccessCertificate = getUnidentifiedAccessCertificate() - - Log.i(TAG, "Their access key present? " + (theirUnidentifiedAccessKey != null) + - " | Our access key present? " + (ourUnidentifiedAccessKey != null) + - " | Our certificate present? " + (ourUnidentifiedAccessCertificate != null)) - - return if (theirUnidentifiedAccessKey != null && ourUnidentifiedAccessKey != null && ourUnidentifiedAccessCertificate != null) { - UnidentifiedAccess(theirUnidentifiedAccessKey) - } else null - } - - fun getAccessForSync(context: Context): UnidentifiedAccess? { - var ourUnidentifiedAccessKey = getSelfUnidentifiedAccessKey() - val ourUnidentifiedAccessCertificate = getUnidentifiedAccessCertificate() - if (isUniversalUnidentifiedAccess(context)) { - ourUnidentifiedAccessKey = getSecretBytes(16) - } - return if (ourUnidentifiedAccessKey != null && ourUnidentifiedAccessCertificate != null) { - UnidentifiedAccess(ourUnidentifiedAccessKey) - } else null - } - - private fun getTargetUnidentifiedAccessKey(recipientPublicKey: String): ByteArray? { - val theirProfileKey = MessagingConfiguration.shared.storage.getProfileKeyForRecipient(recipientPublicKey) ?: return sodium.randomBytesBuf(16) - return UnidentifiedAccess.deriveAccessKeyFrom(theirProfileKey) - } - - private fun getSelfUnidentifiedAccessKey(): ByteArray? { - val userPublicKey = MessagingConfiguration.shared.storage.getUserPublicKey() - if (userPublicKey != null) { - return sodium.randomBytesBuf(16) - } - return null - } - - private fun getUnidentifiedAccessCertificate(): ByteArray? { - val userPublicKey = MessagingConfiguration.shared.storage.getUserPublicKey() - if (userPublicKey != null) { - val certificate = SignalProtos.SenderCertificate.newBuilder().setSender(userPublicKey).setSenderDevice(1).build() - return certificate.toByteArray() - } - return null - } -} \ No newline at end of file diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/InvalidCiphertextException.java b/libsignal/src/main/java/org/session/libsignal/service/api/crypto/InvalidCiphertextException.java deleted file mode 100644 index 717c76cece..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/InvalidCiphertextException.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.session.libsignal.service.api.crypto; - -public class InvalidCiphertextException extends Exception { - public InvalidCiphertextException(Exception nested) { - super(nested); - } - - public InvalidCiphertextException(String s) { - super(s); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/UnidentifiedAccess.java b/libsignal/src/main/java/org/session/libsignal/service/api/crypto/UnidentifiedAccess.java deleted file mode 100644 index 176621f657..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/UnidentifiedAccess.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.session.libsignal.service.api.crypto; - - -import org.session.libsignal.libsignal.util.ByteUtil; - -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.spec.GCMParameterSpec; -import javax.crypto.spec.SecretKeySpec; - -public class UnidentifiedAccess { - - private final byte[] unidentifiedAccessKey; - - public UnidentifiedAccess(byte[] unidentifiedAccessKey) - { - this.unidentifiedAccessKey = unidentifiedAccessKey; - } - - public byte[] getUnidentifiedAccessKey() { - return unidentifiedAccessKey; - } - - public static byte[] deriveAccessKeyFrom(byte[] profileKey) { - try { - byte[] nonce = new byte[12]; - byte[] input = new byte[16]; - - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); - cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(profileKey, "AES"), new GCMParameterSpec(128, nonce)); - - byte[] ciphertext = cipher.doFinal(input); - - return ByteUtil.trim(ciphertext, 16); - } catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchPaddingException | InvalidAlgorithmParameterException | BadPaddingException | IllegalBlockSizeException e) { - throw new AssertionError(e); - } - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/UntrustedIdentityException.java b/libsignal/src/main/java/org/session/libsignal/service/api/crypto/UntrustedIdentityException.java deleted file mode 100644 index 4e168c63ba..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/UntrustedIdentityException.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.crypto; - -import org.session.libsignal.libsignal.IdentityKey; - -public class UntrustedIdentityException extends Exception { - - private final IdentityKey identityKey; - private final String e164number; - - public UntrustedIdentityException(String s, String e164number, IdentityKey identityKey) { - super(s); - this.e164number = e164number; - this.identityKey = identityKey; - } - - public IdentityKey getIdentityKey() { - return identityKey; - } - - public String getE164Number() { - return e164number; - } - -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/messages/SendMessageResult.java b/libsignal/src/main/java/org/session/libsignal/service/api/messages/SendMessageResult.java deleted file mode 100644 index c273eef353..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/messages/SendMessageResult.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.session.libsignal.service.api.messages; - - -import org.session.libsignal.libsignal.IdentityKey; -import org.session.libsignal.service.api.push.SignalServiceAddress; -import org.session.libsignal.service.loki.api.SnodeAPI; - -public class SendMessageResult { - - private final SignalServiceAddress address; - private final Success success; - private final boolean networkFailure; - private final boolean unregisteredFailure; - private final IdentityFailure identityFailure; - private final SnodeAPI.Error lokiAPIError; - - public static SendMessageResult success(SignalServiceAddress address, boolean unidentified, boolean needsSync) { - return new SendMessageResult(address, new Success(unidentified, needsSync), false, false, null, null); - } - - public static SendMessageResult lokiAPIError(SignalServiceAddress address, SnodeAPI.Error lokiAPIError) { - return new SendMessageResult(address, null, false, false, null, lokiAPIError); - } - - public static SendMessageResult networkFailure(SignalServiceAddress address) { - return new SendMessageResult(address, null, true, false, null, null); - } - - public SignalServiceAddress getAddress() { - return address; - } - - public Success getSuccess() { - return success; - } - - public boolean isNetworkFailure() { - return networkFailure; - } - - public IdentityFailure getIdentityFailure() { - return identityFailure; - } - - public SnodeAPI.Error getLokiAPIError() { return lokiAPIError; } - - private SendMessageResult(SignalServiceAddress address, Success success, boolean networkFailure, boolean unregisteredFailure, IdentityFailure identityFailure, SnodeAPI.Error lokiAPIError) { - this.address = address; - this.success = success; - this.networkFailure = networkFailure; - this.unregisteredFailure = unregisteredFailure; - this.identityFailure = identityFailure; - this.lokiAPIError = lokiAPIError; - } - - public static class Success { - private final boolean unidentified; - private final boolean needsSync; - - private Success(boolean unidentified, boolean needsSync) { - this.unidentified = unidentified; - this.needsSync = needsSync; - } - - public boolean isUnidentified() { - return unidentified; - } - - public boolean isNeedsSync() { - return needsSync; - } - } - - public static class IdentityFailure { - private final IdentityKey identityKey; - - private IdentityFailure(IdentityKey identityKey) { - this.identityKey = identityKey; - } - - public IdentityKey getIdentityKey() { - return identityKey; - } - } - - - -}