look for file if it is not passed in

This commit is contained in:
Aaron Bieber 2020-11-16 08:27:40 -07:00
parent 5bad093803
commit 0221349dcc
4 changed files with 25 additions and 6 deletions

2
go.mod
View File

@ -3,6 +3,6 @@ module suah.dev/ogvt
go 1.13
require (
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
suah.dev/protect v1.0.0
)

2
go.sum
View File

@ -1,6 +1,8 @@
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w=
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"golang.org/x/crypto/openpgp"
@ -36,6 +37,14 @@ func main() {
_ = protect.Unveil(pub, "r")
_ = protect.UnveilBlock()
if sig != "" && file == "" {
// Check for a 'file' with the .sig extensions removed
bn := strings.TrimSuffix(sig, filepath.Ext(sig))
if _, err := os.Stat(bn); err == nil {
file = bn
}
}
fPub, err := os.Open(pub)
errExit(err)

View File

@ -5,12 +5,20 @@ set -e
mandoc -T lint ./ogvt.1
go build
printf "Testing detached armor (asc)\t\t"
./ogvt -file test/uptime.txt -sig test/uptime.txt.asc -pub test/adent.pub >/dev/null && echo "OK"
./ogvt -file test/uptime.txt -sig test/uptime.txt.asc -pub test/adent.pub >/dev/null && echo "OK" || echo "FAIL"
printf "Testing detached non-armor (gpg)\t"
./ogvt -file test/uptime.txt -sig test/uptime.txt.gpg -pub test/adent.pub >/dev/null && echo "OK"
./ogvt -file test/uptime.txt -sig test/uptime.txt.gpg -pub test/adent.pub >/dev/null && echo "OK" || echo "FAIL"
printf "Testing detached non-armor (sig)\t"
./ogvt -file test/uptime.txt -sig test/uptime.txt.sig -pub test/adent.pub >/dev/null && echo "OK"
./ogvt -file test/uptime.txt -sig test/uptime.txt.sig -pub test/adent.pub >/dev/null && echo "OK" || echo "FAIL"
printf "Testing just having a sig (nofile)\t"
./ogvt -sig test/uptime.txt.sig -pub test/adent.pub >/dev/null && echo "OK" || echo "FAIL"
printf "Testing bad sig file\t\t\t"
./ogvt -file test/uptime.txt -sig test/bad.sig -pub test/adent.pub >/dev/null || echo "OK"
./ogvt -file test/uptime.txt -sig test/bad.sig -pub test/adent.pub >/dev/null && echo "FAIL" || echo "OK"
printf "Testing empty file\t\t\t"
./ogvt -file test/uptime.txt -sig /dev/null -pub test/adent.pub >/dev/null || echo "OK"
./ogvt -file test/uptime.txt -sig /dev/null -pub test/adent.pub >/dev/null && echo "FAIL" || echo "OK"