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:
parent
680d61c609
commit
f689cca0b8
1 changed files with 3 additions and 7 deletions
|
@ -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))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue