mirror of
https://github.com/golang/go
synced 2024-11-18 01:04:48 -07:00
crypto/rand, crypto/x509: add js/wasm architecture
This commit adds the js/wasm architecture to the crypto packages. Updates #18892 Change-Id: Id41a9d54920746d5019cbeedcff1b83874f2ef73 Reviewed-on: https://go-review.googlesource.com/110095 Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
7b83636800
commit
63756e0c8f
@ -15,6 +15,7 @@ import "io"
|
||||
// On OpenBSD, Reader uses getentropy(2).
|
||||
// On other Unix-like systems, Reader reads from /dev/urandom.
|
||||
// On Windows systems, Reader uses the CryptGenRandom API.
|
||||
// On Wasm, Reader uses the Web Crypto API.
|
||||
var Reader io.Reader
|
||||
|
||||
// Read is a helper function that calls Reader.Read using io.ReadFull.
|
||||
|
25
src/crypto/rand/rand_js.go
Normal file
25
src/crypto/rand/rand_js.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build js,wasm
|
||||
|
||||
package rand
|
||||
|
||||
import "syscall/js"
|
||||
|
||||
func init() {
|
||||
Reader = &reader{}
|
||||
}
|
||||
|
||||
var jsCrypto = js.Global.Get("crypto")
|
||||
|
||||
// reader implements a pseudorandom generator
|
||||
// using JavaScript crypto.getRandomValues method.
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues.
|
||||
type reader struct{}
|
||||
|
||||
func (r *reader) Read(b []byte) (int, error) {
|
||||
jsCrypto.Call("getRandomValues", b)
|
||||
return len(b), nil
|
||||
}
|
10
src/crypto/x509/root_js.go
Normal file
10
src/crypto/x509/root_js.go
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build js,wasm
|
||||
|
||||
package x509
|
||||
|
||||
// Possible certificate files; stop after finding one.
|
||||
var certFiles = []string{}
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build dragonfly freebsd linux nacl netbsd openbsd solaris
|
||||
// +build dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
|
||||
|
||||
package x509
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user