| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "flag" |
| 5 | "fmt" |
| 6 | "log" |
| 7 | "os" |
| 8 | "runtime/debug" |
| 9 | |
| 10 | "filippo.io/age" |
| 11 | "filippo.io/age/plugin" |
| 12 | "filippo.io/age/tag" |
| 13 | ) |
| 14 | |
| 15 | const usage = `age-plugin-tag is an age plugin for P-256 tagged recipients. These are supported |
| 16 | natively by age v1.3.0 and later, but this plugin can be placed in $PATH to add |
| 17 | support to any version and implementation of age that supports plugins. |
| 18 | |
| 19 | Usually, tagged recipients are the public side of private keys held in hardware, |
| 20 | where the identity side is handled by a different plugin.` |
| 21 | |
| 22 | // Version can be set at link time to override debug.BuildInfo.Main.Version when |
| 23 | // building manually without git history. It should look like "v1.2.3". |
| 24 | var Version string |
| 25 | |
| 26 | func main() { |
| 27 | flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) } |
| 28 | |
| 29 | p, err := plugin.New("tag") |
| 30 | if err != nil { |
| 31 | log.Fatal(err) |
| 32 | } |
| 33 | p.RegisterFlags(nil) |
| 34 | |
| 35 | versionFlag := flag.Bool("version", false, "print the version") |
| 36 | flag.Parse() |
| 37 | |
| 38 | if *versionFlag { |
| 39 | if buildInfo, ok := debug.ReadBuildInfo(); ok && Version == "" { |
| 40 | Version = buildInfo.Main.Version |
| 41 | } |
| 42 | fmt.Println(Version) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | p.HandleRecipient(func(b []byte) (age.Recipient, error) { |
| 47 | return tag.NewClassicRecipient(b) |
| 48 | }) |
| 49 | |
| 50 | os.Exit(p.Main()) |
| 51 | } |