mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 02:43:38 +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() {
|
||||
try {
|
||||
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");
|
||||
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);
|
||||
startActivity(intent);
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleResetSecureSession() {
|
||||
|
@ -264,8 +264,8 @@ public class MasterSecretUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] generateSalt() throws NoSuchAlgorithmException {
|
||||
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
||||
private static byte[] generateSalt() {
|
||||
SecureRandom random = new SecureRandom();
|
||||
byte[] salt = new byte[16];
|
||||
random.nextBytes(salt);
|
||||
|
||||
|
@ -308,13 +308,9 @@ public class GroupDatabase extends Database {
|
||||
|
||||
|
||||
public byte[] allocateGroupId() {
|
||||
try {
|
||||
byte[] groupId = new byte[16];
|
||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(groupId);
|
||||
new SecureRandom().nextBytes(groupId);
|
||||
return groupId;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Reader implements Closeable {
|
||||
|
@ -71,7 +71,6 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -1279,13 +1278,9 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
private final long threadId;
|
||||
|
||||
public OutgoingMessageReader(OutgoingMediaMessage message, long threadId) {
|
||||
try {
|
||||
this.message = message;
|
||||
this.id = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
||||
this.id = new SecureRandom().nextLong();
|
||||
this.threadId = threadId;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public MessageRecord getCurrent() {
|
||||
|
@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -818,13 +817,9 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
private final long threadId;
|
||||
|
||||
public OutgoingMessageReader(OutgoingTextMessage message, long threadId) {
|
||||
try {
|
||||
this.message = message;
|
||||
this.threadId = threadId;
|
||||
this.id = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
this.id = new SecureRandom().nextLong();
|
||||
}
|
||||
|
||||
public MessageRecord getCurrent() {
|
||||
|
@ -144,9 +144,8 @@ public abstract class Slide {
|
||||
boolean voiceNote,
|
||||
boolean quote)
|
||||
{
|
||||
try {
|
||||
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,
|
||||
hasThumbnail ? uri : null,
|
||||
resolvedType,
|
||||
@ -159,9 +158,6 @@ public abstract class Slide {
|
||||
voiceNote,
|
||||
quote,
|
||||
caption);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -415,10 +415,9 @@ public class WebRtcCallService extends Service implements InjectableType,
|
||||
|
||||
if (callState != CallState.STATE_IDLE) throw new IllegalStateException("Dialing from non-idle?");
|
||||
|
||||
try {
|
||||
this.callState = CallState.STATE_DIALING;
|
||||
this.recipient = getRemoteRecipient(intent);
|
||||
this.callId = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
||||
this.callId = new SecureRandom().nextLong();
|
||||
this.pendingOutgoingIceUpdates = new LinkedList<>();
|
||||
|
||||
initializeVideo();
|
||||
@ -478,9 +477,6 @@ public class WebRtcCallService extends Service implements InjectableType,
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleResponseMessage(Intent intent) {
|
||||
|
@ -456,11 +456,7 @@ public class Util {
|
||||
}
|
||||
|
||||
public static <T> T getRandomElement(T[] elements) {
|
||||
try {
|
||||
return elements[SecureRandom.getInstance("SHA1PRNG").nextInt(elements.length)];
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return elements[new SecureRandom().nextInt(elements.length)];
|
||||
}
|
||||
|
||||
public static boolean equals(@Nullable Object a, @Nullable Object b) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user