util: move ASSUAN serialization to break circular import

This commit is contained in:
Roman Zeyde
2018-03-11 15:05:54 +02:00
parent 92c352e860
commit 0699273d49
5 changed files with 32 additions and 15 deletions

View File

@@ -229,3 +229,11 @@ def which(cmd):
raise OSError('Cannot find {!r} in $PATH'.format(cmd))
log.debug('which %r => %r', cmd, full_path)
return full_path
def assuan_serialize(data):
"""Serialize data according to ASSUAN protocol (for GPG daemon communication)."""
for c in [b'%', b'\n', b'\r']:
escaped = '%{:02X}'.format(ord(c)).encode('ascii')
data = data.replace(c, escaped)
return data