Commit 397ac7a
committed
Fixed leading null bytes being dropped by big-integer base codecs
The generic base_encode/base_decode convert the whole input to a single
integer, so leading null bytes (high-order zeros) were silently lost: e.g.
Base58 encoded b'\x00abc' to 'ZiCa' instead of '1ZiCa', and b'\x00' to an
empty string. Per the Base58 spec each leading 0x00 byte maps to a leading
charset[0] character. Preserve the leading-zero count on encode and restore
it on decode, so values round-trip and match reference implementations.1 parent 578f57d commit 397ac7a
2 files changed
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
133 | 137 | | |
134 | 138 | | |
135 | 139 | | |
| |||
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
154 | | - | |
| 158 | + | |
| 159 | + | |
155 | 160 | | |
156 | 161 | | |
157 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
176 | 184 | | |
177 | 185 | | |
178 | 186 | | |
| |||
0 commit comments