credential

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package credential encrypts provider credential values at rest.

An encrypted value is self-describing:

enc:v1:<keyID>:<base64url(nonce || AES-256-GCM ciphertext)>

so protection is a property of each stored value, never of the config. Anything without the prefix is plaintext. The additional authenticated data is the provider ID and the credential's key joined by a zero byte, so a ciphertext copied into another provider, or under another key name, fails to decrypt instead of quietly becoming someone else's secret.

Index

Constants

View Source
const (
	ProtectionAESGCM    = "aes-256-gcm"
	ProtectionPlaintext = "plaintext"
)

Protection values reported per credential value.

View Source
const KeySize = 32

KeySize is the only key length accepted: AES-256.

Variables

View Source
var (
	// ErrKeyUnavailable means a value was encrypted under a key ID that isn't
	// configured, or no key is configured at all.
	ErrKeyUnavailable = errors.New("credential key is not configured")
	// ErrMalformed means a value has the encrypted prefix but can't be read.
	ErrMalformed = errors.New("credential value is malformed")
)

Functions

func Describe

func Describe(value string) (protection, keyID string)

Describe reports how one stored value is protected, and under which key. An absent marker means plaintext, never "unknown".

func IsEncrypted

func IsEncrypted(value string) bool

IsEncrypted reports whether a stored value carries the encrypted prefix.

func ParseKey

func ParseKey(encoded string) ([]byte, error)

ParseKey decodes a standard base64 key and checks its length.

Types

type Cipher

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

Cipher encrypts with its primary key and decrypts with any configured key. A nil *Cipher is valid: it passes plaintext through and refuses ciphertext.

func NewCipher

func NewCipher(primary Key, previous ...Key) (*Cipher, error)

NewCipher builds a Cipher that encrypts with primary and can also decrypt values written under any of previous.

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(providerID, name, value string) (string, error)

Decrypt opens a stored value. Plaintext passes through unchanged, so callers can decrypt a map without checking each value first.

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(providerID, name, plaintext string) (string, error)

Encrypt seals plaintext for one credential of one provider.

func (*Cipher) KeyID

func (c *Cipher) KeyID() string

KeyID is the ID of the key new values are encrypted under, or "" for a nil Cipher.

type Key

type Key struct {
	ID    string
	Bytes []byte
}

Key is one AES-256 key and the ID stored beside every value it encrypts.

Jump to

Keyboard shortcuts

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