Make use of the bytes function that supports both py2 and 3 (#48904)

This commit is contained in:
Tim Rupp 2018-11-19 15:24:31 -08:00 committed by GitHub
parent 9b0dd5224b
commit 7546ebf08e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -199,6 +199,8 @@ shell:
import os import os
import tempfile import tempfile
from ansible.module_utils._text import to_bytes
try: try:
from BytesIO import BytesIO from BytesIO import BytesIO
except ImportError: except ImportError:
@ -870,11 +872,11 @@ class RootUserManager(BaseManager):
def encrypt_password_change_file(self, public_key, password): def encrypt_password_change_file(self, public_key, password):
# This function call requires that the public_key be expressed in bytes # This function call requires that the public_key be expressed in bytes
pub = serialization.load_pem_public_key( pub = serialization.load_pem_public_key(
bytes(public_key, 'utf-8'), to_bytes(public_key),
backend=default_backend() backend=default_backend()
) )
message = bytes("{0}\n{0}\n".format(password), 'utf-8') message = to_bytes("{0}\n{0}\n".format(password))
ciphertext = pub.encrypt( ciphertext = pub.encrypt(
message, message,