Documentation
¶
Overview ¶
Package msgcrypto provides the small, reusable encryption primitive used by h8s services. It intentionally knows nothing about NATS subjects, HTTP headers, or proxy policy.
The wire format is NATS nkeys' curve format: "xkv1" || 24-byte random nonce || NaCl box ciphertext. nkeys.Seal generates a fresh nonce for every call and nkeys.Open validates the version, nonce, sender public key, and Poly1305 tag.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidRecipient is returned when a public key is missing or not a // valid nkeys curve public key. ErrInvalidRecipient = errors.New("msgcrypto: invalid recipient curve public key") // ErrInvalidSender is returned when a sender public key is missing or not // a valid nkeys curve public key. ErrInvalidSender = errors.New("msgcrypto: invalid sender curve public key") // ErrDecrypt is returned when a sealed message cannot be opened. ErrDecrypt = errors.New("msgcrypto: unable to decrypt message") )
Functions ¶
func ReadSeedFile ¶
ReadSeedFile reads and trims an encoded curve seed. It rejects empty files and files with group/world permission bits.
Types ¶
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key is a curve keypair. It is safe for concurrent Seal and Open calls; Wipe must only be called after all users have stopped.
func FromSeed ¶
FromSeed creates a keypair from an encoded curve seed (the "SX..." form returned by nkeys.KeyPair.Seed).
func FromSeedFile ¶
FromSeedFile loads an encoded curve seed from path. The file must not be group- or world-readable.
func (*Key) Open ¶
Open decrypts data from sender. The sender must be a valid "X..." curve public key. A truncated, tampered, or wrong-sender message returns ErrDecrypt.