luci: Index | Files

package cryptorand

import ""

Package cryptorand implements a mockable source or crypto strong randomness.

In real world scenario it is same source as provided by crypt/rand. In tests it is replaced with reproducible, not really random stream of bytes.


Package Files


func Get Uses

func Get(c context.Context) io.Reader

Get returns an io.Reader that emits random stream of bytes.

Usually this returns crypto/rand.Reader, but unit tests may replace it with a mock by using 'MockForTest' function.

func MockForTest Uses

func MockForTest(c context.Context, seed int64) context.Context

MockForTest installs deterministic source of 'randomness' in the context.

Must not be used outside of tests.

func Read Uses

func Read(c context.Context, b []byte) (n int, err error)

Read is a helper that reads bytes from random source using io.ReadFull.

On return, n == len(b) if and only if err == nil.

Package cryptorand imports 5 packages (graph) and is imported by 25 packages. Updated 2020-12-06. Refresh now. Tools for package owners.