From 56184a3d8c0c14b99bae1fb0ae9726b4be0f90e5 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 17:18:35 +0300 Subject: [PATCH 1/3] Python 3: avoid %-formatting of byte strings This is needed for Python 3.4 compatibility; Python 3.5 can use `b'%s\n' bytestring` again. --- lib/ansible/parsing/vault/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py index 62df9b8dd1e..c49decf4352 100644 --- a/lib/ansible/parsing/vault/__init__.py +++ b/lib/ansible/parsing/vault/__init__.py @@ -194,10 +194,12 @@ class VaultLib: if not self.cipher_name: raise AnsibleError("the cipher must be set before adding a header") - tmpdata = [b'%s\n' % b_data[i:i+80] for i in range(0, len(b_data), 80)] - tmpdata.insert(0, b'%s;%s;%s\n' % (b_HEADER, self.b_version, - to_bytes(self.cipher_name, errors='strict', encoding='utf-8'))) - tmpdata = b''.join(tmpdata) + header = b';'.join([b_HEADER, self.b_version, + to_bytes(self.cipher_name, errors='strict', encoding='utf-8')]) + tmpdata = [header] + tmpdata += [b_data[i:i+80] for i in range(0, len(b_data), 80)] + tmpdata += [b''] + tmpdata = b'\n'.join(tmpdata) return tmpdata @@ -422,7 +424,7 @@ class VaultAES: d = d_i = b'' while len(d) < key_length + iv_length: - text = b"%s%s%s" % (d_i, password, salt) + text = b''.join([d_i, password, salt]) d_i = to_bytes(md5(text).digest(), errors='strict') d += d_i @@ -568,7 +570,7 @@ class VaultAES256: # COMBINE SALT, DIGEST AND DATA hmac = HMAC.new(key2, cryptedData, SHA256) - message = b'%s\n%s\n%s' % (hexlify(salt), to_bytes(hmac.hexdigest()), hexlify(cryptedData)) + message = b''.join([hexlify(salt), b'\n', to_bytes(hmac.hexdigest()), b'\n', hexlify(cryptedData)]) message = hexlify(message) return message From bd83410bdb670604f6a2b620c626ff36aca93170 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 17:19:26 +0300 Subject: [PATCH 2/3] Enable unit tests on Python 3.4 in tox and Travis These now pass \o/ --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 72550f2ced9..53d8dd5e468 100644 --- a/tox.ini +++ b/tox.ini @@ -10,4 +10,4 @@ commands = py27: python -m compileall -fq -x 'test|samples' lib test contrib py{34,35}: python -m compileall -fq -x 'lib/ansible/module_utils|lib/ansible/modules' lib test contrib # Unittests need lots of work to make code python3 compatible - py{26,27,35}: make tests + py{26,27,34,35}: make tests From 98958ec990702511c1282fe944a81f828d78d3ba Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 17:39:27 +0300 Subject: [PATCH 3/3] Simplify join expression --- lib/ansible/parsing/vault/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py index c49decf4352..d106b72ed64 100644 --- a/lib/ansible/parsing/vault/__init__.py +++ b/lib/ansible/parsing/vault/__init__.py @@ -570,7 +570,7 @@ class VaultAES256: # COMBINE SALT, DIGEST AND DATA hmac = HMAC.new(key2, cryptedData, SHA256) - message = b''.join([hexlify(salt), b'\n', to_bytes(hmac.hexdigest()), b'\n', hexlify(cryptedData)]) + message = b'\n'.join([hexlify(salt), to_bytes(hmac.hexdigest()), hexlify(cryptedData)]) message = hexlify(message) return message