This commit is contained in:
Ryan ZHAO 2021-02-01 10:25:19 +11:00
parent 190badd9c0
commit 9bc360f047
55 changed files with 53 additions and 270 deletions

View File

@ -8,7 +8,7 @@ import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.PartAuthority;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.Util;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;

View File

@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.crypto;
import androidx.annotation.NonNull;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import java.io.IOException;

View File

@ -25,7 +25,7 @@ import org.session.libsignal.libsignal.ecc.ECPrivateKey;
import org.thoughtcrime.securesms.logging.Log;
import org.session.libsession.utilities.Base64;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import java.io.IOException;
import java.security.GeneralSecurityException;

View File

@ -18,7 +18,7 @@
package org.thoughtcrime.securesms.crypto;
import org.thoughtcrime.securesms.logging.Log;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.Util;
import org.session.libsignal.libsignal.InvalidKeyException;
import org.session.libsignal.libsignal.ecc.Curve;

View File

@ -28,7 +28,7 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.MmsException;
import org.thoughtcrime.securesms.util.AttachmentUtil;
import org.session.libsession.utilities.Base64;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.Util;
import java.io.File;

View File

@ -14,7 +14,7 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.AttachmentStreamUriLoader.AttachmentModel;
import org.thoughtcrime.securesms.util.BitmapDecodingException;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.util.guava.Optional;
import org.session.libsignal.service.api.SignalServiceMessageReceiver;

View File

@ -39,7 +39,7 @@ import org.thoughtcrime.securesms.mms.PartAuthority;
import org.session.libsession.messaging.threads.recipients.Recipient;
import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException;
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.NumberUtil;
import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsession.utilities.Util;

View File

@ -97,7 +97,7 @@ import org.thoughtcrime.securesms.sms.IncomingTextMessage;
import org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage;
import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.loki.SessionResetProtocol;

View File

@ -30,7 +30,7 @@ import org.thoughtcrime.securesms.mms.PartAuthority;
import org.session.libsession.messaging.threads.recipients.Recipient;
import org.thoughtcrime.securesms.util.BitmapDecodingException;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsignal.libsignal.util.guava.Optional;
import org.session.libsignal.service.api.crypto.UnidentifiedAccessPair;

View File

@ -10,7 +10,7 @@ import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsignal.service.api.SignalServiceMessageReceiver;
import org.session.libsignal.service.api.push.exceptions.PushNetworkException;

View File

@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.service.api.SignalServiceMessageReceiver;
import org.session.libsignal.service.api.messages.SignalServiceStickerManifest;

View File

@ -19,7 +19,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.service.UpdateApkReadyListener;
import org.thoughtcrime.securesms.util.FileUtils;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.JsonUtils;
import org.session.libsession.utilities.TextSecurePreferences;

View File

@ -23,7 +23,7 @@ import org.thoughtcrime.securesms.net.RequestController;
import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.stickers.StickerRemoteUri;
import org.thoughtcrime.securesms.stickers.StickerUrl;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.util.Pair;

View File

@ -18,7 +18,7 @@ import org.thoughtcrime.securesms.loki.utilities.KeyPairUtilities
import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities
import org.thoughtcrime.securesms.loki.utilities.push
import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsignal.libsignal.util.KeyHelper
import org.session.libsignal.service.loki.crypto.MnemonicCodec

View File

@ -7,7 +7,7 @@ import com.goterl.lazycode.lazysodium.SodiumAndroid
import com.goterl.lazycode.lazysodium.interfaces.Box
import com.goterl.lazycode.lazysodium.interfaces.Sign
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.libsignal.ecc.ECKeyPair
import org.session.libsignal.service.loki.api.crypto.SessionProtocol

View File

@ -15,7 +15,7 @@ import org.session.libsignal.service.loki.protocol.shelved.multidevice.DeviceLin
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
import org.session.libsignal.service.loki.utilities.toHexString
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsession.utilities.TextSecurePreferences
import java.util.*

View File

@ -5,7 +5,7 @@ import android.content.Context
import org.thoughtcrime.securesms.database.Database
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
import org.thoughtcrime.securesms.loki.utilities.*
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupRatchet
import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupRatchetCollectionType
import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey

