gpg: move 'iterlines' to keyring

This commit is contained in:
Roman Zeyde 2016-07-26 17:50:49 +03:00
parent 8a51099488
commit 295d52ef10
3 changed files with 16 additions and 10 deletions

View File

@ -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:]

View File

@ -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)

View File

@ -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)) == []