Documentation ¶
Overview ¶
Package util contains utility code common to the cryptutils programs.
Index ¶
- Constants
- Variables
- func Errorf(m string, args ...interface{})
- func Exists(path string) (bool, bool)
- func NewNonce() *[NonceSize]byte
- func PRNG() io.Reader
- func RandBytes(size int) []byte
- func ReadFile(path string) ([]byte, error)
- func ReadLine(prompt string) (line string, err error)
- func SetPRNG(r io.Reader)
- func VersionString() string
- func WriteFile(data []byte, path string) error
- func Zero(in []byte)
Constants ¶
const NonceSize = 24
NonceSize contains the size, in bytes, of a NaCl nonce.
Variables ¶
var PassPrompt = readpass.PasswordPromptBytes
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.
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 ¶
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 ¶
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 RandBytes ¶
RandBytes is a wrapper for retrieving a buffer of the requested size, filled with random data. On failure, it returns nil.
func ReadFile ¶
ReadFile is a convenience function that transparently handles reading from a file or standard input as necessary.
func SetPRNG ¶
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 ¶
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.