-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,47 @@ | ||
# go-checksums | ||
# go-checksums | ||
|
||
It's a small utlity used for getting checksum for any file! | ||
|
||
## Usage | ||
|
||
```bash | ||
go-checksums.exe -f, --file FILE | ||
``` | ||
|
||
## Demo | ||
|
||
```bash | ||
go run . --file test.txt | ||
Processing... | ||
|
||
MD5: | ||
04ff2868ab8b0fd8c5a7075e935b451c | ||
|
||
Sha1: | ||
319c41f3bc8e4c2df19d60ff04e5bac255e36ffe | ||
|
||
Sha224: | ||
60428e84740e0eafad716e063ac086cc65593bb88dece289600b5cd1 | ||
|
||
Sha256: | ||
b9bbd2bbe3fd9b9c2121ddfdfda6c068b87a0403672067baa0d4527d836552e7 | ||
|
||
Sum384: | ||
e06e912ca5b3c3546fd4df8142134817868abe4ab4e16c2f77c88a8da055720973975344622e0507bea48b5004cf46ec | ||
|
||
Sha512: | ||
f1f3a99cde58c1f59b56f707592f761e3f79f529be1e2d4b0c138f413482e83721e37ccf6760bb2661b45963b17b6d557f92fd1d3481c3351c34c7740c701559 | ||
|
||
SHA512_224: | ||
5af1c3f73f18b9849a3493677e39fedd4b98e380863d9ddeb07e5914 | ||
|
||
SHA512_256: | ||
49ecd0363616a4db7c3e36eb4a31e740cc0aad594076e0fac81a3739e1bc601b | ||
|
||
Finished in: 7.5266ms | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](https://github.com/go-nerds/go-checksums/blob/main/LICENSE). See the [LICENSE](https://github.com/go-nerds/go-checksums/blob/main/LICENSE) file for details. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"crypto/md5" | ||
"crypto/sha1" | ||
"crypto/sha256" | ||
"crypto/sha512" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/gookit/color" | ||
) | ||
|
||
func generateHashes(filePath string) error { | ||
|
||
file, err := os.Open(filePath) | ||
if err != nil { | ||
return errors.New("error in reading the file") | ||
} | ||
|
||
defer file.Close() | ||
|
||
stat, err := file.Stat() | ||
if err != nil { | ||
return errors.New("error returning the File Info") | ||
} | ||
|
||
bs := make([]byte, stat.Size()) | ||
_, err = bufio.NewReader(file).Read(bs) | ||
|
||
if err != nil && err != io.EOF { | ||
return errors.New("error in parsing the file") | ||
} | ||
|
||
color.Cyan.Println("MD5:") | ||
fmt.Printf("%x\n\n", md5.Sum(bs)) | ||
|
||
color.Cyan.Println("Sha1:") | ||
fmt.Printf("%x\n\n", sha1.Sum(bs)) | ||
|
||
color.Cyan.Println("Sha224:") | ||
fmt.Printf("%x\n\n", sha256.Sum224(bs)) | ||
|
||
color.Cyan.Println("Sha256:") | ||
fmt.Printf("%x\n\n", sha256.Sum256(bs)) | ||
|
||
color.Cyan.Println("Sum384:") | ||
fmt.Printf("%x\n\n", sha512.Sum384(bs)) | ||
|
||
color.Cyan.Println("Sha512:") | ||
fmt.Printf("%x\n\n", sha512.Sum512(bs)) | ||
|
||
color.Cyan.Println("SHA512_224:") | ||
fmt.Printf("%x\n\n", sha512.Sum512_224(bs)) | ||
|
||
color.Cyan.Println("SHA512_256:") | ||
fmt.Printf("%x\n\n", sha512.Sum512_256(bs)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module github.com/go-nerds/go-checksums | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/alexflint/go-arg v1.4.3 // indirect | ||
github.com/alexflint/go-scalar v1.1.0 // indirect | ||
github.com/gookit/color v1.5.3 // indirect | ||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo= | ||
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA= | ||
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM= | ||
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE= | ||
github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= | ||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= | ||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/alexflint/go-arg" | ||
"github.com/gookit/color" | ||
) | ||
|
||
type UserInput struct { | ||
File string `arg:"-f,required"` | ||
} | ||
|
||
func main() { | ||
|
||
userInput := UserInput{} | ||
arg.MustParse(&userInput) | ||
|
||
color.Yellowln("Processing...") | ||
start := time.Now() | ||
|
||
err := generateHashes(userInput.File) | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
duration := time.Since(start) | ||
color.Green.Println("Finished in:", duration) | ||
|
||
} |