internal

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillRandom

func FillRandom(buf []byte)

FillRandom takes a buffer and overwrites it with cryptographically-secure random bytes.

func GetRandBytes

func GetRandBytes(n int) []byte

GetRandBytes returns a slice of a specified length, filled with cryptographically-secure random bytes.

func IsKeyExpired added in v0.4.0

func IsKeyExpired(created int64, expireAfter time.Duration) bool

IsKeyExpired checks if the key's created timestamp is older than the allowed duration.

func IsKeyInvalid added in v0.4.0

func IsKeyInvalid(key Revokable, expireAfter time.Duration) bool

IsKeyInvalid checks if the key is revoked or expired.

func MemClr

func MemClr(buf []byte)

MemClr takes a buffer and wipes it with zeroes.

func WithKey

func WithKey(key BytesAccessor, action func([]byte) error) error

WithKey takes in BytesAccessor, e.g., a CryptoKey, makes the underlying bytes readable, and passes them to the function provided. A reference MUST not be stored to the provided bytes. The underlying array will be wiped after the function exits.

func WithKeyFunc

func WithKeyFunc(key BytesFuncAccessor, action func([]byte) ([]byte, error)) ([]byte, error)

WithKeyFunc takes in a BytesFuncAccessor, e.g., a CryptoKey, makes the underlying bytes readable, and passes them to the function provided. A reference MUST not be stored to the provided bytes. The underlying array will be wiped after the function exits.

Types

type BytesAccessor added in v0.4.0

type BytesAccessor interface {
	WithBytes(action func([]byte) error) error
}

type BytesFuncAccessor added in v0.4.0

type BytesFuncAccessor interface {
	WithBytesFunc(action func([]byte) ([]byte, error)) ([]byte, error)
}

type CryptoKey

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

CryptoKey represents an unencrypted key stored in a secure section in memory.

func GenerateKey

func GenerateKey(factory securememory.SecretFactory, created int64, size int) (*CryptoKey, error)

GenerateKey creates a new random CryptoKey.

func NewCryptoKey

func NewCryptoKey(factory securememory.SecretFactory, created int64, revoked bool, key []byte) (*CryptoKey, error)

NewCryptoKey creates a CryptoKey using the given key. Note that the underlying array will be wiped after the function exits.

func NewCryptoKeyForTest

func NewCryptoKeyForTest(created int64, revoked bool) *CryptoKey

NewCryptoKeyForTest creates a CryptoKey intended to be used for TEST only. TODO: explore refactoring dependent tests to eliminate the need for this function.

func (*CryptoKey) Close

func (k *CryptoKey) Close()

Close destroys the underlying buffer for this key.

func (*CryptoKey) Created

func (k *CryptoKey) Created() int64

Created returns the time the CryptoKey was created as a Unix epoch in seconds.

func (*CryptoKey) IsClosed

func (k *CryptoKey) IsClosed() bool

IsClosed returns true if the underlying buffer has been closed.

func (*CryptoKey) Revoked

func (k *CryptoKey) Revoked() bool

Revoked returns whether the CryptoKey has been marked as revoked or not.

func (*CryptoKey) SetRevoked

func (k *CryptoKey) SetRevoked(revoked bool)

SetRevoked atomically sets the revoked flag of the CryptoKey to the given value.

func (*CryptoKey) String added in v0.1.5

func (k *CryptoKey) String() string

func (*CryptoKey) WithBytes added in v0.4.0

func (k *CryptoKey) WithBytes(action func([]byte) error) error

WithBytes implements BytesAccessor.

func (*CryptoKey) WithBytesFunc added in v0.4.0

func (k *CryptoKey) WithBytesFunc(action func([]byte) ([]byte, error)) ([]byte, error)

WithBytesFunc implements BytesFuncAccessor.

type Revokable added in v0.4.0

type Revokable interface {
	// Revoked returns true if the key is revoked.
	Revoked() bool

	// Created returns the time the CryptoKey was created as a Unix epoch in seconds.
	Created() int64
}

Jump to

Keyboard shortcuts

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