View File

@ -9,7 +9,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.jobs.BaseJob
import org.thoughtcrime.securesms.logging.Log
import org.thoughtcrime.securesms.loki.utilities.recipient
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.api.push.SignalServiceAddress
import org.session.libsignal.service.internal.push.SignalServiceProtos
import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey

View File

@ -21,7 +21,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.jobs.BaseJob
import org.thoughtcrime.securesms.logging.Log
import org.thoughtcrime.securesms.loki.utilities.recipient
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import java.util.*
import java.util.concurrent.TimeUnit

View File

@ -7,7 +7,7 @@ import org.thoughtcrime.securesms.loki.utilities.get
import org.thoughtcrime.securesms.loki.utilities.getAll
import org.thoughtcrime.securesms.loki.utilities.getString
import org.thoughtcrime.securesms.loki.utilities.insertOrUpdate
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.libsignal.ecc.DjbECPrivateKey
import org.session.libsignal.libsignal.ecc.DjbECPublicKey
import org.session.libsignal.libsignal.ecc.ECKeyPair

View File

@ -22,7 +22,7 @@ import org.thoughtcrime.securesms.loki.api.LokiPushNotificationManager.ClosedGro
import org.thoughtcrime.securesms.loki.utilities.recipient
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage
import org.thoughtcrime.securesms.sms.MessageSender
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import java.io.IOException
import java.util.*

View File

@ -24,7 +24,7 @@ import org.thoughtcrime.securesms.loki.api.SessionProtocolImpl
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage
import org.thoughtcrime.securesms.sms.IncomingGroupMessage
import org.thoughtcrime.securesms.sms.IncomingTextMessage
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsession.messaging.threads.Address
import org.session.libsession.messaging.threads.recipients.Recipient

View File

@ -7,7 +7,7 @@ import com.goterl.lazycode.lazysodium.utils.Key
import com.goterl.lazycode.lazysodium.utils.KeyPair
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
import org.session.libsession.utilities.Base64
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.libsignal.ecc.DjbECPrivateKey
import org.session.libsignal.libsignal.ecc.DjbECPublicKey
import org.session.libsignal.libsignal.ecc.ECKeyPair

View File

@ -18,7 +18,7 @@ import network.loki.messenger.R;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.util.FileProviderUtil;
import org.thoughtcrime.securesms.util.FileUtils;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.ServiceUtil;
import org.session.libsession.utilities.TextSecurePreferences;

View File

@ -14,7 +14,7 @@ import org.thoughtcrime.securesms.database.model.StickerPackRecord;
import org.thoughtcrime.securesms.database.model.StickerRecord;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.logging.Log;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.concurrent.SignalExecutors;
import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.util.guava.Optional;

View File

@ -7,7 +7,7 @@ import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.data.DataFetcher;
import org.thoughtcrime.securesms.logging.Log;
import org.session.libsession.utilities.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.service.api.SignalServiceMessageReceiver;

View File

@ -14,10 +14,8 @@ import org.session.libsession.utilities.createContext
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.util.Base64
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.internal.util.JsonUtil
import org.session.libsignal.service.loki.api.LokiDotNetAPI
import org.session.libsignal.service.loki.api.opengroups.PublicChatAPI
import org.session.libsignal.service.loki.utilities.DownloadUtilities
import org.session.libsignal.service.loki.utilities.retryIfNeeded
import java.io.ByteArrayOutputStream

View File

@ -3,7 +3,7 @@ package org.session.libsession.messaging.opengroups
import org.session.libsession.messaging.MessagingConfiguration
import org.session.libsession.messaging.messages.visible.VisibleMessage
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
import org.whispersystems.curve25519.Curve25519

View File

@ -19,7 +19,7 @@ import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel
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.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsession.utilities.SSKEnvironment
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsignal.libsignal.logging.Log

View File

