aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-07-24 11:28:35 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-07-24 11:28:35 +0200
commit64ae9e0462a3378e6581296fa3c663ba61d7f13f (patch)
treead60d1650b3a4759cfd2b577ddbb733f58f7e31f
parent377fc867b7da33a4cfd865549efe2ec22a06ece4 (diff)
Split
-rw-r--r--file/names.go6
-rw-r--r--file/names_test.go2
-rw-r--r--verify.go60
3 files changed, 50 insertions, 18 deletions
diff --git a/file/names.go b/file/names.go
index 11310b4..f893294 100644
--- a/file/names.go
+++ b/file/names.go
@@ -41,14 +41,14 @@ func SigName(msgFile string) string {
return msgFile + extSig
}
-func PubFile(comment string) (string, bool) {
+func PubFile(comment string) string {
if strings.HasPrefix(comment, verifyWith) {
file := comment[len(verifyWith):]
if strings.HasSuffix(file, extPub) {
- return FindFile(file), true
+ return FindFile(file)
}
}
- return "", false
+ return ""
}
func VerifyWith(secFile string) string {
diff --git a/file/names_test.go b/file/names_test.go
index 7f6e089..a24faee 100644
--- a/file/names_test.go
+++ b/file/names_test.go
@@ -35,7 +35,7 @@ func TestVerify(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.comment, func(t *testing.T) {
- file, _ := PubFile(tc.comment)
+ file := PubFile(tc.comment)
if file != tc.file {
t.Errorf("got %v, want %v", file, tc.file)
}
diff --git a/verify.go b/verify.go
index 6984382..bf6f8f2 100644
--- a/verify.go
+++ b/verify.go
@@ -36,29 +36,61 @@ func verify(args []string) error {
}
_ = keyType // TODO
- sig, msg, verifyWith, err := openSig(*sigFile)
+ switch {
+ case *zip:
+ if err := verifyGzip(*pubFile, *msgFile); err != nil {
+ return err
+ }
+ case *embedded:
+ if err := verifyEmbedded(*pubFile, *sigFile); err != nil {
+ return err
+ }
+ default:
+ if err := verifyPlain(*pubFile, *sigFile, *msgFile); err != nil {
+ return err
+ }
+ }
+ if !*quiet {
+ fmt.Println("Signature Verified")
+ }
+ return nil
+}
+
+func verifyPlain(pubFile, sigFile, msgFile string) error {
+ msg, err := ioutil.ReadFile(msgFile)
if err != nil {
return err
}
- if *pubFile == "" {
- *pubFile = verifyWith
- }
- pubKey, err := openPub(*pubFile)
+ sig, _, verifyWith, err := openSig(sigFile)
if err != nil {
return err
}
- if !*embedded {
- msg, err = ioutil.ReadFile(*msgFile)
- if err != nil {
- return err
- }
+ if pubFile == "" {
+ pubFile = verifyWith
}
- if err := sig.Verify(msg, pubKey); err != nil {
+ pub, err := openPub(pubFile)
+ if err != nil {
return err
}
- if !*quiet {
- fmt.Println("Signature Verified")
+ return sig.Verify(msg, pub)
+}
+
+func verifyEmbedded(pubFile, sigFile string) error {
+ sig, msg, verifyWith, err := openSig(sigFile)
+ if err != nil {
+ return err
+ }
+ if pubFile == "" {
+ pubFile = verifyWith
}
+ pub, err := openPub(pubFile)
+ if err != nil {
+ return err
+ }
+ return sig.Verify(msg, pub)
+}
+
+func verifyGzip(pubFile, msgFile string) error {
return nil
}
@@ -82,6 +114,6 @@ func openSig(fname string) (*key.Sig, []byte, string, error) {
if err := sig.Validate(); err != nil {
return nil, nil, "", err
}
- pubKey, _ := file.PubFile(comment)
+ pubKey := file.PubFile(comment)
return sig, msg, pubKey, nil
}