Skip to content

Commit

Permalink
Merge pull request #669 from scala-js/issue/668
Browse files Browse the repository at this point in the history
Fix `dom.crypto.getRandomValues`
  • Loading branch information
armanbilge authored Jan 19, 2022
2 parents a839087 + 4cc7429 commit c6f81f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25514,7 +25514,7 @@ crypto/package[SO] @deprecated("use dom.RsaKeyGenParams instead", "2.0.0") val R
crypto/package[SO] @deprecated("use dom.RsaOaepParams instead", "2.0.0") val RsaOaepParams = dom.RsaOaepParams
crypto/package[SO] @deprecated("use dom.RsaPssParams instead", "2.0.0") val RsaPssParams = dom.RsaPssParams
crypto/package[SO] def crypto: Crypto (@deprecated in 2.0.0)
crypto/package[SO] @JSGlobal("crypto.getRandomValues") @js.native def getRandomValues(array: ArrayBufferView): ArrayBufferView
crypto/package[SO] def getRandomValues(array: ArrayBufferView)(implicit dummy: DummyImplicit): ArrayBufferView
crypto/package[SO] @JSGlobal("crypto.subtle") @js.native val subtle: dom.SubtleCrypto
experimental/Fullscreen[SO] (@deprecated in 2.0.0)
experimental/PointerLock[SO] type PointerLockDocument = dom.Document (@deprecated in 2.0.0)
Expand Down
2 changes: 1 addition & 1 deletion api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25514,7 +25514,7 @@ crypto/package[SO] @deprecated("use dom.RsaKeyGenParams instead", "2.0.0") val R
crypto/package[SO] @deprecated("use dom.RsaOaepParams instead", "2.0.0") val RsaOaepParams = dom.RsaOaepParams
crypto/package[SO] @deprecated("use dom.RsaPssParams instead", "2.0.0") val RsaPssParams = dom.RsaPssParams
crypto/package[SO] def crypto: Crypto (@deprecated in 2.0.0)
crypto/package[SO] @JSGlobal("crypto.getRandomValues") @js.native def getRandomValues(array: ArrayBufferView): ArrayBufferView
crypto/package[SO] def getRandomValues(array: ArrayBufferView)(implicit dummy: DummyImplicit): ArrayBufferView
crypto/package[SO] @JSGlobal("crypto.subtle") @js.native val subtle: dom.SubtleCrypto
experimental/Fullscreen[SO] (@deprecated in 2.0.0)
experimental/PointerLock[SO] type PointerLockDocument = dom.Document (@deprecated in 2.0.0)
Expand Down
8 changes: 6 additions & 2 deletions dom/src/main/scala/org/scalajs/dom/crypto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ package object crypto {
@js.native
val subtle: dom.SubtleCrypto = js.native

/** Fills the passed TypedArray with cryptographically sound random values. */
// for binary compat; unusable
@JSGlobal("crypto.getRandomValues")
@js.native
def getRandomValues(array: ArrayBufferView): ArrayBufferView = js.native
protected[crypto] def getRandomValues(array: ArrayBufferView): ArrayBufferView = js.native

/** Fills the passed TypedArray with cryptographically sound random values. */
@inline def getRandomValues(array: ArrayBufferView)(implicit dummy: DummyImplicit): ArrayBufferView =
webcrypto.getRandomValues(array)

@deprecated("use dom.crypto instead", "2.0.0")
@inline def crypto: Crypto = GlobalCrypto.crypto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import scala.scalajs.js.typedarray._

trait WebCryptoApiTests {

// https://github.com/scala-js/scala-js-dom/issues/668
@Test final def cryptoGetRandomValues(): Unit =
dom.crypto.getRandomValues(new Uint8Array(1))

@Test final def getRandomValuesWork: Unit = {
dom.webcrypto.getRandomValues(Array.ofDim[Byte](8).toTypedArray)
}
Expand Down

0 comments on commit c6f81f4

Please sign in to comment.