@ -12,7 +12,7 @@ import org.session.libsession.messaging.sending_receiving.notifications.PushNoti
import org.session.libsession.messaging.sending_receiving.MessageSender.Error
import org.session.libsession.messaging.threads.Address
import org.session.libsession.utilities.GroupUtil
import org.session.libsession.utilities.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.libsignal.ecc.Curve
import org.session.libsignal.service.internal.push.SignalServiceProtos

View File

@ -10,8 +10,6 @@ import org.session.libsession.messaging.MessagingConfiguration
import org.session.libsession.snode.OnionRequestAPI
import org.session.libsession.snode.SnodeAPI
import org.session.libsession.messaging.fileserver.FileServerAPI
import org.session.libsession.messaging.sending_receiving.MessageReceiver
import org.session.libsession.messaging.sending_receiving.attachments.SessionServiceAttachment
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.libsignal.loki.DiffieHellman
@ -25,7 +23,7 @@ import org.session.libsignal.service.internal.push.PushAttachmentData
import org.session.libsignal.service.internal.push.http.DigestingRequestBody
import org.session.libsignal.service.internal.push.http.ProfileCipherOutputStreamFactory
import org.session.libsignal.service.internal.util.Base64
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.internal.util.JsonUtil
import org.session.libsignal.service.loki.api.utilities.HTTP
import org.session.libsignal.service.loki.utilities.*

View File

@ -3,6 +3,7 @@ package org.session.libsession.utilities
import org.whispersystems.curve25519.Curve25519
import org.session.libsignal.libsignal.util.ByteUtil
import org.session.libsignal.service.internal.util.Util
import org.session.libsignal.utilities.Hex
import javax.crypto.Cipher
import javax.crypto.Mac
import javax.crypto.spec.GCMParameterSpec

View File

@ -1,6 +1,7 @@
package org.session.libsession.utilities
import org.session.libsignal.service.api.messages.SignalServiceGroup
import org.session.libsignal.utilities.Hex
object GroupUtil {
const val CLOSED_GROUP_PREFIX = "__textsecure_group__!"

View File

@ -6,10 +6,9 @@
package org.session.libsignal.libsignal;
import org.session.libsignal.libsignal.InvalidKeyException;
import org.session.libsignal.libsignal.ecc.Curve;
import org.session.libsignal.libsignal.ecc.ECPublicKey;
import org.session.libsignal.libsignal.util.Hex;
import org.session.libsignal.utilities.Hex;
/**
* A class for representing an identity key.

View File

@ -1,7 +1,7 @@
package org.session.libsignal.libsignal.loki
import org.whispersystems.curve25519.Curve25519
import org.session.libsignal.libsignal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
/**

View File

@ -5,6 +5,8 @@
*/
package org.session.libsignal.libsignal.util;
import org.session.libsignal.utilities.Hex;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.ParseException;

View File

@ -1,66 +0,0 @@
/**
* Copyright (C) 2014-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/
package org.session.libsignal.libsignal.util;
import java.io.IOException;
/**
* Utility for generating hex dumps.
*/
public class Hex {
private final static char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
public static String toString(byte[] bytes) {
return toString(bytes, 0, bytes.length);
}
public static String toString(byte[] bytes, int offset, int length) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < length; i++) {
appendHexChar(buf, bytes[offset + i]);
buf.append(", ");
}
return buf.toString();
}
public static String toStringCondensed(byte[] bytes) {
StringBuffer buf = new StringBuffer();
for (int i=0;i<bytes.length;i++) {
appendHexChar(buf, bytes[i]);
}
return buf.toString();
}
public static byte[] fromStringCondensed(String encoded) throws IOException {
final char[] data = encoded.toCharArray();
final int len = data.length;
if ((len & 0x01) != 0) {
throw new IOException("Odd number of characters.");
}
final byte[] out = new byte[len >> 1];
for (int i = 0, j = 0; j < len; i++) {
int f = Character.digit(data[j], 16) << 4;
j++;
f = f | Character.digit(data[j], 16);
j++;
out[i] = (byte) (f & 0xFF);
}
return out;
}
private static void appendHexChar(StringBuffer buf, int b) {
buf.append(HEX_DIGITS[(b >> 4) & 0xf]);
buf.append(HEX_DIGITS[b & 0xf]);
}
}

