Skip to content

Commit

Permalink
Remove scalajs-fake-insecure-java-securerandom dependency (#465)
Browse files Browse the repository at this point in the history
* Remove fake insecure random dependency

* Re-implement randomUUID() on Scala.js
  • Loading branch information
armanbilge authored May 31, 2022
1 parent 1d404ca commit a557126
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 0 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,6 @@ lazy val runtime = CrossProject(
.jvmSettings(
Test / fork := true
)
.jsSettings(
scalaJSStage := FastOptStage,
// While not exactlu ideal, this is only used in the invoker to assign a
// unique id to ensure measurements have unique ids. It's never exposed to
// the user and doesn't touch anything sensitve, so we should have no
// issues here. Still, I don't like having this, so we should try to
// replace it.
libraryDependencies += ("org.scala-js" %%% "scalajs-fake-insecure-java-securerandom" % "1.0.0")
.cross(CrossVersion.for3Use2_13)
)

lazy val `runtimeJVM` = runtime.jvm
lazy val `runtimeJS` = runtime.js
Expand Down
11 changes: 11 additions & 0 deletions runtime/js/src/main/scala/scoverage/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ object Platform {

lazy val Source = SupportSource

def insecureRandomUUID() = {
import scala.util.Random
var msb = Random.nextLong()
var lsb = Random.nextLong()
msb &= 0xffffffffffff0fffL // clear version
msb |= 0x0000000000004000L // set to version 4
lsb &= 0x3fffffffffffffffL // clear variant
lsb |= 0x8000000000000000L // set to IETF variant
new java.util.UUID(msb, lsb)
}

}
3 changes: 3 additions & 0 deletions runtime/jvm/src/main/scala/scoverage/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ object Platform {
type FileFilter = SupportFileFilter

lazy val Source = SupportSource

def insecureRandomUUID() = java.util.UUID.randomUUID()

}
2 changes: 1 addition & 1 deletion runtime/shared/src/main/scala/scoverage/Invoker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scoverage.Platform._
/** @author Stephen Samuel */
object Invoker {

private val runtimeUUID = java.util.UUID.randomUUID()
private val runtimeUUID = Platform.insecureRandomUUID()

private val MeasurementsPrefix = "scoverage.measurements."
private val threadFiles = new ThreadLocal[mutable.HashMap[String, FileWriter]]
Expand Down

0 comments on commit a557126

Please sign in to comment.