Python 3: avoid %-formatting of byte strings
This is needed for Python 3.4 compatibility; Python 3.5 can use `b'%s\n' bytestring` again.
This commit is contained in:
parent
89b0c3f6c4
commit
56184a3d8c
1 changed files with 8 additions and 6 deletions
|
@ -194,10 +194,12 @@ class VaultLib:
|
||||||
if not self.cipher_name:
|
if not self.cipher_name:
|
||||||
raise AnsibleError("the cipher must be set before adding a header")
|
raise AnsibleError("the cipher must be set before adding a header")
|
||||||
|
|
||||||
tmpdata = [b'%s\n' % b_data[i:i+80] for i in range(0, len(b_data), 80)]
|
header = b';'.join([b_HEADER, self.b_version,
|
||||||
tmpdata.insert(0, b'%s;%s;%s\n' % (b_HEADER, self.b_version,
|
to_bytes(self.cipher_name, errors='strict', encoding='utf-8')])
|
||||||
to_bytes(self.cipher_name, errors='strict', encoding='utf-8')))
|
tmpdata = [header]
|
||||||
tmpdata = b''.join(tmpdata)
|
tmpdata += [b_data[i:i+80] for i in range(0, len(b_data), 80)]
|
||||||
|
tmpdata += [b'']
|
||||||
|
tmpdata = b'\n'.join(tmpdata)
|
||||||
|
|
||||||
return tmpdata
|
return tmpdata
|
||||||
|
|
||||||
|
@ -422,7 +424,7 @@ class VaultAES:
|
||||||
|
|
||||||
d = d_i = b''
|
d = d_i = b''
|
||||||
while len(d) < key_length + iv_length:
|
while len(d) < key_length + iv_length:
|
||||||
text = b"%s%s%s" % (d_i, password, salt)
|
text = b''.join([d_i, password, salt])
|
||||||
d_i = to_bytes(md5(text).digest(), errors='strict')
|
d_i = to_bytes(md5(text).digest(), errors='strict')
|
||||||
d += d_i
|
d += d_i
|
||||||
|
|
||||||
|
@ -568,7 +570,7 @@ class VaultAES256:
|
||||||
|
|
||||||
# COMBINE SALT, DIGEST AND DATA
|
# COMBINE SALT, DIGEST AND DATA
|
||||||
hmac = HMAC.new(key2, cryptedData, SHA256)
|
hmac = HMAC.new(key2, cryptedData, SHA256)
|
||||||
message = b'%s\n%s\n%s' % (hexlify(salt), to_bytes(hmac.hexdigest()), hexlify(cryptedData))
|
message = b''.join([hexlify(salt), b'\n', to_bytes(hmac.hexdigest()), b'\n', hexlify(cryptedData)])
|
||||||
message = hexlify(message)
|
message = hexlify(message)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue