Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 4899828

Browse files
committed
fix segfault using encode/decode hex functions
1 parent 32c492d commit 4899828

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

ethereum/keys.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import pbkdf2
33
import sys
44

5+
from rlp.utils import encode_hex, decode_hex
6+
57
try:
68
scrypt = __import__('scrypt')
79
except ImportError:
@@ -225,16 +227,6 @@ def zpad(x, l):
225227

226228
if sys.version_info.major == 2:
227229

228-
def decode_hex(s):
229-
if not isinstance(s, (str, unicode)):
230-
raise TypeError('Value must be an instance of str or unicode')
231-
return s.decode('hex')
232-
233-
def encode_hex(s):
234-
if not isinstance(s, (str, unicode)):
235-
raise TypeError('Value must be an instance of str or unicode')
236-
return encode_hex(s)
237-
238230
def int_to_big_endian(value):
239231
cs = []
240232
while value > 0:
@@ -254,20 +246,6 @@ def big_endian_to_int(value):
254246

255247
if sys.version_info.major == 3:
256248

257-
def decode_hex(s):
258-
if isinstance(s, str):
259-
return bytes.fromhex(s)
260-
if isinstance(s, bytes):
261-
return binascii.unhexlify(s)
262-
raise TypeError('Value must be an instance of str or bytes')
263-
264-
def encode_hex(b):
265-
if isinstance(b, str):
266-
b = bytes(b, 'utf-8')
267-
if isinstance(b, bytes):
268-
return binascii.hexlify(b)
269-
raise TypeError('Value must be an instance of str or bytes')
270-
271249
def int_to_big_endian(value):
272250
byte_length = ceil(value.bit_length() / 8)
273251
return (value).to_bytes(byte_length, byteorder='big')

0 commit comments

Comments
 (0)