From 295d52ef10811589df03793391cd6fdd450608e7 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 26 Jul 2016 17:50:49 +0300 Subject: [PATCH] gpg: move 'iterlines' to keyring --- trezor_agent/gpg/agent.py | 11 +---------- trezor_agent/gpg/keyring.py | 9 +++++++++ trezor_agent/gpg/tests/test_keyring.py | 6 ++++++ 3 files changed, 16 insertions(+), 10 deletions(-) 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)) == []