diff --git a/js/src/main/scala/jkugiya/ulid/SecureGenerator.scala b/js/src/main/scala/jkugiya/ulid/SecureGenerator.scala index 22c5154..8986ef8 100644 --- a/js/src/main/scala/jkugiya/ulid/SecureGenerator.scala +++ b/js/src/main/scala/jkugiya/ulid/SecureGenerator.scala @@ -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 } diff --git a/jvm/src/main/scala/jkugiya/ulid/SecureGenerator.scala b/jvm/src/main/scala/jkugiya/ulid/SecureGenerator.scala index 25f3d80..2a8e7f2 100644 --- a/jvm/src/main/scala/jkugiya/ulid/SecureGenerator.scala +++ b/jvm/src/main/scala/jkugiya/ulid/SecureGenerator.scala @@ -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 + } } diff --git a/native/src/main/scala/jkugiya/ulid/SecureGenerator.scala b/native/src/main/scala/jkugiya/ulid/SecureGenerator.scala index 453fa73..72b0d54 100644 --- a/native/src/main/scala/jkugiya/ulid/SecureGenerator.scala +++ b/native/src/main/scala/jkugiya/ulid/SecureGenerator.scala @@ -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 } diff --git a/shared/src/main/scala/jkugiya/ulid/ULID.scala b/shared/src/main/scala/jkugiya/ulid/ULID.scala index b680292..ecc0472 100644 --- a/shared/src/main/scala/jkugiya/ulid/ULID.scala +++ b/shared/src/main/scala/jkugiya/ulid/ULID.scala @@ -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 @@ -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 =