util

package
v0.0.0-...-0ca8a0b Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package util contains utility code common to the cryptutils programs.

Index

Constants

View Source
const NonceSize = 24

NonceSize contains the size, in bytes, of a NaCl nonce.

Variables

A PassPrompt is a function that takes a string to display to the user, and returns a byte slice containing the user's input if no error occurred.

View Source
var Version = struct {
	Major int
	Minor int
	Patch int
	Label string
}{1, 1, 0, ""}

Version contains the current version of the cryptutils system. See semver.org for a description of this format.

Functions

func Errorf

func Errorf(m string, args ...interface{})

Errorf is a convenience function for printing errors and warnings in the standard format used by this project.

func Exists

func Exists(path string) (bool, bool)

Exists is a convenience function that returns a pair of booleans indicating whether a file exists or whether an error occurred checking the file.

func NewNonce

func NewNonce() *[NonceSize]byte

NewNonce generates a new random nonce for use with NaCl. This is a 192-bit random number. In this set of utilities, only one nonce is ever actually used with a key in most cases.

func PRNG

func PRNG() io.Reader

PRNG returns the current PRNG being used by the package.

func RandBytes

func RandBytes(size int) []byte

RandBytes is a wrapper for retrieving a buffer of the requested size, filled with random data. On failure, it returns nil.

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile is a convenience function that transparently handles reading from a file or standard input as necessary.

func ReadLine

func ReadLine(prompt string) (line string, err error)

ReadLine reads a line of input from the user.

func SetPRNG

func SetPRNG(r io.Reader)

SetPRNG is used to change the PRNG. This should only be used in testing to validate PRNG failures. If nil is passed as the reader, crypto/rand.Reader will be used.

func VersionString

func VersionString() string

VersionString returns a formatted semver structure from Version.

func WriteFile

func WriteFile(data []byte, path string) error

WriteFile is a convenience function that transparently handles writing to a file or stdout as necessary.

func Zero

func Zero(in []byte)

Zero wipes out a byte slice. This isn't a bulletproof option, as there are many other factors outside the control of the program that come into play. For example, if memory is swapped out, or if the machine is put to sleep, the program has no control over what happens to its memory. In order to combat this, we try to wipe memory as soon as it is no longer used. In some cases, this will be done with deferred statements to ensure it's done; in other cases it will make sense to do it right after the secret is used.

Types

This section is empty.

Jump to

Keyboard shortcuts

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