From a9b588a8d5888b555f831b87ff7bab426b732b5d Mon Sep 17 00:00:00 2001 From: sewn Date: Tue, 30 Jan 2024 21:32:29 +0300 Subject: [PATCH] roblox/bootstrapper: move util md5 verify internal --- roblox/bootstrapper/package.go | 25 +++++++++++++++++++++++-- util/md5.go | 30 ------------------------------ 2 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 util/md5.go diff --git a/roblox/bootstrapper/package.go b/roblox/bootstrapper/package.go index 2a61204d..e39df86d 100644 --- a/roblox/bootstrapper/package.go +++ b/roblox/bootstrapper/package.go @@ -1,8 +1,12 @@ package bootstrapper import ( + "crypto/md5" + "encoding/hex" "fmt" + "io" "log" + "os" "github.com/vinegarhq/vinegar/util" ) @@ -21,8 +25,20 @@ type Packages []Package func (p *Package) Verify(src string) error { log.Printf("Verifying Package %s (%s)", p.Name, p.Checksum) - if err := util.VerifyFileMD5(src, p.Checksum); err != nil { - return fmt.Errorf("verify package %s: %w", p.Name, err) + f, err := os.Open(src) + if err != nil { + return err + } + defer f.Close() + + h := md5.New() + if _, err := io.Copy(h, f); err != nil { + return err + } + fsum := hex.EncodeToString(h.Sum(nil)) + + if p.Checksum != fsum { + return fmt.Errorf("package %s (%s) is corrupted, please re-download or delete package", p.Name, src) } return nil @@ -64,3 +80,8 @@ func (p *Package) Extract(src, dest string) error { log.Printf("Extracted Package %s (%s): %s", p.Name, p.Checksum, dest) return nil } + +func verifyFileMD5(name string, sum string) error { + + return nil +} diff --git a/util/md5.go b/util/md5.go deleted file mode 100644 index abae8932..00000000 --- a/util/md5.go +++ /dev/null @@ -1,30 +0,0 @@ -package util - -import ( - "crypto/md5" - "encoding/hex" - "fmt" - "io" - "os" -) - -// VerifyFileMD5 checks the named file with the named MD5 checksum. -func VerifyFileMD5(name string, sum string) error { - f, err := os.Open(name) - if err != nil { - return err - } - defer f.Close() - - h := md5.New() - if _, err := io.Copy(h, f); err != nil { - return err - } - fsum := hex.EncodeToString(h.Sum(nil)) - - if sum != fsum { - return fmt.Errorf("file %s has checksum mismatch", name) - } - - return nil -}