diff --git a/trezor_agent/gpg/agent.py b/trezor_agent/gpg/agent.py index 9011fae..63cac3b 100644 --- a/trezor_agent/gpg/agent.py +++ b/trezor_agent/gpg/agent.py @@ -99,15 +99,6 @@ def pkdecrypt(keygrip, conn): return _serialize_point(shared_secret) -def iterlines(conn): - """Iterate over input, split by lines.""" - while True: - line = keyring.recvline(conn) - if line is None: - break - yield line - - def handle_connection(conn): """Handle connection from GPG binary using the ASSUAN protocol.""" keygrip = None @@ -116,7 +107,7 @@ def handle_connection(conn): version = keyring.gpg_version() keyring.sendline(conn, b'OK') - for line in iterlines(conn): + for line in keyring.iterlines(conn): parts = line.split(' ') command = parts[0] args = parts[1:] diff --git a/trezor_agent/gpg/keyring.py b/trezor_agent/gpg/keyring.py index f3e7a4f..1da9468 100644 --- a/trezor_agent/gpg/keyring.py +++ b/trezor_agent/gpg/keyring.py @@ -52,6 +52,15 @@ def recvline(sock): return result +def iterlines(conn): + """Iterate over input, split by lines.""" + while True: + line = recvline(conn) + if line is None: + break + yield line + + def unescape(s): """Unescape ASSUAN message (0xAB <-> '%AB').""" s = bytearray(s) diff --git a/trezor_agent/gpg/tests/test_keyring.py b/trezor_agent/gpg/tests/test_keyring.py index 53a7c86..ec24664 100644 --- a/trezor_agent/gpg/tests/test_keyring.py +++ b/trezor_agent/gpg/tests/test_keyring.py @@ -74,3 +74,9 @@ SETHASH 8 4141414141414141414141414141414141414141414141414141414141414141 SETKEYDESC Sign+a+new+TREZOR-based+subkey PKSIGN ''' + + +def test_iterlines(): + sock = FakeSocket() + sock.rx.write(b'foo\nbar\nxyz') + assert list(keyring.iterlines(sock)) == []