/* godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server Copyright (C) 2021-2023 Sergey Matveev 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 . */ package meta4 import ( "encoding/hex" "encoding/xml" ) type ForHTTP struct { SHA256 []byte SHA512 []byte Streebog256 []byte Streebog512 []byte SHAKE128 []byte SHAKE256 []byte URLs []string } func Parse(fn string, data []byte) (*ForHTTP, error) { var meta Metalink err := xml.Unmarshal(data, &meta) if err != nil { return nil, err } for _, f := range meta.Files { if f.Name != fn { continue } forHTTP := ForHTTP{} for _, h := range f.Hashes { 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 case HashStreebog256: forHTTP.Streebog256 = digest case HashStreebog512: forHTTP.Streebog512 = digest case HashSHAKE128: forHTTP.SHAKE128 = digest case HashSHAKE256: forHTTP.SHAKE256 = digest } } for _, u := range f.URLs { forHTTP.URLs = append(forHTTP.URLs, u.URL) } return &forHTTP, nil } return nil, nil }