2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019-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/>.
32 "golang.org/x/crypto/blake2b"
36 pkgName, fn, fnHash, hasherName string,
37 hasher hash.Hash, digest []byte,
39 expected, err := os.ReadFile(fnHash)
43 fd, err := os.Open(fn)
45 if os.IsNotExist(err) {
50 _, err = io.Copy(hasher, bufio.NewReader(fd))
55 isEqual := bytes.Equal(hasher.Sum(digest[:0]), expected)
58 fmt.Println("GOOD", hasherName, pkgName)
61 fmt.Println("BAD", hasherName, pkgName)
65 func goodIntegrity() bool {
66 dirs, err := os.ReadDir(Root)
70 hasherSHA256 := sha256.New()
71 hasherBLAKE2b256 := blake2b256New()
72 digestSHA256 := make([]byte, sha256.Size)
73 digestBLAKE2b256 := make([]byte, blake2b.Size256)
76 for _, dir := range dirs {
77 files, err := os.ReadDir(filepath.Join(Root, dir.Name()))
81 for _, file := range files {
82 if strings.HasSuffix(file.Name(), "."+HashAlgoSHA256) {
83 pkgName = strings.TrimSuffix(file.Name(), "."+HashAlgoSHA256)
86 filepath.Join(Root, dir.Name(), pkgName),
87 filepath.Join(Root, dir.Name(), file.Name()),
88 "SHA256", hasherSHA256, digestSHA256,
94 if strings.HasSuffix(file.Name(), "."+HashAlgoBLAKE2b256) {
95 pkgName = strings.TrimSuffix(file.Name(), "."+HashAlgoBLAKE2b256)
98 filepath.Join(Root, dir.Name(), pkgName),
99 filepath.Join(Root, dir.Name(), file.Name()),
100 "BLAKE2b-256", hasherBLAKE2b256, digestBLAKE2b256,