This is an education project that attempts to reimplement the GNU coreutils in Go. You can find the full manual here:
https://www.gnu.org/software/coreutils/manual/coreutils.html
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
594 B
45 lines
594 B
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"flag"
|
|
"os"
|
|
"log"
|
|
"crypto/sha512"
|
|
)
|
|
|
|
type Opts struct {
|
|
Inputs []string
|
|
}
|
|
|
|
func ParseOpts() Opts {
|
|
var opts Opts
|
|
|
|
flag.Parse()
|
|
opts.Inputs = flag.Args()
|
|
|
|
return opts
|
|
}
|
|
|
|
func ToHex(hash [sha512.Size]byte) string {
|
|
result := ""
|
|
|
|
for _, b := range hash {
|
|
result += fmt.Sprintf("%x", b)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func main() {
|
|
opts := ParseOpts()
|
|
|
|
for _, fname := range opts.Inputs {
|
|
in_data, err := os.ReadFile(fname)
|
|
if err != nil { log.Fatal(err) }
|
|
|
|
hash := sha512.Sum512(in_data)
|
|
|
|
fmt.Println(ToHex(hash), fname)
|
|
}
|
|
}
|
|
|