crypto

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package crypto provides error constructors for encryption and key management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CiphertextTooShort

func CiphertextTooShort() error

CiphertextTooShort returns an error when ciphertext is shorter than the nonce size.

Returns:

  • error: "ciphertext too short"

func CreateCipher

func CreateCipher(cause error) error

CreateCipher wraps a failure to create an AES cipher.

Parameters:

  • cause: the underlying crypto error.

Returns:

  • error: "create cipher: <cause>"

func CreateGCM

func CreateGCM(cause error) error

CreateGCM wraps a failure to create a GCM instance.

Parameters:

  • cause: the underlying crypto error.

Returns:

  • error: "create GCM: <cause>"

func Decrypt

func Decrypt(cause error) error

Decrypt wraps a decryption failure with cause.

Parameters:

  • cause: the underlying decryption error.

Returns:

  • error: "decrypt: <cause>"

func DecryptFailed

func DecryptFailed() error

DecryptFailed returns an error indicating decryption failure.

Returns:

  • error: "decryption failed: wrong key?"

func EncryptFailed

func EncryptFailed(cause error) error

EncryptFailed wraps an encryption failure.

Parameters:

  • cause: the underlying error from crypto.Encrypt.

Returns:

  • error: "encrypt: <cause>"

func GenerateKey

func GenerateKey(cause error) error

GenerateKey wraps a failure to generate a random key.

Parameters:

  • cause: the underlying IO error.

Returns:

  • error: "generate key: <cause>"

func GenerateNonce

func GenerateNonce(cause error) error

GenerateNonce wraps a failure to generate a random nonce.

Parameters:

  • cause: the underlying IO error.

Returns:

  • error: "generate nonce: <cause>"

func InvalidKeySize

func InvalidKeySize(got, want int) error

InvalidKeySize returns an error when a key file has the wrong size.

Parameters:

  • got: actual key size in bytes.
  • want: expected key size in bytes.

Returns:

  • error: "invalid key size: got N bytes, want M"

func LoadKey

func LoadKey(cause error, keyPath string) error

LoadKey classifies a key-loading failure.

If the underlying error is os.ErrNotExist, returns NoKeyAt(keyPath). Otherwise wraps the cause as a generic load-key error.

Parameters:

  • cause: the underlying error from crypto.LoadKey
  • keyPath: the resolved key path that was checked

Returns:

  • error: NoKeyAt or "load key: <cause>"

func MkdirKeyDir

func MkdirKeyDir(cause error) error

MkdirKeyDir wraps a failure to create the key directory.

Parameters:

  • cause: the underlying OS error

Returns:

  • error: "failed to create key dir: <cause>"

func NoKeyAt

func NoKeyAt(path string) error

NoKeyAt returns an error indicating a missing encryption key.

Parameters:

  • path: the resolved key path that was checked.

Returns:

  • error: "encrypted scratchpad found but no key at <path>"

func ReadKey

func ReadKey(cause error) error

ReadKey wraps a failure to read a key file.

Parameters:

  • cause: the underlying read error.

Returns:

  • error: "read key: <cause>"

func SaveKey

func SaveKey(cause error) error

SaveKey wraps a failure to save an encryption key.

Parameters:

  • cause: the underlying error from key saving

Returns:

  • error: "failed to save scratchpad key: <cause>"

func WriteKey

func WriteKey(cause error) error

WriteKey wraps a failure to write a key file.

Parameters:

  • cause: the underlying write error.

Returns:

  • error: "write key: <cause>"

Types

This section is empty.

Jump to

Keyboard shortcuts

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