Skip to content

Commit

Permalink
Merge pull request #36 from LedgerHQ/codeql-fixes
Browse files Browse the repository at this point in the history
Fix defects found by CodeQL
  • Loading branch information
jibeee authored Jun 30, 2022
2 parents c7ca048 + a7f821b commit 30146e5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ledgerwallet/transport/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def write(self, data: bytes):
raise NotImplementedError

@abstractmethod
def read(self) -> bytes:
def read(self, timeout: int = 0) -> bytes:
raise NotImplementedError

@abstractmethod
def exchange(self, data: bytes) -> bytes:
def exchange(self, data: bytes, timeout: int = 0) -> bytes:
raise NotImplementedError

@abstractmethod
Expand Down
13 changes: 3 additions & 10 deletions ledgerwallet/transport/hid.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import os
if os.getenv("LEDGERWALLET_HIDRAW", "").lower() in ["1", "true"]:
import hidraw as hid
else:
import hid
import hid

from .device import Device

Expand Down Expand Up @@ -72,14 +68,11 @@ def read(self, timeout: int = 1000) -> bytes:

def exchange(self, data: bytes, timeout: int = 1000):
self.write(data)
return self.read(timeout)
return self.read(timeout=timeout)

def close(self):
if self.opened:
try:
self.device.close()
except:
pass
self.device.close()
self.opened = False


Expand Down
4 changes: 2 additions & 2 deletions ledgerwallet/transport/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def write(self, data: bytes):
data_to_send = int.to_bytes(len(data), 4, "big") + data
self.socket.send(data_to_send)

def read(self) -> bytes:
def read(self, timeout: int = 0) -> bytes:
packet_len = int.from_bytes(self.socket.recv(4), "big")
return self.socket.recv(packet_len + 2)

def exchange(self, data: bytes):
def exchange(self, data: bytes, timeout: int = 0):
self.write(data)
return self.read()

Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

def read(rel_path):
here = path.abspath(path.dirname(__file__))
with codecs.open(path.join(here, rel_path), 'r') as fp:
with codecs.open(path.join(here, rel_path), "r") as fp:
return fp.read()


def get_version(rel_path):
for line in read(rel_path).splitlines():
if line.startswith('__version__'):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
else:
raise RuntimeError("Unable to find version string.")
if line.startswith("__version__"):
delimiter = '"' if '"' in line else "'"
return line.split(delimiter)[1]
raise RuntimeError("Unable to find version string.")


this_dir = path.abspath(path.dirname(__file__))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_parse(self):
self.assertEquals(Bip32Path.parse(v), k)

def test_parse_empty(self):
# not in sample as not the parse/build behavior is not symetrical
# not in sample as not the parse/build behavior is not symmetrical
self.assertEqual(Bip32Path.parse(bytes.fromhex("00")), str())

def test_build(self):
Expand Down

0 comments on commit 30146e5

Please sign in to comment.