Ignore leading zeroes in hexToPaddedByteArray#86
Ignore leading zeroes in hexToPaddedByteArray#86etan-k wants to merge 3 commits intostatus-im:masterfrom
Conversation
When converting hex strings into fixed size byte arrays, the function `hexToPaddedByteArray` is commonly used to deal with the input data being shorter than the target buffer. However, the opposite case of the input data having extra leading zeroes leads to an error. This patch allows leading zeroes in `hexToPaddedByteArray`, ignoring them when the input string is longer than the destination array.
|
I noticed this limitation when using nim-blscurve to import a private key from the Ethereum 2.0 spec, i.e., https://github.com/ethereum/eth2.0-specs/blob/dev/tests/generators/bls/main.py#L45-L51 nim-blscurve's BLST |
|
So, the intention here is that you want to be able to decode a string such as "0x0000ffff" into a 3-element array and get the result |
|
Anytime a number is imported. The semantics are same regardless of number of leading zeroes. The function already does the opposite of padding with extra zeroes, e.g., passing "0xffff" to the 3-element array would also result in Example use case was given above, the Eth2 sample private keys contain a lot of extra zeroes, which does not make them invalid as it is still representing the same number, but putting them as is into the |
|
Interesting. Perhaps the name of the function should then reveal that a big endian number is being loaded. The name |
|
Well, |
When converting hex strings into fixed size byte arrays, the function
hexToPaddedByteArrayis commonly used to deal with the input databeing shorter than the target buffer. However, the opposite case of the
input data having extra leading zeroes leads to an error.
This patch allows leading zeroes in
hexToPaddedByteArray, ignoringthem when the input string is longer than the destination array.