1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-15 18:00:59 +00:00

revert bytes/str change in tools.py

This commit is contained in:
Pavol Rusnak 2017-12-19 16:10:37 +01:00
parent 8a37c28ed6
commit c550e5c703
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -22,6 +22,17 @@ import binascii
import struct
import sys
if sys.version_info < (3,):
def byteindex(data, index):
return ord(data[index])
def iterbytes(data):
return (ord(char) for char in data)
else:
def byteindex(data, index):
return data[index]
iterbytes = iter
def Hash(data):
return hashlib.sha256(hashlib.sha256(data).digest()).digest()
@ -41,8 +52,8 @@ def hash_160_to_bc_address(h160, address_type):
def compress_pubkey(public_key):
if public_key[0] == 4:
return bytes(public_key[64] & 1 + 2) + public_key[1:33]
if byteindex(public_key, 0) == 4:
return bytes((byteindex(public_key, 64) & 1) + 2) + public_key[1:33]
raise ValueError("Pubkey is already compressed")
@ -62,7 +73,7 @@ def b58encode(v):
""" encode v, which is a string of bytes, to base58."""
long_value = 0
for c in v:
for c in iterbytes(v):
long_value = long_value * 256 + c
result = ''
@ -75,7 +86,7 @@ def b58encode(v):
# Bitcoin does a little leading-zero-compression:
# leading 0-bytes in the input become leading-1s
nPad = 0
for c in v:
for c in iterbytes(v):
if c == 0:
nPad += 1
else: