diff options
author | John Newbery <john@johnnewbery.com> | 2019-10-30 10:39:15 -0400 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2019-10-30 10:53:19 -0400 |
commit | f950ec25201e8ff7948be99ce3171f9700c4a8dc (patch) | |
tree | 77f9baa6ab542cc79570d29961602cbed5c5a683 /test/functional/test_framework/bignum.py | |
parent | 3b9b38579c59d5b31bd75103618776eafc05c132 (diff) | |
download | bitcoin-f950ec25201e8ff7948be99ce3171f9700c4a8dc.tar.xz |
[tests] remove bn2bin()
It's only called in one place.
Diffstat (limited to 'test/functional/test_framework/bignum.py')
-rw-r--r-- | test/functional/test_framework/bignum.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/test/functional/test_framework/bignum.py b/test/functional/test_framework/bignum.py index c34704aa0c..529d39c420 100644 --- a/test/functional/test_framework/bignum.py +++ b/test/functional/test_framework/bignum.py @@ -9,29 +9,29 @@ endian format. This file is copied from python-bitcoinlib. """ -def bn2bin(v): - """Convert a number to a byte array.""" - s = bytearray() - bytes_len = (v.bit_length() + 7) // 8 - for i in range(bytes_len, 0, -1): - s.append((v >> ((i - 1) * 8)) & 0xff) - return s - def bn2mpi(v): """Convert number to MPI format, without the sign byte.""" + # The top bit is used to indicate the sign of the number. If there + # isn't a spare bit in the bit length, add an extension byte. have_ext = False + ext = bytearray() if v.bit_length() > 0: have_ext = (v.bit_length() & 0x07) == 0 + ext.append(0) + # Is the number negative? neg = False if v < 0: neg = True v = -v - ext = bytearray() - if have_ext: - ext.append(0) - v_bin = bn2bin(v) + # Convert the int to bytes + v_bin = bytearray() + bytes_len = (v.bit_length() + 7) // 8 + for i in range(bytes_len, 0, -1): + v_bin.append((v >> ((i - 1) * 8)) & 0xff) + + # Add the sign bit if necessary if neg: if have_ext: ext[0] |= 0x80 |