1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-15 19:08:07 +00:00

common: HashWriter move to common

This commit is contained in:
Tomas Susanka 2017-12-22 15:41:25 +01:00
parent 1f677306a1
commit 19ef1480d8
4 changed files with 18 additions and 17 deletions

View File

@ -0,0 +1,16 @@
class HashWriter:
def __init__(self, hashfunc):
self.ctx = hashfunc()
self.buf = bytearray(1) # used in append()
def extend(self, buf: bytearray):
self.ctx.update(buf)
def append(self, b: int):
self.buf[0] = b
self.ctx.update(self.buf)
def getvalue(self) -> bytes:
return self.ctx.digest()

View File

@ -3,6 +3,7 @@ from trezor.messages.SignTx import SignTx
from trezor.messages import InputScriptType, FailureType
from apps.wallet.sign_tx.writers import *
from apps.common.hash_writer import HashWriter
class Bip143Error(ValueError):

View File

@ -16,6 +16,7 @@ from apps.wallet.sign_tx.segwit_bip143 import *
from apps.wallet.sign_tx.scripts import *
from apps.wallet.sign_tx.writers import *
from apps.wallet.sign_tx.tx_weight_calculator import *
from apps.common.hash_writer import HashWriter
# the number of bip32 levels used in a wallet (chain and address)
_BIP32_WALLET_DEPTH = const(2)

View File

@ -112,20 +112,3 @@ def get_tx_hash(w, double: bool, reverse: bool=False) -> bytes:
if reverse:
d = bytes(reversed(d))
return d
class HashWriter:
def __init__(self, hashfunc):
self.ctx = hashfunc()
self.buf = bytearray(1) # used in append()
def extend(self, buf: bytearray):
self.ctx.update(buf)
def append(self, b: int):
self.buf[0] = b
self.ctx.update(self.buf)
def getvalue(self) -> bytes:
return self.ctx.digest()