trezor: refactor transport enumeration a bit

This commit is contained in:
Roman Zeyde 2018-03-03 18:14:43 +02:00
parent 66e3e60370
commit e90bd0cd81
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
3 changed files with 16 additions and 6 deletions

View File

@ -5,5 +5,10 @@
from keepkeylib.client import CallException, PinException
from keepkeylib.client import KeepKeyClient as Client
from keepkeylib.messages_pb2 import PassphraseAck, PinMatrixAck
from keepkeylib.transport_hid import HidTransport as Transport
from keepkeylib.transport_hid import HidTransport
from keepkeylib.types_pb2 import IdentityType
def enumerate_transports():
"""Returns USB HID transports."""
return [HidTransport(p) for p in HidTransport.enumerate()]

View File

@ -115,14 +115,14 @@ class Trezor(interface.Device):
current_version))
def connect(self):
"""Enumerate and connect to the first USB HID interface."""
transport = self._defs.TrezorDevice.enumerate()
if not transport:
"""Enumerate and connect to the first available interface."""
transports = self._defs.enumerate_transports()
if not transports:
raise interface.NotFoundError('{} not connected'.format(self))
log.debug('transports: %s', transport)
log.debug('transports: %s', transports)
for _ in range(5):
connection = self._defs.Client(transport[0])
connection = self._defs.Client(transports[0])
self._override_pin_handler(connection)
self._override_passphrase_handler(connection)
self._verify_version(connection)

View File

@ -6,3 +6,8 @@ from trezorlib.client import CallException, PinException
from trezorlib.client import TrezorClient as Client
from trezorlib.messages import IdentityType, PassphraseAck, PinMatrixAck
from trezorlib.device import TrezorDevice
def enumerate_transports():
"""Returns all available transports."""
return TrezorDevice.enumerate()