Skip to content

Commit d29d751

Browse files
committed
plugin: add String methods to Recipient and Identity
1 parent 2a671dc commit d29d751

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

plugin/client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ func (r *Recipient) Name() string {
5252
return r.name
5353
}
5454

55+
// String returns the recipient encoding string ("age1name1...") or
56+
// "<identity-based recipient>" if r was created by [Identity.Recipient].
57+
func (r *Recipient) String() string {
58+
if r.identity {
59+
return "<identity-based recipient>"
60+
}
61+
return r.encoding
62+
}
63+
5564
func (r *Recipient) Wrap(fileKey []byte) (stanzas []*age.Stanza, err error) {
5665
stanzas, _, err = r.WrapWithLabels(fileKey)
5766
return
@@ -193,6 +202,11 @@ func (i *Identity) Name() string {
193202
return i.name
194203
}
195204

205+
// String returns the identity encoding string ("AGE-PLUGIN-NAME-1...").
206+
func (i *Identity) String() string {
207+
return i.encoding
208+
}
209+
196210
// Recipient returns a Recipient wrapping this identity. When that Recipient is
197211
// used to encrypt a file key, the identity encoding is provided as-is to the
198212
// plugin, which is expected to support encrypting to identities.

0 commit comments

Comments
 (0)