cryptorand

package
v0.0.0-...-ecc550e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 31

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(ctx 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

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

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

Must not be used outside of tests.

func Read

func Read(ctx 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL