gcpkmsrand

package module
v0.0.0-...-d019705 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

Google Cloud KMS Go io.Reader and rand.Source

GoDoc

This package provides a struct that implements Go's io.Reader and math/rand.Source interfaces, using Google Cloud KMS HSMs to generate entropy.

Usage

r, err := gcpkmsrand.NewReader("projects/my-project/locations/us-east1")
if err != nil {
  // handle error
}

// Directly
b := make([]byte, 32)
if _, err := r.Read(b); err != nil {
  // handle error
}

// Via the math package
rnd := rand.New(r)
rnd.Uint32()

Limitations

  • The maximum number of random bytes is 1024 at this time.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is the random reader.

func NewReader

func NewReader(location string) (*Reader, error)

NewReader creates a new random reader. It establishes a connection to Google Cloud KMS with the provided parameters. The location is specified as the "project/<project>/locations/<location>".

Example
package main

import (
	gcpkmsrand "github.com/sethvargo/gcpkms-rand"
)

func main() {
	r, err := gcpkmsrand.NewReader("projects/my-project/locations/us-east1")
	if err != nil {
		// handle error
	}
	_ = r
}
Output:

func (*Reader) Close

func (r *Reader) Close() error

Close closes the reader and the connection to upstream resources.

func (*Reader) Int63

func (r *Reader) Int63() int64

Int63 implements the Source interface.

func (*Reader) Read

func (r *Reader) Read(b []byte) (int, error)

Read implements the io.Reader interface to be used as a random generator.

func (*Reader) Seed

func (r *Reader) Seed(_ int64)

Seed is required for the Source interface, but seeding is not supported.

func (*Reader) Uint64

func (r *Reader) Uint64() uint64

Uint64 implements the Source64 interface.

Jump to

Keyboard shortcuts

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