View File

@ -31,7 +31,7 @@ import org.session.libsignal.libsignal.protocol.PreKeySignalMessage;
import org.session.libsignal.libsignal.protocol.SignalMessage;
import org.session.libsignal.libsignal.state.SignalProtocolStore;
import org.session.libsignal.libsignal.util.ByteUtil;
import org.session.libsignal.libsignal.util.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsignal.libsignal.util.Pair;
import java.io.IOException;

View File

@ -11,10 +11,9 @@ import com.google.protobuf.ByteString;
import org.session.libsignal.libsignal.InvalidVersionException;
import org.session.libsignal.libsignal.logging.Log;
import org.session.libsignal.service.api.push.SignalServiceAddress;
import org.session.libsignal.service.internal.push.SignalServiceProtos;
import org.session.libsignal.service.internal.push.SignalServiceProtos.Envelope;
import org.session.libsignal.service.internal.util.Base64;
import org.session.libsignal.service.internal.util.Hex;
import org.session.libsignal.utilities.Hex;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;

View File

@ -9,11 +9,10 @@ import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.format.DateTimeFormatter;
import org.session.libsignal.libsignal.util.ByteUtil;
import org.session.libsignal.service.api.crypto.InvalidCiphertextException;
import org.session.libsignal.service.internal.contacts.crypto.UnauthenticatedQuoteException;
import org.session.libsignal.service.internal.contacts.entities.DiscoveryRequest;
import org.session.libsignal.service.internal.contacts.entities.DiscoveryResponse;
import org.session.libsignal.service.internal.contacts.entities.RemoteAttestationResponse;
import org.session.libsignal.service.internal.util.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsignal.service.internal.util.JsonUtil;
import org.session.libsignal.service.internal.util.Util;

View File

