File: encrypt.go

package info (click to toggle)
golang-github-proglottis-gpgme 0.0~git20181127.3b0be09-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 156 kB
  • sloc: ansic: 124; makefile: 12
file content (39 lines) | stat: -rw-r--r-- 644 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
package main

import (
	"flag"
	"os"

	"github.com/proglottis/gpgme"
)

func main() {
	flag.Parse()
	filter := flag.Arg(0)
	if filter == "" {
		panic("must specify recipient filter")
	}
	recipients, err := gpgme.FindKeys(filter, false)
	if err != nil {
		panic(err)
	}
	if len(recipients) < 1 {
		panic("no keys match")
	}
	plain, err := gpgme.NewDataReader(os.Stdin)
	if err != nil {
		panic(err)
	}
	cipher, err := gpgme.NewDataWriter(os.Stdout)
	if err != nil {
		panic(err)
	}
	ctx, err := gpgme.New()
	if err != nil {
		panic(err)
	}
	ctx.SetArmor(true)
	if err := ctx.Encrypt(recipients, 0, plain, cipher); err != nil {
		panic(err)
	}
}