| 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style |
| 4 | // license that can be found in the LICENSE file or at |
| 5 | // https://developers.google.com/open-source/licenses/bsd |
| 6 | |
| 7 | package pluginscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ |
| 8 | |
| 9 | import ( |
| 10 | "bufioscip-go gomod github.com/golang/go/src . bufio/" |
| 11 | "crypto/randscip-go gomod github.com/golang/go/src . `crypto/rand`/" |
| 12 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 13 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 14 | "ioscip-go gomod github.com/golang/go/src . io/" |
| 15 | mathrandscip-go gomod github.com/golang/go/src . `math/rand/v2`/ "math/rand/v2scip-go gomod github.com/golang/go/src . `math/rand/v2`/" |
| 16 | "osscip-go gomod github.com/golang/go/src . os/" |
| 17 | "path/filepathscip-go gomod github.com/golang/go/src . `path/filepath`/" |
| 18 | "strconvscip-go gomod github.com/golang/go/src . strconv/" |
| 19 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 20 | "timescip-go gomod github.com/golang/go/src . time/" |
| 21 | |
| 22 | execscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/ "golang.org/x/sys/execabsscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/" |
| 23 | |
| 24 | "filippo.io/agescip-go gomod filippo.io/age . `filippo.io/age`/" |
| 25 | "filippo.io/age/internal/formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/" |
| 26 | ) |
| 27 | |
| 28 | type Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient# struct { |
| 29 | namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name. string |
| 30 | encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#encoding. string |
| 31 | uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#ui. *ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI# |
| 32 | |
| 33 | // identity is true when encoding is an identity string. |
| 34 | identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#identity. bool |
| 35 | } |
| 36 | |
| 37 | var _ agescip-go gomod filippo.io/age . `filippo.io/age`/.Recipientscip-go gomod filippo.io/age . `filippo.io/age`/Recipient# = &Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#{} |
| 38 | var _ agescip-go gomod filippo.io/age . `filippo.io/age`/.RecipientWithLabelsscip-go gomod filippo.io/age . `filippo.io/age`/RecipientWithLabels# = &Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#{} |
| 39 | |
| 40 | func NewRecipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NewRecipient().(s string, ui *ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#) (*Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#, error) { |
| 41 | name, _, err := ParseRecipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ParseRecipient().(s) |
| 42 | if err != nil { |
| 43 | return nil, err |
| 44 | } |
| 45 | return &Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#{ |
| 46 | namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name.: name, encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#encoding.: s, uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#ui.: ui, |
| 47 | }, nil |
| 48 | } |
| 49 | |
| 50 | // Name returns the plugin name, which is used in the recipient ("age1name1...") |
| 51 | // and identity ("AGE-PLUGIN-NAME-1...") encodings, as well as in the plugin |
| 52 | // binary name ("age-plugin-name"). |
| 53 | func (r *Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#) Namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#Name().() string { |
| 54 | return r.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name. |
| 55 | } |
| 56 | |
| 57 | // String returns the recipient encoding string ("age1name1...") or |
| 58 | // "<identity-based recipient>" if r was created by [Identity.Recipient]. |
| 59 | func (r *Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#) Stringscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#String().() string { |
| 60 | if r.identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#identity. { |
| 61 | return "<identity-based recipient>" |
| 62 | } |
| 63 | return r.encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#encoding. |
| 64 | } |
| 65 | |
| 66 | func (r *Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#) Wrapscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#Wrap().(fileKey []byte) (stanzas []*agescip-go gomod filippo.io/age . `filippo.io/age`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age`/Stanza#, err error) { |
| 67 | stanzas, _, err = r.WrapWithLabelsscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#WrapWithLabels().(fileKey) |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | func (r *Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#) WrapWithLabelsscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#WrapWithLabels().(fileKey []byte) (stanzas []*agescip-go gomod filippo.io/age . `filippo.io/age`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age`/Stanza#, labels []string, err error) { |
| 72 | defer func() { |
| 73 | if err != nil { |
| 74 | err = fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%s plugin: %w", r.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name., err) |
| 75 | } |
| 76 | }() |
| 77 | |
| 78 | conn, err := openClientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/openClientConnection().(r.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name., "recipient-v1") |
| 79 | if err != nil { |
| 80 | return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("couldn't start plugin: %w", err) |
| 81 | } |
| 82 | defer conn.Closescip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Close().() |
| 83 | |
| 84 | // Phase 1: client sends recipient or identity and file key |
| 85 | addType := "add-recipient" |
| 86 | if r.identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#identity. { |
| 87 | addType = "add-identity" |
| 88 | } |
| 89 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, addType, r.encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#encoding.); err != nil { |
| 90 | return nil, nil, err |
| 91 | } |
| 92 | if _, err := writeGreasescip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeGrease().(conn); err != nil { |
| 93 | return nil, nil, err |
| 94 | } |
| 95 | if err := writeStanzaWithBodyscip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanzaWithBody().(conn, "wrap-file-key", fileKey); err != nil { |
| 96 | return nil, nil, err |
| 97 | } |
| 98 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "extension-labels"); err != nil { |
| 99 | return nil, nil, err |
| 100 | } |
| 101 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "done"); err != nil { |
| 102 | return nil, nil, err |
| 103 | } |
| 104 | |
| 105 | // Phase 2: plugin responds with stanzas |
| 106 | sr := formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.NewStanzaReaderscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/NewStanzaReader().(bufioscip-go gomod github.com/golang/go/src . bufio/.NewReaderscip-go gomod github.com/golang/go/src . bufio/NewReader().(conn)) |
| 107 | ReadLoop: |
| 108 | for { |
| 109 | s, err := r.uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#ui..readStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#readStanza().(r.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name., sr) |
| 110 | if err != nil { |
| 111 | return nil, nil, err |
| 112 | } |
| 113 | |
| 114 | switch s.Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type. { |
| 115 | case "recipient-stanza": |
| 116 | if len(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.) < 2 { |
| 117 | return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed recipient stanza: unexpected argument count") |
| 118 | } |
| 119 | n, err := strconvscip-go gomod github.com/golang/go/src . strconv/.Atoiscip-go gomod github.com/golang/go/src . strconv/Atoi().(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.[0]) |
| 120 | if err != nil { |
| 121 | return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed recipient stanza: invalid index") |
| 122 | } |
| 123 | // We only send a single file key, so the index must be 0. |
| 124 | if n != 0 { |
| 125 | return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed recipient stanza: unexpected index") |
| 126 | } |
| 127 | |
| 128 | stanzas = append(stanzas, &agescip-go gomod filippo.io/age . `filippo.io/age`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age`/Stanza#{ |
| 129 | Typescip-go gomod filippo.io/age . `filippo.io/age`/Stanza#Type.: s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.[1], |
| 130 | Argsscip-go gomod filippo.io/age . `filippo.io/age`/Stanza#Args.: s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.[2:], |
| 131 | Bodyscip-go gomod filippo.io/age . `filippo.io/age`/Stanza#Body.: s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body., |
| 132 | }) |
| 133 | |
| 134 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "ok"); err != nil { |
| 135 | return nil, nil, err |
| 136 | } |
| 137 | case "labels": |
| 138 | if labels != nil { |
| 139 | return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("repeated labels stanza") |
| 140 | } |
| 141 | labels = s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args. |
| 142 | |
| 143 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "ok"); err != nil { |
| 144 | return nil, nil, err |
| 145 | } |
| 146 | case "error": |
| 147 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "ok"); err != nil { |
| 148 | return nil, nil, err |
| 149 | } |
| 150 | |
| 151 | return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%s", s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.) |
| 152 | case "done": |
| 153 | break ReadLoop |
| 154 | default: |
| 155 | if ok, err := r.uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#ui..handlescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#handle().(r.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name., conn, s); err != nil { |
| 156 | return nil, nil, err |
| 157 | } else if !ok { |
| 158 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "unsupported"); err != nil { |
| 159 | return nil, nil, err |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if len(stanzas) == 0 { |
| 166 | return nil, nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("received zero recipient stanzas") |
| 167 | } |
| 168 | |
| 169 | return stanzas, labels, nil |
| 170 | } |
| 171 | |
| 172 | type Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity# struct { |
| 173 | namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name. string |
| 174 | encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#encoding. string |
| 175 | uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#ui. *ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI# |
| 176 | } |
| 177 | |
| 178 | var _ agescip-go gomod filippo.io/age . `filippo.io/age`/.Identityscip-go gomod filippo.io/age . `filippo.io/age`/Identity# = &Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#{} |
| 179 | |
| 180 | func NewIdentityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NewIdentity().(s string, ui *ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#) (*Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#, error) { |
| 181 | name, _, err := ParseIdentityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ParseIdentity().(s) |
| 182 | if err != nil { |
| 183 | return nil, err |
| 184 | } |
| 185 | return &Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#{ |
| 186 | namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name.: name, encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#encoding.: s, uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#ui.: ui, |
| 187 | }, nil |
| 188 | } |
| 189 | |
| 190 | func NewIdentityWithoutDatascip-go gomod filippo.io/age . `filippo.io/age/plugin`/NewIdentityWithoutData().(name string, ui *ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#) (*Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#, error) { |
| 191 | s := EncodeIdentityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/EncodeIdentity().(name, nil) |
| 192 | if s == "" { |
| 193 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("invalid plugin name: %q", name) |
| 194 | } |
| 195 | return &Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#{ |
| 196 | namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name.: stringsscip-go gomod github.com/golang/go/src . strings/.ToLowerscip-go gomod github.com/golang/go/src . strings/ToLower().(name), encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#encoding.: s, uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#ui.: ui, |
| 197 | }, nil |
| 198 | } |
| 199 | |
| 200 | // Name returns the plugin name, which is used in the recipient ("age1name1...") |
| 201 | // and identity ("AGE-PLUGIN-NAME-1...") encodings, as well as in the plugin |
| 202 | // binary name ("age-plugin-name"). |
| 203 | func (i *Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#) Namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#Name().() string { |
| 204 | return i.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name. |
| 205 | } |
| 206 | |
| 207 | // String returns the identity encoding string ("AGE-PLUGIN-NAME-1..."). |
| 208 | func (i *Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#) Stringscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#String().() string { |
| 209 | return i.encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#encoding. |
| 210 | } |
| 211 | |
| 212 | // Recipient returns a Recipient wrapping this identity. When that Recipient is |
| 213 | // used to encrypt a file key, the identity encoding is provided as-is to the |
| 214 | // plugin, which is expected to support encrypting to identities. |
| 215 | func (i *Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#) Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#Recipient().() *Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient# { |
| 216 | return &Recipientscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#{ |
| 217 | namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#name.: i.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name., |
| 218 | encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#encoding.: i.encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#encoding., |
| 219 | identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#identity.: true, |
| 220 | uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Recipient#ui.: i.uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#ui., |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | func (i *Identityscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#) Unwrapscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#Unwrap().(stanzas []*agescip-go gomod filippo.io/age . `filippo.io/age`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age`/Stanza#) (fileKey []byte, err error) { |
| 225 | defer func() { |
| 226 | if err != nil { |
| 227 | err = fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%s plugin: %w", i.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name., err) |
| 228 | } |
| 229 | }() |
| 230 | |
| 231 | conn, err := openClientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/openClientConnection().(i.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name., "identity-v1") |
| 232 | if err != nil { |
| 233 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("couldn't start plugin: %w", err) |
| 234 | } |
| 235 | defer conn.Closescip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Close().() |
| 236 | |
| 237 | // Phase 1: client sends the plugin the identity string and the stanzas |
| 238 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "add-identity", i.encodingscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#encoding.); err != nil { |
| 239 | return nil, err |
| 240 | } |
| 241 | if _, err := writeGreasescip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeGrease().(conn); err != nil { |
| 242 | return nil, err |
| 243 | } |
| 244 | for _, rs := range stanzas { |
| 245 | s := &formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#{ |
| 246 | Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type.: "recipient-stanza", |
| 247 | Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.: append([]string{"0", rs.Typescip-go gomod filippo.io/age . `filippo.io/age`/Stanza#Type.}, rs.Argsscip-go gomod filippo.io/age . `filippo.io/age`/Stanza#Args....), |
| 248 | Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.: rs.Bodyscip-go gomod filippo.io/age . `filippo.io/age`/Stanza#Body., |
| 249 | } |
| 250 | if err := s.Marshalscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Marshal().(conn); err != nil { |
| 251 | return nil, err |
| 252 | } |
| 253 | } |
| 254 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "done"); err != nil { |
| 255 | return nil, err |
| 256 | } |
| 257 | |
| 258 | // Phase 2: plugin responds with various commands and a file key |
| 259 | sr := formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.NewStanzaReaderscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/NewStanzaReader().(bufioscip-go gomod github.com/golang/go/src . bufio/.NewReaderscip-go gomod github.com/golang/go/src . bufio/NewReader().(conn)) |
| 260 | ReadLoop: |
| 261 | for { |
| 262 | s, err := i.uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#ui..readStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#readStanza().(i.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name., sr) |
| 263 | if err != nil { |
| 264 | return nil, err |
| 265 | } |
| 266 | |
| 267 | switch s.Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type. { |
| 268 | case "file-key": |
| 269 | if len(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.) != 1 { |
| 270 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed file-key stanza: unexpected arguments count") |
| 271 | } |
| 272 | n, err := strconvscip-go gomod github.com/golang/go/src . strconv/.Atoiscip-go gomod github.com/golang/go/src . strconv/Atoi().(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.[0]) |
| 273 | if err != nil { |
| 274 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed file-key stanza: invalid index") |
| 275 | } |
| 276 | // We only send a single file key, so the index must be 0. |
| 277 | if n != 0 { |
| 278 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed file-key stanza: unexpected index") |
| 279 | } |
| 280 | if fileKey != nil { |
| 281 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("received duplicated file-key stanza") |
| 282 | } |
| 283 | |
| 284 | fileKey = s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body. |
| 285 | |
| 286 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "ok"); err != nil { |
| 287 | return nil, err |
| 288 | } |
| 289 | case "error": |
| 290 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "ok"); err != nil { |
| 291 | return nil, err |
| 292 | } |
| 293 | |
| 294 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%s", s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.) |
| 295 | case "done": |
| 296 | break ReadLoop |
| 297 | default: |
| 298 | if ok, err := i.uiscip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#ui..handlescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#handle().(i.namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/Identity#name., conn, s); err != nil { |
| 299 | return nil, err |
| 300 | } else if !ok { |
| 301 | if err := writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "unsupported"); err != nil { |
| 302 | return nil, err |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if fileKey == nil { |
| 309 | return nil, agescip-go gomod filippo.io/age . `filippo.io/age`/.ErrIncorrectIdentityscip-go gomod filippo.io/age . `filippo.io/age`/ErrIncorrectIdentity. |
| 310 | } |
| 311 | return fileKey, nil |
| 312 | } |
| 313 | |
| 314 | // ClientUI holds callbacks that will be invoked by (Un)Wrap if the plugin |
| 315 | // wishes to interact with the user. If any of them is nil or returns an error, |
| 316 | // failure will be reported to the plugin, but note that the error is otherwise |
| 317 | // discarded. Implementations are encouraged to display errors to the user |
| 318 | // before returning them. |
| 319 | type ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI# struct { |
| 320 | // DisplayMessage displays the message, which is expected to have lowercase |
| 321 | // initials and no final period. |
| 322 | DisplayMessagescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#DisplayMessage. func(name, message string) error |
| 323 | |
| 324 | // RequestValue requests a secret or public input, with the provided prompt. |
| 325 | RequestValuescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#RequestValue. func(name, prompt string, secret bool) (string, error) |
| 326 | |
| 327 | // Confirm requests a confirmation with the provided prompt. The yes and no |
| 328 | // value are the choices provided to the user. no may be empty. The return |
| 329 | // value indicates whether the user selected the yes or no option. |
| 330 | Confirmscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#Confirm. func(name, prompt, yes, no string) (choseYes bool, err error) |
| 331 | |
| 332 | // WaitTimer is invoked once (Un)Wrap has been waiting for 5 seconds on the |
| 333 | // plugin, for example because the plugin is waiting for an external event |
| 334 | // (e.g. a hardware token touch). Unlike the other callbacks, WaitTimer runs |
| 335 | // in a separate goroutine, and if missing it's simply ignored. |
| 336 | WaitTimerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#WaitTimer. func(name string) |
| 337 | } |
| 338 | |
| 339 | func (c *ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#) handlescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#handle().(name string, conn *clientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#, s *formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#) (ok bool, err error) { |
| 340 | switch s.Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type. { |
| 341 | case "msg": |
| 342 | if c.DisplayMessagescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#DisplayMessage. == nil { |
| 343 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "fail") |
| 344 | } |
| 345 | if err := c.DisplayMessagescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#DisplayMessage.(name, string(s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.)); err != nil { |
| 346 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "fail") |
| 347 | } |
| 348 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "ok") |
| 349 | case "request-secret", "request-public": |
| 350 | if c.RequestValuescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#RequestValue. == nil { |
| 351 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "fail") |
| 352 | } |
| 353 | secret, err := c.RequestValuescip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#RequestValue.(name, string(s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.), s.Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type. == "request-secret") |
| 354 | if err != nil { |
| 355 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "fail") |
| 356 | } |
| 357 | return true, writeStanzaWithBodyscip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanzaWithBody().(conn, "ok", []byte(secret)) |
| 358 | case "confirm": |
| 359 | if len(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.) != 1 && len(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.) != 2 { |
| 360 | return true, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed confirm stanza: unexpected number of arguments") |
| 361 | } |
| 362 | if c.Confirmscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#Confirm. == nil { |
| 363 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "fail") |
| 364 | } |
| 365 | yes, err := formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.DecodeStringscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/DecodeString().(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.[0]) |
| 366 | if err != nil { |
| 367 | return true, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed confirm stanza: invalid YES option encoding") |
| 368 | } |
| 369 | var no []byte |
| 370 | if len(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.) == 2 { |
| 371 | no, err = formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.DecodeStringscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/DecodeString().(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.[1]) |
| 372 | if err != nil { |
| 373 | return true, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("malformed confirm stanza: invalid NO option encoding") |
| 374 | } |
| 375 | } |
| 376 | choseYes, err := c.Confirmscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#Confirm.(name, string(s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.), string(yes), string(no)) |
| 377 | if err != nil { |
| 378 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "fail") |
| 379 | } |
| 380 | result := "yes" |
| 381 | if !choseYes { |
| 382 | result = "no" |
| 383 | } |
| 384 | return true, writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn, "ok", result) |
| 385 | default: |
| 386 | return false, nil |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | // readStanza calls r.ReadStanza and, if set, invokes WaitTimer in a separate |
| 391 | // goroutine if the call takes longer than 5 seconds. |
| 392 | func (c *ClientUIscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#) readStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#readStanza().(name string, r *formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.StanzaReaderscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/StanzaReader#) (*formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#, error) { |
| 393 | if c.WaitTimerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#WaitTimer. != nil { |
| 394 | defer timescip-go gomod github.com/golang/go/src . time/.AfterFuncscip-go gomod github.com/golang/go/src . time/AfterFunc().(5*timescip-go gomod github.com/golang/go/src . time/.Secondscip-go gomod github.com/golang/go/src . time/Second., func() { c.WaitTimerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/ClientUI#WaitTimer.(name) }).Stopscip-go gomod github.com/golang/go/src . time/Timer#Stop().() |
| 395 | } |
| 396 | return r.ReadStanzascip-go gomod filippo.io/age . `filippo.io/age/internal/format`/StanzaReader#ReadStanza().() |
| 397 | } |
| 398 | |
| 399 | type clientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection# struct { |
| 400 | cmdscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#cmd. *execscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/.Cmdscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/Cmd# |
| 401 | ioscip-go gomod github.com/golang/go/src . io/.Readerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Reader. // stdout |
| 402 | ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Writer. // stdin |
| 403 | closescip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#close. func() |
| 404 | } |
| 405 | |
| 406 | // NotFoundError is returned by [Recipient.Wrap] and [Identity.Unwrap] when the |
| 407 | // plugin binary cannot be found. |
| 408 | type NotFoundErrorscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError# struct { |
| 409 | // Name is the plugin (not binary) name. |
| 410 | Namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Name. string |
| 411 | // Err is the underlying error, usually an [exec.Error] wrapping |
| 412 | // [exec.ErrNotFound]. |
| 413 | Errscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Err. error |
| 414 | } |
| 415 | |
| 416 | func (e *NotFoundErrorscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#) Errorscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Error().() string { |
| 417 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%q plugin not found: %v", e.Namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Name., e.Errscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Err.) |
| 418 | } |
| 419 | |
| 420 | func (e *NotFoundErrorscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#) Unwrapscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Unwrap().() error { |
| 421 | return e.Errscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Err. |
| 422 | } |
| 423 | |
| 424 | var testOnlyPluginPathscip-go gomod filippo.io/age . `filippo.io/age/plugin`/testOnlyPluginPath. string |
| 425 | |
| 426 | func openClientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/openClientConnection().(name, protocol string) (*clientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#, error) { |
| 427 | path := "age-plugin-" + name |
| 428 | if testOnlyPluginPathscip-go gomod filippo.io/age . `filippo.io/age/plugin`/testOnlyPluginPath. != "" { |
| 429 | path = filepathscip-go gomod github.com/golang/go/src . `path/filepath`/.Joinscip-go gomod github.com/golang/go/src . `path/filepath`/Join().(testOnlyPluginPathscip-go gomod filippo.io/age . `filippo.io/age/plugin`/testOnlyPluginPath., path) |
| 430 | } else if stringsscip-go gomod github.com/golang/go/src . strings/.ContainsRunescip-go gomod github.com/golang/go/src . strings/ContainsRune().(name, osscip-go gomod github.com/golang/go/src . os/.PathSeparatorscip-go gomod github.com/golang/go/src . os/PathSeparator.) { |
| 431 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("invalid plugin name: %q", name) |
| 432 | } |
| 433 | cmd := execscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/.Commandscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/Command().(path, "--age-plugin="+protocol) |
| 434 | |
| 435 | stdout, err := cmd.StdoutPipescip-go gomod github.com/golang/go/src . `os/exec`/Cmd#StdoutPipe().() |
| 436 | if err != nil { |
| 437 | return nil, err |
| 438 | } |
| 439 | stdin, err := cmd.StdinPipescip-go gomod github.com/golang/go/src . `os/exec`/Cmd#StdinPipe().() |
| 440 | if err != nil { |
| 441 | return nil, err |
| 442 | } |
| 443 | |
| 444 | cc := &clientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#{ |
| 445 | cmdscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#cmd.: cmd, |
| 446 | Readerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Reader.: stdout, |
| 447 | Writerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Writer.: stdin, |
| 448 | closescip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#close.: func() { |
| 449 | stdin.Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() |
| 450 | stdout.Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() |
| 451 | }, |
| 452 | } |
| 453 | |
| 454 | if osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("AGEDEBUG") == "plugin" { |
| 455 | cc.Readerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Reader. = ioscip-go gomod github.com/golang/go/src . io/.TeeReaderscip-go gomod github.com/golang/go/src . io/TeeReader().(cc.Readerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Reader., osscip-go gomod github.com/golang/go/src . os/.Stderrscip-go gomod github.com/golang/go/src . os/Stderr.) |
| 456 | cc.Writerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Writer. = ioscip-go gomod github.com/golang/go/src . io/.MultiWriterscip-go gomod github.com/golang/go/src . io/MultiWriter().(cc.Writerscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Writer., osscip-go gomod github.com/golang/go/src . os/.Stderrscip-go gomod github.com/golang/go/src . os/Stderr.) |
| 457 | cmd.Stderrscip-go gomod github.com/golang/go/src . `os/exec`/Cmd#Stderr. = osscip-go gomod github.com/golang/go/src . os/.Stderrscip-go gomod github.com/golang/go/src . os/Stderr. |
| 458 | } |
| 459 | |
| 460 | // Avoid running plugins in the client's working directory, as it might |
| 461 | // differ between clients. |
| 462 | cmd.Dirscip-go gomod github.com/golang/go/src . `os/exec`/Cmd#Dir. = osscip-go gomod github.com/golang/go/src . os/.TempDirscip-go gomod github.com/golang/go/src . os/TempDir().() |
| 463 | |
| 464 | if err := cmd.Startscip-go gomod github.com/golang/go/src . `os/exec`/Cmd#Start().(); err != nil { |
| 465 | if errorsscip-go gomod github.com/golang/go/src . errors/.Isscip-go gomod github.com/golang/go/src . errors/Is().(err, execscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/.ErrNotFoundscip-go gomod golang.org/x/sys v0.47.0 `golang.org/x/sys/execabs`/ErrNotFound.) { |
| 466 | return nil, &NotFoundErrorscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#{Namescip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Name.: name, Errscip-go gomod filippo.io/age . `filippo.io/age/plugin`/NotFoundError#Err.: err} |
| 467 | } |
| 468 | return nil, err |
| 469 | } |
| 470 | |
| 471 | return cc, nil |
| 472 | } |
| 473 | |
| 474 | func (cc *clientConnectionscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#) Closescip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#Close().() error { |
| 475 | // Close stdin and stdout and send SIGINT (if supported) to the plugin, |
| 476 | // then wait for it to cleanup and exit. |
| 477 | cc.closescip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#close.() |
| 478 | cc.cmdscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#cmd..Processscip-go gomod github.com/golang/go/src . `os/exec`/Cmd#Process..Signalscip-go gomod github.com/golang/go/src . os/Process#Signal().(osscip-go gomod github.com/golang/go/src . os/.Interruptscip-go gomod github.com/golang/go/src . os/Interrupt.) |
| 479 | return cc.cmdscip-go gomod filippo.io/age . `filippo.io/age/plugin`/clientConnection#cmd..Waitscip-go gomod github.com/golang/go/src . `os/exec`/Cmd#Wait().() |
| 480 | } |
| 481 | |
| 482 | func writeStanzascip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanza().(conn ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, t string, args ...string) error { |
| 483 | s := &formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#{Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type.: t, Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args.: args} |
| 484 | return s.Marshalscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Marshal().(conn) |
| 485 | } |
| 486 | |
| 487 | func writeStanzaWithBodyscip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeStanzaWithBody().(conn ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, t string, body []byte) error { |
| 488 | s := &formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#{Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type.: t, Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.: body} |
| 489 | return s.Marshalscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Marshal().(conn) |
| 490 | } |
| 491 | |
| 492 | func writeGreasescip-go gomod filippo.io/age . `filippo.io/age/plugin`/writeGrease().(conn ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#) (sent bool, err error) { |
| 493 | if mathrandscip-go gomod github.com/golang/go/src . `math/rand/v2`/.IntN(3) == 0 { |
| 494 | return false, nil |
| 495 | } |
| 496 | s := &formatscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/.Stanzascip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#{Typescip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Type.: fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("grease-%x", mathrandscip-go gomod github.com/golang/go/src . `math/rand/v2`/.Int())} |
| 497 | for i := 0; i < mathrandscip-go gomod github.com/golang/go/src . `math/rand/v2`/.IntN(3); i++ { |
| 498 | s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args. = append(s.Argsscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Args., fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%d", mathrandscip-go gomod github.com/golang/go/src . `math/rand/v2`/.IntN(100))) |
| 499 | } |
| 500 | if mathrandscip-go gomod github.com/golang/go/src . `math/rand/v2`/.IntN(2) == 0 { |
| 501 | s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body. = make([]byte, mathrandscip-go gomod github.com/golang/go/src . `math/rand/v2`/.IntN(100)) |
| 502 | randscip-go gomod github.com/golang/go/src . `crypto/rand`/.Readscip-go gomod github.com/golang/go/src . `crypto/rand`/Read().(s.Bodyscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Body.) |
| 503 | } |
| 504 | return true, s.Marshalscip-go gomod filippo.io/age . `filippo.io/age/internal/format`/Stanza#Marshal().(conn) |
| 505 | } |