mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 05:43:39 +00:00
Simplify access to SecureRandom
This shouldn't matter at all, but it's more "correct," and shows my age less.
This commit is contained in:
parent
8aa185070b
commit
a52c295a38
@ -879,10 +879,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleInviteLink() {
|
private void handleInviteLink() {
|
||||||
try {
|
|
||||||
String inviteText;
|
String inviteText;
|
||||||
|
|
||||||
boolean a = SecureRandom.getInstance("SHA1PRNG").nextBoolean();
|
boolean a = new SecureRandom().nextBoolean();
|
||||||
if (a) inviteText = getString(R.string.ConversationActivity_lets_switch_to_signal, "https://sgnl.link/1LoIMUl");
|
if (a) inviteText = getString(R.string.ConversationActivity_lets_switch_to_signal, "https://sgnl.link/1LoIMUl");
|
||||||
else inviteText = getString(R.string.ConversationActivity_lets_use_this_to_chat, "https://sgnl.link/1MF56H1");
|
else inviteText = getString(R.string.ConversationActivity_lets_use_this_to_chat, "https://sgnl.link/1MF56H1");
|
||||||
|
|
||||||
@ -895,9 +894,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
intent.putExtra(Intent.EXTRA_TEXT, inviteText);
|
intent.putExtra(Intent.EXTRA_TEXT, inviteText);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleResetSecureSession() {
|
private void handleResetSecureSession() {
|
||||||
|
@ -264,8 +264,8 @@ public class MasterSecretUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] generateSalt() throws NoSuchAlgorithmException {
|
private static byte[] generateSalt() {
|
||||||
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
SecureRandom random = new SecureRandom();
|
||||||
byte[] salt = new byte[16];
|
byte[] salt = new byte[16];
|
||||||
random.nextBytes(salt);
|
random.nextBytes(salt);
|
||||||
|
|
||||||
|
@ -308,13 +308,9 @@ public class GroupDatabase extends Database {
|
|||||||
|
|
||||||
|
|
||||||
public byte[] allocateGroupId() {
|
public byte[] allocateGroupId() {
|
||||||
try {
|
|
||||||
byte[] groupId = new byte[16];
|
byte[] groupId = new byte[16];
|
||||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(groupId);
|
new SecureRandom().nextBytes(groupId);
|
||||||
return groupId;
|
return groupId;
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Reader implements Closeable {
|
public static class Reader implements Closeable {
|
||||||
|
@ -71,7 +71,6 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
|||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -1279,13 +1278,9 @@ public class MmsDatabase extends MessagingDatabase {
|
|||||||
private final long threadId;
|
private final long threadId;
|
||||||
|
|
||||||
public OutgoingMessageReader(OutgoingMediaMessage message, long threadId) {
|
public OutgoingMessageReader(OutgoingMediaMessage message, long threadId) {
|
||||||
try {
|
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.id = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
this.id = new SecureRandom().nextLong();
|
||||||
this.threadId = threadId;
|
this.threadId = threadId;
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageRecord getCurrent() {
|
public MessageRecord getCurrent() {
|
||||||
|
@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -818,13 +817,9 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
private final long threadId;
|
private final long threadId;
|
||||||
|
|
||||||
public OutgoingMessageReader(OutgoingTextMessage message, long threadId) {
|
public OutgoingMessageReader(OutgoingTextMessage message, long threadId) {
|
||||||
try {
|
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.threadId = threadId;
|
this.threadId = threadId;
|
||||||
this.id = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
this.id = new SecureRandom().nextLong();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageRecord getCurrent() {
|
public MessageRecord getCurrent() {
|
||||||
|
@ -144,9 +144,8 @@ public abstract class Slide {
|
|||||||
boolean voiceNote,
|
boolean voiceNote,
|
||||||
boolean quote)
|
boolean quote)
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
String resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri)).or(defaultMime);
|
String resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri)).or(defaultMime);
|
||||||
String fastPreflightId = String.valueOf(SecureRandom.getInstance("SHA1PRNG").nextLong());
|
String fastPreflightId = String.valueOf(new SecureRandom().nextLong());
|
||||||
return new UriAttachment(uri,
|
return new UriAttachment(uri,
|
||||||
hasThumbnail ? uri : null,
|
hasThumbnail ? uri : null,
|
||||||
resolvedType,
|
resolvedType,
|
||||||
@ -159,9 +158,6 @@ public abstract class Slide {
|
|||||||
voiceNote,
|
voiceNote,
|
||||||
quote,
|
quote,
|
||||||
caption);
|
caption);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -415,10 +415,9 @@ public class WebRtcCallService extends Service implements InjectableType,
|
|||||||
|
|
||||||
if (callState != CallState.STATE_IDLE) throw new IllegalStateException("Dialing from non-idle?");
|
if (callState != CallState.STATE_IDLE) throw new IllegalStateException("Dialing from non-idle?");
|
||||||
|
|
||||||
try {
|
|
||||||
this.callState = CallState.STATE_DIALING;
|
this.callState = CallState.STATE_DIALING;
|
||||||
this.recipient = getRemoteRecipient(intent);
|
this.recipient = getRemoteRecipient(intent);
|
||||||
this.callId = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
this.callId = new SecureRandom().nextLong();
|
||||||
this.pendingOutgoingIceUpdates = new LinkedList<>();
|
this.pendingOutgoingIceUpdates = new LinkedList<>();
|
||||||
|
|
||||||
initializeVideo();
|
initializeVideo();
|
||||||
@ -478,9 +477,6 @@ public class WebRtcCallService extends Service implements InjectableType,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleResponseMessage(Intent intent) {
|
private void handleResponseMessage(Intent intent) {
|
||||||
|
@ -456,11 +456,7 @@ public class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getRandomElement(T[] elements) {
|
public static <T> T getRandomElement(T[] elements) {
|
||||||
try {
|
return elements[new SecureRandom().nextInt(elements.length)];
|
||||||
return elements[SecureRandom.getInstance("SHA1PRNG").nextInt(elements.length)];
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equals(@Nullable Object a, @Nullable Object b) {
|
public static boolean equals(@Nullable Object a, @Nullable Object b) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user