v1.1.1
This commit is contained in:
committed by
GitHub
parent
f4aae0093c
commit
d786e7aa81
@@ -19,7 +19,6 @@ var (
|
|||||||
bits = flag.Int("b", 256, "Bits: 224, 256, 384 and 512.")
|
bits = flag.Int("b", 256, "Bits: 224, 256, 384 and 512.")
|
||||||
check = flag.String("c", "", "Check hashsum file.")
|
check = flag.String("c", "", "Check hashsum file.")
|
||||||
recursive = flag.Bool("r", false, "Process directories recursively.")
|
recursive = flag.Bool("r", false, "Process directories recursively.")
|
||||||
verbose = flag.Bool("v", false, "Verbose mode. (The exit code is always 0 in this mode)")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -150,17 +149,18 @@ func main() {
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
txtlines = append(txtlines, scanner.Text())
|
txtlines = append(txtlines, scanner.Text())
|
||||||
}
|
}
|
||||||
|
var exit int
|
||||||
for _, eachline := range txtlines {
|
for _, eachline := range txtlines {
|
||||||
lines := strings.Split(string(eachline), " *")
|
lines := strings.Split(string(eachline), " *")
|
||||||
if strings.Contains(string(eachline), " *") {
|
if strings.Contains(string(eachline), " *") {
|
||||||
var h hash.Hash
|
var h hash.Hash
|
||||||
if *bits == 224 {
|
if len(lines[0])*4 == 224 {
|
||||||
h = sha3.New224()
|
h = sha3.New224()
|
||||||
} else if *bits == 256 {
|
} else if len(lines[0])*4 == 256 {
|
||||||
h = sha3.New256()
|
h = sha3.New256()
|
||||||
} else if *bits == 384 {
|
} else if len(lines[0])*4 == 384 {
|
||||||
h = sha3.New384()
|
h = sha3.New384()
|
||||||
} else if *bits == 512 {
|
} else if len(lines[0])*4 == 512 {
|
||||||
h = sha3.New512()
|
h = sha3.New512()
|
||||||
}
|
}
|
||||||
_, err := os.Stat(lines[1])
|
_, err := os.Stat(lines[1])
|
||||||
@@ -172,26 +172,18 @@ func main() {
|
|||||||
io.Copy(h, f)
|
io.Copy(h, f)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
if *verbose {
|
if hex.EncodeToString(h.Sum(nil)) == lines[0] {
|
||||||
if hex.EncodeToString(h.Sum(nil)) == lines[0] {
|
fmt.Println(lines[1]+"\t", "OK")
|
||||||
fmt.Println(lines[1]+"\t", "OK")
|
|
||||||
} else {
|
|
||||||
fmt.Println(lines[1]+"\t", "FAILED")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if hex.EncodeToString(h.Sum(nil)) == lines[0] {
|
fmt.Println(lines[1]+"\t", "FAILED")
|
||||||
} else {
|
exit = 1
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if *verbose {
|
fmt.Println(lines[1]+"\t", "Not found!")
|
||||||
fmt.Println(lines[1]+"\t", "Not found!")
|
exit = 1
|
||||||
} else {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
os.Exit(exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user