import pytest from ragger.error import ExceptionRAPDU from application_client.handshake_command_sender import CLA, Errors, InsType, P1, P2 def test_bad_cla(backend): with pytest.raises(ExceptionRAPDU) as e: backend.exchange(cla=CLA + 1, ins=InsType.GET_VERSION) assert e.value.status == Errors.SW_CLA_NOT_SUPPORTED @pytest.mark.parametrize("ins", [0x00, 0x02, 0x08, 0xFF]) def test_bad_ins(backend, ins): with pytest.raises(ExceptionRAPDU) as e: backend.exchange(cla=CLA, ins=ins) assert e.value.status == Errors.SW_INS_NOT_SUPPORTED @pytest.mark.parametrize("ins,p1,p2", [ (InsType.GET_VERSION, 0x01, 0x00), (InsType.GET_VERSION, 0x00, 0x80), (InsType.GET_APP_NAME, 0x01, 0x00), (InsType.GET_PUBLIC_KEY, 0x02, 0x00), (InsType.GET_PUBLIC_KEY, 0x00, 0x01), (InsType.SIGN_TX, 0x05, 0x00), # no such SIGN_TX sub-op (InsType.SIGN_TX, P1.SIGN_BEGIN, 0x80), (InsType.SIGN_TX, P1.SIGN_REVIEW, 0x80), (InsType.SIGN_MESSAGE, 0x01, 0x00), ]) def test_wrong_p1p2(backend, ins, p1, p2): with pytest.raises(ExceptionRAPDU) as e: backend.exchange(cla=CLA, ins=ins, p1=p1, p2=p2) assert e.value.status == Errors.SW_WRONG_P1P2