]> Sergey Matveev's repositories - godlighty.git/blobdiff - meta4/parse.go
More known hashes, sync with meta4ra
[godlighty.git] / meta4 / parse.go
index bc839452d975dea050c7faeae64634ef57fef6d0..bd9ef3613db62b6328cfbc7c80ec9420a8869d3d 100644 (file)
@@ -1,19 +1,17 @@
-/*
-godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server
-Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server
+// Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package meta4
 
@@ -22,10 +20,25 @@ import (
        "encoding/xml"
 )
 
+var KnownHashes = map[string]string{
+       "blake3-256":   "BLAKE3-256",
+       "blake2b-512":  "BLAKE2b-512",
+       "blake2b-256":  "BLAKE2b-256",
+       "sha-256":      "SHA-256",
+       "sha-512":      "SHA-512",
+       "shake128":     "SHAKE128",
+       "shake256":     "SHAKE256",
+       "skein-256":    "Skein-256",
+       "skein-512":    "Skein-512",
+       "streebog-256": "Streebog-256",
+       "streebog-512": "Streebog-512",
+       "xxh3-128":     "XXH3-128",
+}
+
 type ForHTTP struct {
-       SHA256 []byte
-       SHA512 []byte
-       URLs   []string
+       Hashes   map[string][]byte
+       URLs     []string
+       Torrents []string
 }
 
 func Parse(fn string, data []byte) (*ForHTTP, error) {
@@ -38,22 +51,26 @@ func Parse(fn string, data []byte) (*ForHTTP, error) {
                if f.Name != fn {
                        continue
                }
-               forHTTP := ForHTTP{}
+               forHTTP := ForHTTP{Hashes: make(map[string][]byte)}
                for _, h := range f.Hashes {
+                       name := KnownHashes[h.Type]
+                       if name == "" {
+                               continue
+                       }
                        digest, err := hex.DecodeString(h.Hash)
                        if err != nil {
                                return nil, err
                        }
-                       switch h.Type {
-                       case HashSHA256:
-                               forHTTP.SHA256 = digest
-                       case HashSHA512:
-                               forHTTP.SHA512 = digest
-                       }
+                       forHTTP.Hashes[name] = digest
                }
                for _, u := range f.URLs {
                        forHTTP.URLs = append(forHTTP.URLs, u.URL)
                }
+               for _, m := range f.MetaURLs {
+                       if m.MediaType == "torrent" {
+                               forHTTP.Torrents = append(forHTTP.Torrents, m.URL)
+                       }
+               }
                return &forHTTP, nil
        }
        return nil, nil