-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Share SecureRandom #1594
Share SecureRandom #1594
Conversation
@@ -248,32 +246,6 @@ object Util { | |||
return result | |||
} | |||
|
|||
fun getSecretBytes(size: Int): ByteArray { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice clean up!
Looking at the files there are a whole bunch more of seemingly unused functions. Might be worth removing those as well if they are truly unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed getRandomLengthBytes
because it creates a SecureRandom
and it's probably better to delete an unused function than maintain it. I didn't want to get too distracted deleting all unused functions in files touched.
@@ -458,12 +459,6 @@ public void setActive(String groupId, boolean active) { | |||
database.update(TABLE_NAME, values, GROUP_ID + " = ?", new String[] {groupId}); | |||
} | |||
|
|||
public byte[] allocateGroupId() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there are a few other unused functions in there, might be worth cleaning it while we're doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
public byte[] allocateGroupId() {
byte[] groupId = new byte[16];
new SecureRandom().nextBytes(groupId);
return groupId;
}
Every usage of
SecureRandom
created a new instance. This is inefficient. This PR adds a sharedSecureRandom
that is used throughout the app.Additionally this PR cleans up some other unused usages of
SecureRandom
, and adds extension functionsshuffledSecure
,randomSecure
andrandomSecureOrNull
which are all pretty obvious enough if you have a look.