mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
python/debuglink: clean out debuglink methods
This commit is contained in:
parent
afeeafd5cd
commit
6069173252
@ -62,42 +62,27 @@ class DebugLink:
|
||||
obj = self._call(proto.DebugLinkGetState(wait_layout=True))
|
||||
return layout_lines(obj.layout_lines)
|
||||
|
||||
def read_pin(self):
|
||||
state = self.state()
|
||||
return state.pin, state.matrix
|
||||
|
||||
def read_pin_encoded(self):
|
||||
return self.encode_pin(*self.read_pin())
|
||||
state = self.state()
|
||||
return self.encode_pin(state.pin, state.matrix)
|
||||
|
||||
def encode_pin(self, pin, matrix=None):
|
||||
"""Transform correct PIN according to the displayed matrix."""
|
||||
if matrix is None:
|
||||
_, matrix = self.read_pin()
|
||||
matrix = self.state().matrix
|
||||
return "".join([str(matrix.index(p) + 1) for p in pin])
|
||||
|
||||
def read_mnemonic_secret(self):
|
||||
obj = self._call(proto.DebugLinkGetState())
|
||||
return obj.mnemonic_secret
|
||||
|
||||
def read_recovery_word(self):
|
||||
obj = self._call(proto.DebugLinkGetState())
|
||||
return (obj.recovery_fake_word, obj.recovery_word_pos)
|
||||
state = self.state()
|
||||
return (state.recovery_fake_word, state.recovery_word_pos)
|
||||
|
||||
def read_reset_word(self):
|
||||
obj = self._call(proto.DebugLinkGetState(wait_word_list=True))
|
||||
return obj.reset_word
|
||||
state = self._call(proto.DebugLinkGetState(wait_word_list=True))
|
||||
return state.reset_word
|
||||
|
||||
def read_reset_word_pos(self):
|
||||
obj = self._call(proto.DebugLinkGetState(wait_word_pos=True))
|
||||
return obj.reset_word_pos
|
||||
|
||||
def read_reset_entropy(self):
|
||||
obj = self._call(proto.DebugLinkGetState())
|
||||
return obj.reset_entropy
|
||||
|
||||
def read_passphrase_protection(self):
|
||||
obj = self._call(proto.DebugLinkGetState())
|
||||
return obj.passphrase_protection
|
||||
state = self._call(proto.DebugLinkGetState(wait_word_pos=True))
|
||||
return state.reset_word_pos
|
||||
|
||||
def input(self, word=None, button=None, swipe=None, x=None, y=None, wait=False):
|
||||
if not self.allow_interactions:
|
||||
|
@ -37,9 +37,9 @@ class TestDebuglink:
|
||||
resp = client.call_raw(messages.GetAddress())
|
||||
assert isinstance(resp, messages.PinMatrixRequest)
|
||||
|
||||
pin, matrix = client.debug.read_pin()
|
||||
assert pin == "1234"
|
||||
assert matrix != ""
|
||||
state = client.debug.state()
|
||||
assert state.pin == "1234"
|
||||
assert state.matrix != ""
|
||||
|
||||
pin_encoded = client.debug.read_pin_encoded()
|
||||
resp = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))
|
||||
|
@ -31,8 +31,7 @@ def _set_wipe_code(client, wipe_code):
|
||||
# Set/change wipe code.
|
||||
with client:
|
||||
if client.features.pin_protection:
|
||||
pin, _ = client.debug.read_pin()
|
||||
pins = [pin, wipe_code, wipe_code]
|
||||
pins = [client.debug.state().pin, wipe_code, wipe_code]
|
||||
pin_matrices = [
|
||||
messages.PinMatrixRequest(type=PinType.Current),
|
||||
messages.PinMatrixRequest(type=PinType.WipeCodeFirst),
|
||||
@ -66,8 +65,7 @@ def _change_pin(client, old_pin, new_pin):
|
||||
|
||||
def _check_wipe_code(client, wipe_code):
|
||||
"""Check that wipe code is set by changing the PIN to it."""
|
||||
old_pin, _ = client.debug.read_pin()
|
||||
f = _change_pin(client, old_pin, wipe_code)
|
||||
f = _change_pin(client, client.debug.state().pin, wipe_code)
|
||||
assert isinstance(f, messages.Failure)
|
||||
|
||||
|
||||
|
@ -79,7 +79,7 @@ class TestMsgRecoverydevice:
|
||||
|
||||
# Mnemonic is the same
|
||||
client.init_device()
|
||||
assert client.debug.read_mnemonic_secret() == MNEMONIC12.encode()
|
||||
assert client.debug.state().mnemonic_secret == MNEMONIC12.encode()
|
||||
|
||||
assert client.features.pin_protection is True
|
||||
assert client.features.passphrase_protection is True
|
||||
@ -131,7 +131,7 @@ class TestMsgRecoverydevice:
|
||||
|
||||
# Mnemonic is the same
|
||||
client.init_device()
|
||||
assert client.debug.read_mnemonic_secret() == MNEMONIC12.encode()
|
||||
assert client.debug.state().mnemonic_secret == MNEMONIC12.encode()
|
||||
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
|
@ -84,7 +84,7 @@ class TestMsgRecoverydeviceT2:
|
||||
|
||||
# Mnemonic is the same
|
||||
client.init_device()
|
||||
assert client.debug.read_mnemonic_secret() == MNEMONIC12.encode()
|
||||
assert client.debug.state().mnemonic_secret == MNEMONIC12.encode()
|
||||
|
||||
assert client.features.pin_protection is True
|
||||
assert client.features.passphrase_protection is True
|
||||
@ -140,7 +140,7 @@ class TestMsgRecoverydeviceT2:
|
||||
|
||||
# Mnemonic is the same
|
||||
client.init_device()
|
||||
assert client.debug.read_mnemonic_secret() == MNEMONIC12.encode()
|
||||
assert client.debug.state().mnemonic_secret == MNEMONIC12.encode()
|
||||
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
|
@ -63,7 +63,7 @@ def test_secret(client, shares, secret):
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
assert client.features.backup_type is messages.BackupType.Slip39_Advanced
|
||||
assert debug.read_mnemonic_secret().hex() == secret
|
||||
assert debug.state().mnemonic_secret.hex() == secret
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
|
@ -67,7 +67,7 @@ def test_secret(client, shares, secret):
|
||||
assert client.features.backup_type is messages.BackupType.Slip39_Basic
|
||||
|
||||
# Check mnemonic
|
||||
assert debug.read_mnemonic_secret().hex() == secret
|
||||
assert debug.state().mnemonic_secret.hex() == secret
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
|
@ -43,7 +43,7 @@ def reset_device(client, strength):
|
||||
|
||||
# Provide entropy
|
||||
assert isinstance(ret, proto.EntropyRequest)
|
||||
internal_entropy = client.debug.read_reset_entropy()
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
ret = client.call_raw(proto.EntropyAck(entropy=external_entropy))
|
||||
|
||||
# Generate mnemonic locally
|
||||
@ -142,7 +142,7 @@ class TestMsgResetDevice:
|
||||
|
||||
# Provide entropy
|
||||
assert isinstance(ret, proto.EntropyRequest)
|
||||
internal_entropy = client.debug.read_reset_entropy()
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
ret = client.call_raw(proto.EntropyAck(entropy=external_entropy))
|
||||
|
||||
# Generate mnemonic locally
|
||||
|
@ -48,7 +48,7 @@ class TestMsgResetDeviceSkipbackup:
|
||||
|
||||
# Provide entropy
|
||||
assert isinstance(ret, proto.EntropyRequest)
|
||||
internal_entropy = client.debug.read_reset_entropy()
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
ret = client.call_raw(proto.EntropyAck(entropy=self.external_entropy))
|
||||
assert isinstance(ret, proto.Success)
|
||||
|
||||
|
@ -33,14 +33,14 @@ class TestProtectCall:
|
||||
|
||||
def test_no_protection(self, client):
|
||||
with client:
|
||||
assert client.debug.read_pin()[0] is None
|
||||
assert client.debug.state().pin is None
|
||||
client.set_expected_responses([proto.Address()])
|
||||
self._some_protected_call(client)
|
||||
|
||||
@pytest.mark.setup_client(pin="1234")
|
||||
def test_pin(self, client):
|
||||
with client:
|
||||
assert client.debug.read_pin()[0] == "1234"
|
||||
assert client.debug.state().pin == "1234"
|
||||
client.set_expected_responses([proto.PinMatrixRequest(), proto.Address()])
|
||||
self._some_protected_call(client)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user