Skip to content

Commit a557126

Browse files
authored
Remove scalajs-fake-insecure-java-securerandom dependency (#465)
* Remove fake insecure random dependency * Re-implement randomUUID() on Scala.js
1 parent 1d404ca commit a557126

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

build.sbt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@ lazy val runtime = CrossProject(
119119
.jvmSettings(
120120
Test / fork := true
121121
)
122-
.jsSettings(
123-
scalaJSStage := FastOptStage,
124-
// While not exactlu ideal, this is only used in the invoker to assign a
125-
// unique id to ensure measurements have unique ids. It's never exposed to
126-
// the user and doesn't touch anything sensitve, so we should have no
127-
// issues here. Still, I don't like having this, so we should try to
128-
// replace it.
129-
libraryDependencies += ("org.scala-js" %%% "scalajs-fake-insecure-java-securerandom" % "1.0.0")
130-
.cross(CrossVersion.for3Use2_13)
131-
)
132122

133123
lazy val `runtimeJVM` = runtime.jvm
134124
lazy val `runtimeJS` = runtime.js

runtime/js/src/main/scala/scoverage/Platform.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,15 @@ object Platform {
1717

1818
lazy val Source = SupportSource
1919

20+
def insecureRandomUUID() = {
21+
import scala.util.Random
22+
var msb = Random.nextLong()
23+
var lsb = Random.nextLong()
24+
msb &= 0xffffffffffff0fffL // clear version
25+
msb |= 0x0000000000004000L // set to version 4
26+
lsb &= 0x3fffffffffffffffL // clear variant
27+
lsb |= 0x8000000000000000L // set to IETF variant
28+
new java.util.UUID(msb, lsb)
29+
}
30+
2031
}

runtime/jvm/src/main/scala/scoverage/Platform.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ object Platform {
1616
type FileFilter = SupportFileFilter
1717

1818
lazy val Source = SupportSource
19+
20+
def insecureRandomUUID() = java.util.UUID.randomUUID()
21+
1922
}

runtime/shared/src/main/scala/scoverage/Invoker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scoverage.Platform._
88
/** @author Stephen Samuel */
99
object Invoker {
1010

11-
private val runtimeUUID = java.util.UUID.randomUUID()
11+
private val runtimeUUID = Platform.insecureRandomUUID()
1212

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

0 commit comments

Comments
 (0)