ogvt/main.go

69 lines
1.3 KiB
Go

package main
import (
"flag"
"fmt"
"io"
"os"
"strings"
"golang.org/x/crypto/openpgp"
)
func verifyArmored(kr openpgp.KeyRing, file, sig io.Reader) (*openpgp.Entity, error) {
return openpgp.CheckArmoredDetachedSignature(kr, file, sig)
}
func verify(kr openpgp.KeyRing, file, sig io.Reader) (*openpgp.Entity, error) {
return openpgp.CheckDetachedSignature(kr, file, sig)
}
func open(path string) io.Reader {
f, err := os.Open(path)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return f
}
func main() {
var sig, file, pub string
flag.StringVar(&sig, "sig", "", "path to signature file")
flag.StringVar(&file, "file", "", "path to file")
flag.StringVar(&pub, "pub", "", "path to pub file")
flag.Parse()
pledge("stdio tty unveil rpath")
unveil(sig, "r")
unveil(file, "r")
unveil(pub, "r")
unveilBlock()
kr, err := openpgp.ReadArmoredKeyRing(open(pub))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var ent *openpgp.Entity
switch {
case strings.HasSuffix(sig, ".sig"):
ent, err = verify(kr, open(file), open(sig))
case strings.HasSuffix(sig, ".asc"):
ent, err = verifyArmored(kr, open(file), open(sig))
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, id := range ent.Identities {
fmt.Printf("%s\n", id.Name)
}
fmt.Println("Signature OK.")
}