Skip to content

Commit

Permalink
backend: Add optional tick_timeout argument to exchange functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Feb 15, 2024
1 parent 15a3774 commit 04752ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/ragger/backend/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ def receive(self) -> RAPDU:
"""
raise NotImplementedError

def exchange(self, cla: int, ins: int, p1: int = 0, p2: int = 0, data: bytes = b"") -> RAPDU:
def exchange(self,
cla: int,
ins: int,
p1: int = 0,
p2: int = 0,
data: bytes = b"",
tick_timeout: int = 5 * 60 * 10) -> RAPDU:
"""
Formats and sends an APDU to the backend, then receives its response.
Expand All @@ -181,10 +187,10 @@ def exchange(self, cla: int, ins: int, p1: int = 0, p2: int = 0, data: bytes = b
:return: The APDU response
:rtype: RAPDU
"""
return self.exchange_raw(pack_APDU(cla, ins, p1, p2, data))
return self.exchange_raw(pack_APDU(cla, ins, p1, p2, data), tick_timeout)

@abstractmethod
def exchange_raw(self, data: bytes = b"") -> RAPDU:
def exchange_raw(self, data: bytes = b"", tick_timeout: int = 5 * 60 * 10) -> RAPDU:
"""
Sends the given APDU to the backend, then receives its response.
Expand Down
4 changes: 2 additions & 2 deletions src/ragger/backend/speculos.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def receive(self) -> RAPDU:
return result

@raise_policy_enforcer
def exchange_raw(self, data: bytes = b"") -> RAPDU:
def exchange_raw(self, data: bytes = b"", tick_timeout: int = 5 * 60 * 10) -> RAPDU:
self.apdu_logger.info("=> %s", data.hex())
return RAPDU(0x9000, self._client._apdu_exchange(data))
return RAPDU(0x9000, self._client._apdu_exchange(data, tick_timeout))

@raise_policy_enforcer
def _get_last_async_response(self, response) -> RAPDU:
Expand Down
2 changes: 1 addition & 1 deletion src/ragger/backend/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def send_raw(self, data: bytes = b""):
def receive(self) -> RAPDU:
return RAPDU(0x9000, b"")

def exchange_raw(self, data: bytes = b"") -> RAPDU:
def exchange_raw(self, data: bytes = b"", tick_timeout: int = 5 * 60 * 10) -> RAPDU:
return RAPDU(0x9000, b"")

@contextmanager
Expand Down

0 comments on commit 04752ad

Please sign in to comment.