byte2int for PY3

This commit is contained in:
Manuel Ebert 2014-04-16 17:14:57 -04:00
parent 8b7a37a196
commit 32f1d35c93
2 changed files with 8 additions and 1 deletions

View file

@ -67,7 +67,7 @@ class Journal(object):
util.prompt("ERROR: Your journal file seems to be corrupted. You do have a backup, don't you?")
sys.exit(1)
padding_length = ord(plain[-1])
padding_length = util.byte2int(plain[-1])
if padding_length > AES.block_size and padding_length != 32:
# 32 is the space character and is kept for backwards compatibility
return None

View file

@ -145,3 +145,10 @@ def int2byte(i):
"""Converts an integer to a byte.
This is equivalent to chr() in Python 2 and bytes((i,)) in Python 3."""
return chr(i) if PY2 else bytes((i,))
def byte2int(b):
"""Converts a byte to an integer.
This is equivalent to ord(bs[0]) on Python 2 and bs[0] on Python 3."""
return ord(b)if PY2 else b