1 // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server
2 // Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 var KnownHashes = map[string]string{
24 "blake3-256": "BLAKE3-256",
25 "blake2b-512": "BLAKE2b-512",
26 "blake2b-256": "BLAKE2b-256",
29 "shake128": "SHAKE128",
30 "shake256": "SHAKE256",
31 "skein-256": "Skein-256",
32 "skein-512": "Skein-512",
33 "streebog-256": "Streebog-256",
34 "streebog-512": "Streebog-512",
35 "xxh3-128": "XXH3-128",
39 Hashes map[string][]byte
44 func Parse(fn string, data []byte) (*ForHTTP, error) {
46 err := xml.Unmarshal(data, &meta)
50 for _, f := range meta.Files {
54 forHTTP := ForHTTP{Hashes: make(map[string][]byte)}
55 for _, h := range f.Hashes {
56 name := KnownHashes[h.Type]
60 digest, err := hex.DecodeString(h.Hash)
64 forHTTP.Hashes[name] = digest
66 for _, u := range f.URLs {
67 forHTTP.URLs = append(forHTTP.URLs, u.URL)
69 for _, m := range f.MetaURLs {
70 if m.MediaType == "torrent" {
71 forHTTP.Torrents = append(forHTTP.Torrents, m.URL)