File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
test/functional/test_framework Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 12
12
import struct
13
13
14
14
def bn_bytes (v , have_ext = False ):
15
+ """Return number of bytes in integer representation of v."""
15
16
ext = 0
16
17
if have_ext :
17
18
ext = 1
18
19
return (v .bit_length () + 7 ) // 8 + ext
19
20
20
21
def bn2bin (v ):
22
+ """Convert a number to a byte array."""
21
23
s = bytearray ()
22
24
i = bn_bytes (v )
23
25
while i > 0 :
@@ -26,6 +28,7 @@ def bn2bin(v):
26
28
return s
27
29
28
30
def bn2mpi (v ):
31
+ """Convert number to MPI format."""
29
32
have_ext = False
30
33
if v .bit_length () > 0 :
31
34
have_ext = (v .bit_length () & 0x07 ) == 0
@@ -47,11 +50,12 @@ def bn2mpi(v):
47
50
v_bin [0 ] |= 0x80
48
51
return s + ext + v_bin
49
52
50
- # bitcoin-specific little endian format, with implicit size
51
53
def mpi2vch (s ):
54
+ """Convert MPI format to bitcoin-specific little endian format, with implicit size."""
52
55
r = s [4 :] # strip size
53
56
r = r [::- 1 ] # reverse string, converting BE->LE
54
57
return r
55
58
56
59
def bn2vch (v ):
60
+ """Convert number to bitcoin-specific little endian format."""
57
61
return bytes (mpi2vch (bn2mpi (v )))
You can’t perform that action at this time.
0 commit comments