From 32f1d35c93483c50dad95e630946269aa5beb94c Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 17:14:57 -0400 Subject: [PATCH] byte2int for PY3 --- jrnl/Journal.py | 2 +- jrnl/util.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 4fdffa14..bd1eab52 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -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 diff --git a/jrnl/util.py b/jrnl/util.py index 3a92f0e4..315666b3 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -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 +