@ -18,7 +18,7 @@ package org.session.libsignal.service.internal.contacts.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.session.libsignal.service.internal.util.Hex;
import org.session.libsignal.utilities.Hex;
public class DiscoveryRequest {

View File

@ -18,7 +18,7 @@ package org.session.libsignal.service.internal.contacts.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.session.libsignal.service.internal.util.Hex;
import org.session.libsignal.utilities.Hex;
public class DiscoveryResponse {

View File

@ -42,27 +42,13 @@ import org.session.libsignal.service.internal.contacts.entities.DiscoveryRequest
import org.session.libsignal.service.internal.contacts.entities.DiscoveryResponse;
import org.session.libsignal.service.internal.contacts.entities.RemoteAttestationRequest;
import org.session.libsignal.service.internal.contacts.entities.RemoteAttestationResponse;
import org.session.libsignal.service.internal.push.AttachmentUploadAttributes;
import org.session.libsignal.service.internal.push.ContactDiscoveryCredentials;
import org.session.libsignal.service.internal.push.ContactDiscoveryFailureReason;
import org.session.libsignal.service.internal.push.ContactTokenDetailsList;
import org.session.libsignal.service.internal.push.DeviceLimitExceededException;
import org.session.libsignal.service.internal.push.OutgoingPushMessageList;
import org.session.libsignal.service.internal.push.PreKeyResponseItem;
import org.session.libsignal.service.internal.push.ProfileAvatarUploadAttributes;
import org.session.libsignal.service.internal.push.ProvisioningMessage;
import org.session.libsignal.service.internal.push.PushAttachmentData;
import org.session.libsignal.service.internal.push.SendMessageResponse;
import org.session.libsignal.service.internal.push.SenderCertificate;
import org.session.libsignal.service.internal.push.SignalServiceEnvelopeEntity;
import org.session.libsignal.service.internal.push.SignalServiceEnvelopeEntityList;
import org.session.libsignal.service.internal.push.exceptions.MismatchedDevicesException;
import org.session.libsignal.service.internal.push.exceptions.StaleDevicesException;
import org.session.libsignal.service.internal.push.http.DigestingRequestBody;
import org.session.libsignal.service.internal.push.http.OutputStreamFactory;
import org.session.libsignal.service.internal.util.Base64;
import org.session.libsignal.service.internal.util.BlacklistingTrustManager;
import org.session.libsignal.service.internal.util.Hex;
import org.session.libsignal.utilities.Hex;
import org.session.libsignal.service.internal.util.JsonUtil;
import org.session.libsignal.service.internal.util.Util;

View File

@ -1,128 +0,0 @@
/**
* Copyright (C) 2014-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/
package org.session.libsignal.service.internal.util;
import java.io.IOException;
/**
* Utility for generating hex dumps.
*/
public class Hex {
private final static int HEX_DIGITS_START = 10;
private final static int ASCII_TEXT_START = HEX_DIGITS_START + (16*2 + (16/2));
final static String EOL = System.getProperty("line.separator");
private final static char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
public static String toString(byte[] bytes) {
return toString(bytes, 0, bytes.length);
}
public static String toString(byte[] bytes, int offset, int length) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < length; i++) {
appendHexChar(buf, bytes[offset + i]);
buf.append(' ');
}
return buf.toString();
}
public static String toStringCondensed(byte[] bytes) {
StringBuffer buf = new StringBuffer();
for (int i=0;i<bytes.length;i++) {
appendHexChar(buf, bytes[i]);
}
return buf.toString();
}
public static byte[] fromStringCondensed(String encoded) throws IOException {
final char[] data = encoded.toCharArray();
final int len = data.length;
if ((len & 0x01) != 0) {
throw new IOException("Odd number of characters.");
}
final byte[] out = new byte[len >> 1];
// two characters form the hex value.
for (int i = 0, j = 0; j < len; i++) {
int f = Character.digit(data[j], 16) << 4;
j++;
f = f | Character.digit(data[j], 16);
j++;
out[i] = (byte) (f & 0xFF);
}
return out;
}
public static String dump(byte[] bytes) {
return dump(bytes, 0, bytes.length);
}
public static String dump(byte[] bytes, int offset, int length) {
StringBuffer buf = new StringBuffer();
int lines = ((length - 1) / 16) + 1;
int lineOffset;
int lineLength;
for (int i = 0; i < lines; i++) {
lineOffset = (i * 16) + offset;
lineLength = Math.min(16, (length - (i * 16)));
appendDumpLine(buf, i, bytes, lineOffset, lineLength);
buf.append(EOL);
}
return buf.toString();
}
private static void appendDumpLine(StringBuffer buf, int line, byte[] bytes, int lineOffset, int lineLength) {
buf.append(HEX_DIGITS[(line >> 28) & 0xf]);
buf.append(HEX_DIGITS[(line >> 24) & 0xf]);
buf.append(HEX_DIGITS[(line >> 20) & 0xf]);
buf.append(HEX_DIGITS[(line >> 16) & 0xf]);
buf.append(HEX_DIGITS[(line >> 12) & 0xf]);
buf.append(HEX_DIGITS[(line >> 8) & 0xf]);
buf.append(HEX_DIGITS[(line >> 4) & 0xf]);
buf.append(HEX_DIGITS[(line ) & 0xf]);
buf.append(": ");
for (int i = 0; i < 16; i++) {
int idx = i + lineOffset;
if (i < lineLength) {
int b = bytes[idx];
appendHexChar(buf, b);
} else {
buf.append(" ");
}
if ((i % 2) == 1) {
buf.append(' ');
}
}
for (int i = 0; i < 16 && i < lineLength; i++) {
int idx = i + lineOffset;
int b = bytes[idx];
if (b >= 0x20 && b <= 0x7e) {
buf.append((char)b);
} else {
buf.append('.');
}
}
}
private static void appendHexChar(StringBuffer buf, int b) {
buf.append(HEX_DIGITS[(b >> 4) & 0xf]);
buf.append(HEX_DIGITS[b & 0xf]);
}
}

View File

