]> Sergey Matveev's repositories - meta4ra.git/commitdiff
Check size before hashing v0.6.0
authorSergey Matveev <stargrave@stargrave.org>
Sun, 3 Mar 2024 08:41:03 +0000 (11:41 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 3 Mar 2024 08:41:16 +0000 (11:41 +0300)
cmd/meta4-check/main.go
common.go

index 61b50486b1d6795d19920662568a36862aa885de..b807a26993c8b945b477ab63c72ea3ca8b9461ae 100644 (file)
@@ -90,6 +90,27 @@ and -extract-sig, then you can just specify empty ("") FILE.
                                bad = true
                        }
                }
+
+               fullPath := toCheck[f.Name]
+               if !(len(toCheck) == 0 || fullPath != "") {
+                       continue
+               }
+               if fullPath == "" {
+                       fullPath = f.Name
+               }
+               s, err := os.Stat(fullPath)
+               if err != nil {
+                       fmt.Println(err)
+                       bad = true
+                       continue
+               }
+               if uint64(s.Size()) != f.Size {
+                       fmt.Println("size mismatch",
+                               f.Name, "our:", s.Size(), "their:", f.Size)
+                       bad = true
+                       continue
+               }
+
                hasher := meta4ra.NewHasher(*hashes)
                var hashTheir string
                var hashName string
@@ -106,15 +127,11 @@ and -extract-sig, then you can just specify empty ("") FILE.
                                }
                        }
                }
-               log.Fatalln("no common hashes found for:", f.Name)
+               fmt.Println("no common hashes found for:", f.Name)
+               bad = true
+               continue
+
        HashFound:
-               fullPath := toCheck[f.Name]
-               if !(len(toCheck) == 0 || fullPath != "") {
-                       continue
-               }
-               if fullPath == "" {
-                       fullPath = f.Name
-               }
                fd, err := os.Open(fullPath)
                if err != nil {
                        fmt.Println("Error:", f.Name, err)
@@ -135,7 +152,7 @@ and -extract-sig, then you can just specify empty ("") FILE.
                        fmt.Println(f.Name, hashName, "good")
                } else {
                        fmt.Println(
-                               "Hash does not match:", f.Name, hashName,
+                               "hash mismatch:", f.Name, hashName,
                                "our:", hashOur,
                                "their:", hashTheir,
                        )
index 01bfa4f3a3f1010ad877f1365bf35dec445d69d2..5868c2c8d266421f88104da0833a812dad6aac33 100644 (file)
--- a/common.go
+++ b/common.go
@@ -17,7 +17,7 @@
 package meta4ra
 
 const (
-       Generator       = "meta4ra/0.5.0"
+       Generator       = "meta4ra/0.6.0"
        SigMediaTypePGP = "application/pgp-signature"
        SigMediaTypeSSH = "application/ssh-signature"
 )