return false by default

This commit is contained in:
AJ ONeal 2020-08-25 23:24:49 -06:00
parent bf5d18e73a
commit 1369d91375
1 changed files with 7 additions and 6 deletions

View File

@ -216,6 +216,10 @@ func (h *Hashcash) Verify(subject string) error {
} }
func verifyBits(hash []byte, bits, n int) bool { func verifyBits(hash []byte, bits, n int) bool {
if 0 == bits {
return true
}
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
if bits > 8 { if bits > 8 {
bits -= 8 bits -= 8
@ -227,17 +231,14 @@ func verifyBits(hash []byte, bits, n int) bool {
// (bits % 8) == bits // (bits % 8) == bits
pad := 8 - bits pad := 8 - bits
if 0 != hash[i]>>pad { if 0 == hash[i]>>pad {
return true
}
}
return false return false
} }
return true
}
// 0 == bits
return true
}
// Solve will search for a solution, returning an error if the difficulty is // Solve will search for a solution, returning an error if the difficulty is
// above the local or global MaxDifficulty, the Algorithm is unsupported. // above the local or global MaxDifficulty, the Algorithm is unsupported.
func (h *Hashcash) Solve(maxDifficulty int) error { func (h *Hashcash) Solve(maxDifficulty int) error {