Switch from using Random to SecureRandom

This commit is contained in:
cketti 2023-05-05 16:35:30 +02:00
parent 338d7c25c0
commit 79078344c2
2 changed files with 5 additions and 5 deletions

View file

@ -1,9 +1,9 @@
package com.fsck.k9.mail
import java.util.Random
import java.security.SecureRandom
import org.jetbrains.annotations.VisibleForTesting
class BoundaryGenerator @VisibleForTesting internal constructor(private val random: Random) {
class BoundaryGenerator @VisibleForTesting internal constructor(private val random: SecureRandom) {
fun generateBoundary(): String {
return buildString(4 + BOUNDARY_CHARACTER_COUNT) {
@ -25,7 +25,7 @@ class BoundaryGenerator @VisibleForTesting internal constructor(private val rand
'U', 'V', 'W', 'X', 'Y', 'Z',
)
private val INSTANCE = BoundaryGenerator(Random())
private val INSTANCE = BoundaryGenerator(SecureRandom())
@JvmStatic
fun getInstance() = INSTANCE

View file

@ -2,7 +2,7 @@ package com.fsck.k9.mail
import assertk.assertThat
import assertk.assertions.isEqualTo
import java.util.Random
import java.security.SecureRandom
import org.junit.Test
import org.mockito.kotlin.mock
@ -29,7 +29,7 @@ class BoundaryGeneratorTest {
assertThat(result).isEqualTo("----0123456789ABCDEFGHIJKLMNOPQRSZ")
}
private fun createRandom(vararg values: Int): Random {
private fun createRandom(vararg values: Int): SecureRandom {
return mock {
var ongoingStubbing = on { nextInt(36) }
for (value in values) {