From bf1252650ad1ef72697d2a77520a331ee7871396 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sun, 7 Dec 2025 15:10:58 +0100 Subject: [PATCH] plugin: add Handle{Recipient|Identity}Encoding methods --- plugin/plugin.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugin/plugin.go b/plugin/plugin.go index fa1d86e..a3a9fa7 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -106,6 +106,34 @@ func (p *Plugin) HandleIdentity(f func(data []byte) (age.Identity, error)) { p.identity = f } +// HandleRecipientEncoding is like [Plugin.HandleRecipient] but provides the +// full recipient encoding string to the callback. +// +// It allows using functions like ParseRecipient directly. +func (p *Plugin) HandleRecipientEncoding(f func(recipient string) (age.Recipient, error)) { + p.HandleRecipient(func(data []byte) (age.Recipient, error) { + return f(EncodeRecipient(p.name, data)) + }) +} + +// HandleIdentityEncodingAsRecipient is like [Plugin.HandleIdentityAsRecipient] but +// provides the full identity encoding string to the callback. +func (p *Plugin) HandleIdentityEncodingAsRecipient(f func(identity string) (age.Recipient, error)) { + p.HandleIdentityAsRecipient(func(data []byte) (age.Recipient, error) { + return f(EncodeIdentity(p.name, data)) + }) +} + +// HandleIdentityEncoding is like [Plugin.HandleIdentity] but provides the +// full identity encoding string to the callback. +// +// It allows using functions like ParseIdentity directly. +func (p *Plugin) HandleIdentityEncoding(f func(identity string) (age.Identity, error)) { + p.HandleIdentity(func(data []byte) (age.Identity, error) { + return f(EncodeIdentity(p.name, data)) + }) +} + // Main runs the plugin protocol. It returns an exit code to pass to os.Exit. // // It automatically calls [Plugin.RegisterFlags] and [flag.Parse] if they were