Skip to content

Commit

Permalink
More comments and more descriptive varnames
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed May 24, 2020
1 parent e2f3f8d commit 8405806
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions base58.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,24 @@ func FastBase58DecodingAlphabet(str string, alphabet *Alphabet) ([]byte, error)
mask = 32
}
mask -= 8
var j, cnt int
for j, cnt = 0, 0; j < len(outi); j++ {

outLen := 0
for j := 0; j < len(outi); j++ {
for mask < 32 { // loop relies on uint overflow
binu[cnt] = byte(outi[j] >> mask)
binu[outLen] = byte(outi[j] >> mask)
mask -= 8
cnt++
outLen++
}
mask = 24
}

for n := zcount; n < len(binu); n++ {
if binu[n] > 0 {
return binu[n-zcount : cnt], nil
// find the most significant byte post-decode, if any
for msb := zcount; msb < len(binu); msb++ {
if binu[msb] > 0 {
return binu[msb-zcount : outLen], nil
}
}
return binu[:cnt], nil

// it's all zeroes
return binu[:outLen], nil
}

0 comments on commit 8405806

Please sign in to comment.