File: plugin-tag.go

package info (click to toggle)
age 1.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 984 kB
  • sloc: makefile: 11
file content (51 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/debug"

	"filippo.io/age"
	"filippo.io/age/plugin"
	"filippo.io/age/tag"
)

const usage = `age-plugin-tag is an age plugin for P-256 tagged recipients. These are supported
natively by age v1.3.0 and later, but this plugin can be placed in $PATH to add
support to any version and implementation of age that supports plugins.

Usually, tagged recipients are the public side of private keys held in hardware,
where the identity side is handled by a different plugin.`

// Version can be set at link time to override debug.BuildInfo.Main.Version when
// building manually without git history. It should look like "v1.2.3".
var Version string

func main() {
	flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) }

	p, err := plugin.New("tag")
	if err != nil {
		log.Fatal(err)
	}
	p.RegisterFlags(nil)

	versionFlag := flag.Bool("version", false, "print the version")
	flag.Parse()

	if *versionFlag {
		if buildInfo, ok := debug.ReadBuildInfo(); ok && Version == "" {
			Version = buildInfo.Main.Version
		}
		fmt.Println(Version)
		return
	}

	p.HandleRecipient(func(b []byte) (age.Recipient, error) {
		return tag.NewClassicRecipient(b)
	})

	os.Exit(p.Main())
}