2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019-2021 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/>.
33 "golang.org/x/crypto/blake2b"
37 pkgName, fn, fnHash, hasherName string,
38 hasher hash.Hash, digest []byte,
40 expected, err := ioutil.ReadFile(fnHash)
44 fd, err := os.Open(fn)
46 if os.IsNotExist(err) {
51 _, err = io.Copy(hasher, bufio.NewReader(fd))
56 isEqual := bytes.Compare(hasher.Sum(digest[:0]), expected) == 0
59 fmt.Println("GOOD", hasherName, pkgName)
62 fmt.Println("BAD", hasherName, pkgName)
66 func goodIntegrity() bool {
67 dirs, err := ioutil.ReadDir(Root)
71 hasherSHA256 := sha256.New()
72 hasherBLAKE2b256 := blake2b256New()
73 digestSHA256 := make([]byte, sha256.Size)
74 digestBLAKE2b256 := make([]byte, blake2b.Size256)
77 for _, dir := range dirs {
78 files, err := ioutil.ReadDir(filepath.Join(Root, dir.Name()))
82 for _, file := range files {
83 if strings.HasSuffix(file.Name(), "."+HashAlgoSHA256) {
84 pkgName = strings.TrimSuffix(file.Name(), "."+HashAlgoSHA256)
87 filepath.Join(Root, dir.Name(), pkgName),
88 filepath.Join(Root, dir.Name(), file.Name()),
89 "SHA256", hasherSHA256, digestSHA256,
95 if strings.HasSuffix(file.Name(), "."+HashAlgoBLAKE2b256) {
96 pkgName = strings.TrimSuffix(file.Name(), "."+HashAlgoBLAKE2b256)
99 filepath.Join(Root, dir.Name(), pkgName),
100 filepath.Join(Root, dir.Name(), file.Name()),
101 "BLAKE2b-256", hasherBLAKE2b256, digestBLAKE2b256,