Commit 843c33d5 authored by ale's avatar ale

Make pwgen.py work with both python2 and python3

parent e8a3d3d9
......@@ -58,7 +58,7 @@ def encrypt(data, dst):
p = subprocess.Popen(
['ansible-vault', 'encrypt', '--output=' + dst, '-'],
stdin=subprocess.PIPE)
p.communicate(data)
p.communicate(data.encode())
rc = p.wait()
if rc != 0:
raise Exception('ansible-vault encrypt error')
......@@ -71,7 +71,7 @@ def generate_simple_password(length=32):
cut&pastable and usable on the command line.
"""
n = int(length * 5 / 8)
return base64.b32encode(os.urandom(n)).rstrip('=')
return base64.b32encode(os.urandom(n)).rstrip('='.encode())
def generate_binary_secret(length=32):
......@@ -84,7 +84,7 @@ def generate_binary_secret(length=32):
"""
n = int(length * 3 / 4)
return base64.b64encode(os.urandom(n)).rstrip('=')
return base64.b64encode(os.urandom(n)).rstrip('='.encode())
def generate_tsig_key():
......@@ -103,6 +103,7 @@ def generate_tsig_key():
'/usr/sbin/dnssec-keygen', '-a', 'HMAC-SHA512', '-b', '512',
'-n', 'USER', '-r', '/dev/urandom', '-K', tmp_dir, 'pwgen',
]).strip()
base = base.decode()
result = {'algo': 'HMAC-SHA512'}
with open(os.path.join(tmp_dir, base + '.key')) as fd:
result['public'] = fd.read().split()[7]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment