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

vault: Uniformize construction of cipher objects

This commit is contained in:
Nicolas Braud-Santoni 2017-02-26 23:02:49 -05:00 committed by Brian Coca
parent 680d61c609
commit f689cca0b8

View file

@ -201,10 +201,9 @@ class VaultLib:
self.cipher_name = u"AES256" self.cipher_name = u"AES256"
try: try:
Cipher = CIPHER_MAPPING[self.cipher_name] this_cipher = CIPHER_MAPPING[self.cipher_name]()
except KeyError: except KeyError:
raise AnsibleError(u"{0} cipher could not be found".format(self.cipher_name)) raise AnsibleError(u"{0} cipher could not be found".format(self.cipher_name))
this_cipher = Cipher()
# encrypt data # encrypt data
b_ciphertext = this_cipher.encrypt(b_plaintext, self.b_password) b_ciphertext = this_cipher.encrypt(b_plaintext, self.b_password)
@ -238,11 +237,8 @@ class VaultLib:
b_vaulttext = self._split_header(b_vaulttext) b_vaulttext = self._split_header(b_vaulttext)
# create the cipher object # create the cipher object
cipher_class_name = u'Vault{0}'.format(self.cipher_name) if self.cipher_name in CIPHER_WHITELIST:
this_cipher = CIPHER_MAPPING[self.cipher_name]()
if cipher_class_name in globals() and self.cipher_name in CIPHER_WHITELIST:
Cipher = globals()[cipher_class_name]
this_cipher = Cipher()
else: else:
raise AnsibleError("{0} cipher could not be found".format(self.cipher_name)) raise AnsibleError("{0} cipher could not be found".format(self.cipher_name))