From 680d61c60985f7905242bc40273afdb967daa4a9 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Sun, 26 Feb 2017 18:55:16 -0500 Subject: [PATCH] vault: call is_encrypted directly in is_encrypted_file Doing the conversion and checking for exceptions there is pointless since is_encrypted already does it. --- lib/ansible/parsing/vault/__init__.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py index 9dba96d38a..4bfb75feca 100644 --- a/lib/ansible/parsing/vault/__init__.py +++ b/lib/ansible/parsing/vault/__init__.py @@ -147,20 +147,11 @@ def is_encrypted_file(file_obj, start_pos=0, count=-1): current_position = file_obj.tell() try: file_obj.seek(start_pos) - vaulttext = file_obj.read(count) - try: - b_vaulttext = to_bytes(to_text(vaulttext, encoding='ascii', errors='strict'), encoding='ascii', errors='strict') - except (UnicodeError, TypeError): - # At present, vault files contain only ascii characters. The encoding is utf-8 - # without BOM (for future expansion). If the header does not - # decode as ascii then we know we do not have proper vault - # encrypted data. - return False + return is_encrypted(file_obj.read(count)) + finally: file_obj.seek(current_position) - return is_encrypted(b_vaulttext) - class VaultLib: