1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.
This commit is contained in:
Nicolas Braud-Santoni 2017-02-26 18:55:16 -05:00 committed by Brian Coca
parent 385f1d82dc
commit 680d61c609

View file

@ -147,20 +147,11 @@ def is_encrypted_file(file_obj, start_pos=0, count=-1):
current_position = file_obj.tell() current_position = file_obj.tell()
try: try:
file_obj.seek(start_pos) file_obj.seek(start_pos)
vaulttext = file_obj.read(count) return is_encrypted(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
finally: finally:
file_obj.seek(current_position) file_obj.seek(current_position)
return is_encrypted(b_vaulttext)
class VaultLib: class VaultLib: