def test_rt_image_invalid_hab_encrypt_app_data(): bimg = BootImgRT(address=0x1) with pytest.raises(SPSDKError, match="Nonce is not present"): bimg._hab_encrypt_app_data(app_data=bytes(16)) bimg = BootImgRT(address=0x1) bimg._nonce = bytes(16) with pytest.raises(SPSDKError, match="Invalid length of application data"): bimg._hab_encrypt_app_data(app_data=bytes(15)) bimg = BootImgRT(address=0x1) bimg._dek_key = None bimg._nonce = bytes(16) with pytest.raises(SPSDKError, match="DEK key is not present"): bimg._hab_encrypt_app_data(app_data=bytes(16))
def test_rt_image_invalid(): with pytest.raises(SPSDKError, match="Invalid IVT offset"): BootImgRT(address=0x1, offset=16) with pytest.raises(SPSDKError, match="Invalid version"): BootImgRT(address=0x1, version=0x44) with pytest.raises(SPSDKError, match="Plugin is not supported"): BootImgRT(address=0x1, plugin=True) bimg = BootImgRT(address=0x1) with pytest.raises(SPSDKError, match="Invalid length of DEK key"): bimg.dek_key = bytes(15) with pytest.raises(SPSDKError, match="Invalid IVT offset"): bimg.ivt_offset = 15 bimg = BootImgRT(address=0x1) bimg._dek_key = bytes(15) bimg.hab_encrypted csf = SegCSF(enabled=True) csf.append_command( CmdWriteData(ops=EnumWriteOps.WRITE_VALUE, data=[(0x30340004, 0x4F400005)])) with pytest.raises(SPSDKError, match="Nonce not present"): bimg.csf = csf bimg._nonce = bytes(15) with pytest.raises(SPSDKError, match="Mac not present"): bimg.csf = csf