Merge pull request #3 from aeternity/PT-162121241-fix-decoding-zeros

Correct decoding of binary full of zeros
This commit is contained in:
Tobias Lindahl 2018-11-21 14:46:41 +01:00 committed by GitHub
commit 60a335668a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -195,7 +195,10 @@ base58_to_integer([Char | Str]) ->
-spec base58_to_binary(base58()) -> binary().
base58_to_binary(Base58) ->
Bin = binary:encode_unsigned(base58_to_integer(Base58)),
Bin = case base58_to_integer(Base58) of
0 -> <<>>; %% Will be padded below
N -> binary:encode_unsigned(N)
end,
%The conversion between the binary and the integer strips any leading zero bytes that
% might have appeared in the binary - '0's' should be prepended to the binary stream for each
% 1 that appeared at the start of the base58 string.