Skip to content

Commit

Permalink
workshop
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Sep 29, 2023
1 parent 5c618a7 commit 4d2ccf7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InsType(IntEnum):
GET_APP_NAME = 0x04
GET_PUBLIC_KEY = 0x05
SIGN_TX = 0x06
GET_NONCE = 0x07

class Errors(IntEnum):
SW_DENY = 0x6985
Expand Down Expand Up @@ -71,6 +72,13 @@ def get_version(self) -> RAPDU:
p2=P2.P2_LAST,
data=b"")

def get_nonce(self) -> RAPDU:
return self.backend.exchange(cla=CLA,
ins=InsType.GET_NONCE,
p1=P1.P1_START,
p2=P2.P2_LAST,
data=b"")


def get_app_name(self) -> RAPDU:
return self.backend.exchange(cla=CLA,
Expand Down
5 changes: 5 additions & 0 deletions tests/application_client/boilerplate_response_unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def unpack_get_version_response(response: bytes) -> Tuple[int, int, int]:
major, minor, patch = unpack("BBB", response)
return (major, minor, patch)

def unpack_get_nonce_response(response: bytes) -> int:
assert len(response) == 1
return unpack("B", response)


# Unpack from response:
# response = format_id (1)
# app_name_raw_len (1)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_nonce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from application_client.boilerplate_command_sender import BoilerplateCommandSender
from application_client.boilerplate_response_unpacker import unpack_get_nonce_response

# In this test we check the behavior of the device when asked to provide a nonce
def test_nonce(backend):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
# Send the GET_VERSION instruction
rapdu = client.get_nonce()
# Use an helper to parse the response, assert the values
print(unpack_get_nonce_response(rapdu.data))

0 comments on commit 4d2ccf7

Please sign in to comment.