From 4cbf388bc93b9ce946fe9f9dc13ef7a7ccd650dc Mon Sep 17 00:00:00 2001 From: Tobias Lindahl Date: Wed, 21 Nov 2018 14:25:52 +0100 Subject: [PATCH] Correct decoding of binary full of zeros --- src/base58.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/base58.erl b/src/base58.erl index d978b66..0d39fc4 100644 --- a/src/base58.erl +++ b/src/base58.erl @@ -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.