Documentation
¶
Overview ¶
Package age is a pure-Go (no cgo) reimplementation of Ruby's age gem — the binding for the age file-encryption format (https://age-encryption.org).
It mirrors the gem's public surface: the Age.encrypt / Age.decrypt one-shots, the Age::X25519 and Age::Scrypt recipient/identity types, ASCII armor, the streaming Age::Encryptor / Age::Decryptor IO wrappers and the Age::Error exception tree. The format and cryptography are provided by filippo.io/age, the reference age implementation written by age's author, so files produced here are read by the reference age CLI and vice-versa — without any Ruby runtime.
Quick start ¶
id, _ := x25519.Generate()
ct, _ := age.Encrypt([]byte("hello"), []age.Recipient{id.ToPublic()})
pt, _ := age.Decrypt(ct, []age.Identity{id})
string(pt) // "hello"
The age format and its ChaCha20-Poly1305 / X25519 / scrypt primitives are endian-independent, so the package is byte-identical on every supported architecture, big- or little-endian.
Index ¶
Constants ¶
const Version = "0.1.0"
Version is the version of this Go port. It is independent of the upstream Ruby age gem's version.
Variables ¶
var ( // Err is the base sentinel every other error in the package wraps, mirroring // the gem's Age::Error base class. Err = errors.New("age") // ErrNoIdentityMatch is returned by Decrypt when none of the supplied // identities could unwrap the file key, mirroring the gem's // Age::NoMatchingKeys (age's NoIdentityMatchError). ErrNoIdentityMatch = fmt.Errorf("%w: no identity matched any recipient stanza", Err) // ErrIncorrectPassphrase is returned by Decrypt when a passphrase-encrypted // (scrypt) file is decrypted with the wrong passphrase. ErrIncorrectPassphrase = fmt.Errorf("%w: incorrect passphrase", Err) // ErrParse is returned when a key string, recipient or passphrase cannot be // parsed, mirroring the gem's parse/format errors. ErrParse = fmt.Errorf("%w: parse error", Err) // ErrFormat is returned when a ciphertext is malformed, truncated or has been // tampered with (authentication failure), mirroring the gem's decrypt error. ErrFormat = fmt.Errorf("%w: malformed or corrupt ciphertext", Err) // ErrEncrypt is returned when encryption cannot proceed, for example when no // recipients are given or an scrypt recipient is combined with another // recipient (age requires an scrypt recipient to be the only one). ErrEncrypt = fmt.Errorf("%w: encryption failed", Err) )
The package's sentinel errors mirror the exception hierarchy of the Ruby age gem, whose classes descend from Age::Error. Every error returned by the package wraps Err, so a caller can match the whole family with errors.Is(err, age.Err) — the Go equivalent of "rescue Age::Error" — or match a specific member for finer control.
Functions ¶
func Decrypt ¶
Decrypt decrypts an age message (binary or ASCII-armored — the framing is detected automatically) using the given identities and returns the plaintext, mirroring the gem's Age.decrypt(ciphertext, identities:). It returns ErrNoIdentityMatch when no identity matches, ErrIncorrectPassphrase for a wrong scrypt passphrase and ErrFormat when the message is corrupt or has been tampered with.
Types ¶
type Decryptor ¶
type Decryptor struct {
// contains filtered or unexported fields
}
Decryptor streams decryption from an underlying io.Reader, mirroring the gem's Age::Decryptor. Binary and ASCII-armored input are detected automatically. It implements io.Reader.
func NewDecryptor ¶
NewDecryptor begins decrypting the age message read from src with the given identities, mirroring Age::Decryptor.new. It fails immediately with ErrNoIdentityMatch / ErrIncorrectPassphrase when the header cannot be unwrapped, or ErrFormat when the header is malformed.
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
Encryptor streams encryption to an underlying io.Writer, mirroring the gem's Age::Encryptor. Write encrypted chunks with Write and finish the message with Close (which flushes the final chunk and, when armored, the trailing footer); Close must be called for the output to be valid. It implements io.WriteCloser.
func NewEncryptor ¶
NewEncryptor starts an age message on dst encrypted to the given recipients, mirroring Age::Encryptor.new. With WithArmor the message is ASCII-armored.
type Identity ¶
Identity is a key that can decrypt a message (an age identity). The X25519 and scrypt identity types satisfy it, mirroring the objects passed to the gem's Age.decrypt(identities:) keyword.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package scrypt mirrors the gem's Age::Scrypt namespace: passphrase-based age recipients and identities.
|
Package scrypt mirrors the gem's Age::Scrypt namespace: passphrase-based age recipients and identities. |
|
Package x25519 mirrors the gem's Age::X25519 namespace: native age X25519 key-pair recipients and identities, whose string forms are the familiar "age1…" recipients and "AGE-SECRET-KEY-1…" identities.
|
Package x25519 mirrors the gem's Age::X25519 namespace: native age X25519 key-pair recipients and identities, whose string forms are the familiar "age1…" recipients and "AGE-SECRET-KEY-1…" identities. |
