2 meta4a -- Metalink 4.0 checker
3 Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Metalink 4.0 checker
32 "go.stargrave.org/meta4ra"
36 hashes := flag.String("hashes", strings.Join(meta4ra.HashesDefault, ","), "hash-name:command-s")
37 extractSig := flag.Bool("extract-sig", false, "Extract signature files")
38 log.SetFlags(log.Lshortfile)
41 for _, metaPath := range flag.Args() {
42 data, err := os.ReadFile(metaPath)
46 var meta meta4ra.Metalink
47 err = xml.Unmarshal(data, &meta)
51 for _, f := range meta.Files {
52 for _, sig := range f.Signature {
57 switch sig.MediaType {
58 case meta4ra.SigMediaTypePGP:
60 case meta4ra.SigMediaTypeSSH:
66 if err = os.WriteFile(
68 []byte(strings.TrimPrefix(sig.Signature, "\n")),
71 fmt.Println("Error:", f.Name, "can not save signature:", err)
75 hasher := meta4ra.NewHasher(*hashes)
78 for i, name := range hasher.Names {
79 for _, h := range f.Hashes {
81 hasher.Names = []string{name}
82 hasher.Cmds = append(hasher.Cmds[:0], hasher.Cmds[i])
83 hasher.Ins = append(hasher.Ins[:0], hasher.Ins[i])
84 hasher.Outs = append(hasher.Outs[:0], hasher.Outs[i])
91 log.Fatalln("no common hashes found for:", f.Name)
93 fd, err := os.Open(f.Name)
98 _, err = io.Copy(hasher, bufio.NewReaderSize(fd, 1<<20))
100 sums := hasher.Sums()
102 fmt.Println("Error:", f.Name, err)
106 hashOur := sums[0].Hash
107 if hashOur == hashTheir {
108 fmt.Println(f.Name, hashName, "good")
111 "Hash does not match:", f.Name, hashName,