@ -1,6 +1,5 @@
package org.session.libsignal.service.loki.api
import com.fasterxml.jackson.databind.JsonNode
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.functional.bind
import nl.komponents.kovenant.functional.map
@ -20,7 +19,7 @@ import org.session.libsignal.service.internal.push.PushAttachmentData
import org.session.libsignal.service.internal.push.http.DigestingRequestBody
import org.session.libsignal.service.internal.push.http.ProfileCipherOutputStreamFactory
import org.session.libsignal.service.internal.util.Base64
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.internal.util.JsonUtil
import org.session.libsignal.service.loki.api.fileserver.FileServerAPI
import org.session.libsignal.service.loki.api.onionrequests.OnionRequestAPI

View File

@ -1,14 +1,11 @@
package org.session.libsignal.service.loki.api.fileserver
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.functional.bind
import nl.komponents.kovenant.functional.map
import okhttp3.Request
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.libsignal.util.Hex
import org.session.libsignal.service.internal.util.Base64
import org.session.libsignal.service.internal.util.JsonUtil
import org.session.libsignal.service.loki.api.SnodeAPI
import org.session.libsignal.service.loki.api.LokiDotNetAPI
import org.session.libsignal.service.loki.api.onionrequests.OnionRequestAPI
import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol
@ -16,7 +13,6 @@ import org.session.libsignal.service.loki.protocol.shelved.multidevice.DeviceLin
import org.session.libsignal.service.loki.utilities.*
import java.net.URL
import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.set
class FileServerAPI(public val server: String, userPublicKey: String, userPrivateKey: ByteArray, private val database: LokiAPIDatabaseProtocol) : LokiDotNetAPI(userPublicKey, userPrivateKey, database) {

View File

@ -7,7 +7,7 @@ import nl.komponents.kovenant.functional.map
import nl.komponents.kovenant.then
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.util.Base64
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.internal.util.JsonUtil
import org.session.libsignal.service.loki.api.LokiDotNetAPI
import org.session.libsignal.service.loki.api.SnodeAPI

View File

@ -2,7 +2,7 @@ package org.session.libsignal.service.loki.api.opengroups
import org.whispersystems.curve25519.Curve25519
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
public data class PublicChatMessage(

View File

@ -2,7 +2,7 @@ package org.session.libsignal.service.loki.api.utilities
import org.whispersystems.curve25519.Curve25519
import org.session.libsignal.libsignal.util.ByteUtil
import org.session.libsignal.libsignal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.internal.util.Util
import javax.crypto.Cipher
import javax.crypto.Mac

View File

@ -2,8 +2,7 @@ package org.session.libsignal.service.loki.protocol.closedgroups
import com.google.protobuf.ByteString
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.libsignal.protocol.SignalProtos
import org.session.libsignal.libsignal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.internal.push.SignalServiceProtos
import org.session.libsignal.service.internal.util.JsonUtil
import org.session.libsignal.service.loki.utilities.toHexString

View File

@ -3,7 +3,7 @@ package org.session.libsignal.service.loki.protocol.closedgroups
import com.google.protobuf.ByteString
import org.whispersystems.curve25519.Curve25519
import org.session.libsignal.libsignal.loki.ClosedGroupCiphertextMessage
import org.session.libsignal.libsignal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.libsignal.util.Pair
import org.session.libsignal.service.api.messages.SignalServiceEnvelope
import org.session.libsignal.service.internal.push.SignalServiceProtos

View File

@ -5,7 +5,7 @@ import org.session.libsignal.libsignal.ecc.DjbECPublicKey
import org.session.libsignal.libsignal.ecc.ECKeyPair
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.libsignal.util.ByteUtil
import org.session.libsignal.libsignal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.internal.util.Util
import org.session.libsignal.service.loki.api.utilities.EncryptionUtilities
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded

View File

@ -3,7 +3,7 @@ package org.session.libsignal.service.loki.protocol.shelved.multidevice
import org.whispersystems.curve25519.Curve25519
import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.service.internal.util.Base64
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
import java.util.*

View File

@ -1,6 +1,6 @@
package org.session.libsignal.service.loki.utilities
import org.session.libsignal.service.internal.util.Hex
import org.session.libsignal.utilities.Hex
fun String.removing05PrefixIfNeeded(): String {
return if (length == 66) removePrefix("05") else this

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.session.libsession.utilities;
package org.session.libsignal.utilities;
import java.io.IOException;