Skip to content

Commit 0447d8d

Browse files
committed
age: add links to docs
1 parent 3d91014 commit 0447d8d

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

age.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// Package age implements file encryption according to the age-encryption.org/v1
66
// specification.
77
//
8-
// For most use cases, use the Encrypt and Decrypt functions with
9-
// X25519Recipient and X25519Identity. If passphrase encryption is required, use
10-
// ScryptRecipient and ScryptIdentity. For compatibility with existing SSH keys
8+
// For most use cases, use the [Encrypt] and [Decrypt] functions with
9+
// [X25519Recipient] and [X25519Identity]. If passphrase encryption is required, use
10+
// [ScryptRecipient] and [ScryptIdentity]. For compatibility with existing SSH keys
1111
// use the filippo.io/age/agessh package.
1212
//
1313
// age encrypted files are binary and not malleable. For encoding them as text,
@@ -57,36 +57,34 @@ import (
5757
"filippo.io/age/internal/stream"
5858
)
5959

60-
// An Identity is passed to Decrypt to unwrap an opaque file key from a
61-
// recipient stanza. It can be for example a secret key like X25519Identity, a
60+
// An Identity is passed to [Decrypt] to unwrap an opaque file key from a
61+
// recipient stanza. It can be for example a secret key like [X25519Identity], a
6262
// plugin, or a custom implementation.
63-
//
64-
// Unwrap must return an error wrapping ErrIncorrectIdentity if none of the
65-
// recipient stanzas match the identity, any other error will be considered
66-
// fatal.
67-
//
68-
// Most age API users won't need to interact with this directly, and should
69-
// instead pass Recipient implementations to Encrypt and Identity
70-
// implementations to Decrypt.
7163
type Identity interface {
64+
// Unwrap must return an error wrapping [ErrIncorrectIdentity] if none of
65+
// the recipient stanzas match the identity, any other error will be
66+
// considered fatal.
67+
//
68+
// Most age API users won't need to interact with this method directly, and
69+
// should instead pass [Identity] implementations to [Decrypt].
7270
Unwrap(stanzas []*Stanza) (fileKey []byte, err error)
7371
}
7472

73+
// ErrIncorrectIdentity is returned by [Identity.Unwrap] if none of the
74+
// recipient stanzas match the identity.
7575
var ErrIncorrectIdentity = errors.New("incorrect identity for recipient block")
7676

77-
// A Recipient is passed to Encrypt to wrap an opaque file key to one or more
78-
// recipient stanza(s). It can be for example a public key like X25519Recipient,
77+
// A Recipient is passed to [Encrypt] to wrap an opaque file key to one or more
78+
// recipient stanza(s). It can be for example a public key like [X25519Recipient],
7979
// a plugin, or a custom implementation.
80-
//
81-
// Most age API users won't need to interact with this directly, and should
82-
// instead pass Recipient implementations to Encrypt and Identity
83-
// implementations to Decrypt.
8480
type Recipient interface {
81+
// Most age API users won't need to interact with this method directly, and
82+
// should instead pass [Recipient] implementations to [Encrypt].
8583
Wrap(fileKey []byte) ([]*Stanza, error)
8684
}
8785

88-
// RecipientWithLabels can be optionally implemented by a Recipient, in which
89-
// case Encrypt will use WrapWithLabels instead of Wrap.
86+
// RecipientWithLabels can be optionally implemented by a [Recipient], in which
87+
// case [Encrypt] will use WrapWithLabels instead of [Recipient.Wrap].
9088
//
9189
// Encrypt will succeed only if the labels returned by all the recipients
9290
// (assuming the empty set for those that don't implement RecipientWithLabels)
@@ -103,9 +101,9 @@ type RecipientWithLabels interface {
103101
// A Stanza is a section of the age header that encapsulates the file key as
104102
// encrypted to a specific recipient.
105103
//
106-
// Most age API users won't need to interact with this directly, and should
107-
// instead pass Recipient implementations to Encrypt and Identity
108-
// implementations to Decrypt.
104+
// Most age API users won't need to interact with this type directly, and should
105+
// instead pass [Recipient] implementations to [Encrypt] and [Identity]
106+
// implementations to [Decrypt].
109107
type Stanza struct {
110108
Type string
111109
Args []string
@@ -189,11 +187,11 @@ func slicesEqual(s1, s2 []string) bool {
189187
return true
190188
}
191189

192-
// NoIdentityMatchError is returned by Decrypt when none of the supplied
190+
// NoIdentityMatchError is returned by [Decrypt] when none of the supplied
193191
// identities match the encrypted file.
194192
type NoIdentityMatchError struct {
195193
// Errors is a slice of all the errors returned to Decrypt by the Unwrap
196-
// calls it made. They all wrap ErrIncorrectIdentity.
194+
// calls it made. They all wrap [ErrIncorrectIdentity].
197195
Errors []error
198196
}
199197

@@ -205,6 +203,9 @@ func (*NoIdentityMatchError) Error() string {
205203
//
206204
// It returns a Reader reading the decrypted plaintext of the age file read
207205
// from src. All identities will be tried until one successfully decrypts the file.
206+
//
207+
// If no identity matches the encrypted file, the returned error will be of type
208+
// [NoIdentityMatchError].
208209
func Decrypt(src io.Reader, identities ...Identity) (io.Reader, error) {
209210
if len(identities) == 0 {
210211
return nil, errors.New("no identities specified")

0 commit comments

Comments
 (0)