Skip to content

Commit

Permalink
Remove reference to java.security.SecureRandom from ULID.scala.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturaz committed Sep 4, 2024
1 parent 50c9a49 commit c714c58
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions js/src/main/scala/jkugiya/ulid/SecureGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import java.util.{Random => JRandom}
private[ulid] object SecureGenerator {
// Secure generation isn't widely available on JS.
def get: JRandom = new JRandom()

def algorithm(random: JRandom): String = random.getClass.toString
}

5 changes: 5 additions & 0 deletions jvm/src/main/scala/jkugiya/ulid/SecureGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ private[ulid] object SecureGenerator {
.recover({ case _ => new JRandom() })
.get
}

def algorithm(random: JRandom): String = random match {
case sr: SecureRandom => sr.getAlgorithm
case _ => random.getClass.toString
}
}
2 changes: 2 additions & 0 deletions native/src/main/scala/jkugiya/ulid/SecureGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import java.util.{Random => JRandom}
private[ulid] object SecureGenerator {
// Secure generation isn't available on native.
def get: JRandom = new JRandom()

def algorithm(random: JRandom): String = random.getClass.toString
}

7 changes: 1 addition & 6 deletions shared/src/main/scala/jkugiya/ulid/ULID.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jkugiya.ulid
import jkugiya.ulid.ULID._

import java.nio.ByteBuffer
import java.security.SecureRandom
import java.util.{UUID, Random => JRandom}
import scala.util.Try

Expand All @@ -23,11 +22,7 @@ object ULID {
override final def generate(): ULID =
new ULID(System.currentTimeMillis(), random)

override final def algorithm(): String = random match {
case sr: SecureRandom => sr.getAlgorithm
case _ => random.getClass.toString
}

override final def algorithm(): String = SecureGenerator.algorithm(random)
}

def getGenerator(random: JRandom = SecureGenerator.get): ULIDGenerator =
Expand Down

0 comments on commit c714c58

Please sign in to comment.