summaryrefslogtreecommitdiff
path: root/python/helpers.py
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-21 16:04:16 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-21 16:04:16 +0100
commitaaf0d2c49f343e909dc69b487056ca31238ffabf (patch)
tree9e054a390aad0be8f2acec8a77de3a7e97d881ba /python/helpers.py
parent57952a7dd9d9c586dcac84e46987d15d49674774 (diff)
downloadlilliput-ae-implem-aaf0d2c49f343e909dc69b487056ca31238ffabf.tar.xz
[implem-python] Nettoyage PEP8
- espaces avant ':' - espaces en trop après ',' - parenthèses dans les if - levée d'exception plutôt que 'return None' implicite Simplification de genkat_aead.py grâce à l'exception levée par le module.
Diffstat (limited to 'python/helpers.py')
-rw-r--r--python/helpers.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/python/helpers.py b/python/helpers.py
index 45c48c9..b02bea4 100644
--- a/python/helpers.py
+++ b/python/helpers.py
@@ -2,20 +2,20 @@ from constants import BLOCK_BITS, BLOCK_BYTES
from lilliput_tbc import LilliputTBCEnc
-def ArrayToBlockbytesMatrix(array) :
+def ArrayToBlockbytesMatrix(array):
length = len(array)
pad = 0
- if(length % BLOCK_BYTES == 0) :
+ if length % BLOCK_BYTES == 0:
number_blocks = int(length / BLOCK_BYTES)
- else :
+ else:
number_blocks = int((length + (BLOCK_BYTES - (length % BLOCK_BYTES))) / BLOCK_BYTES)
pad = 1
matrix = [[0] * BLOCK_BYTES for block in range(0, number_blocks - pad)]
- if(pad == 1) :
+ if pad == 1:
matrix.append([0] * (length % BLOCK_BYTES))
- for byte in range(0, length) :
+ for byte in range(0, length):
matrix[int(byte / BLOCK_BYTES)][byte % BLOCK_BYTES] = array[byte]
return matrix
@@ -85,3 +85,16 @@ def BuildAuth(t, A, key):
Auth = XorState(Auth, enc)
return Auth
+
+
+class TagValidationError(Exception):
+ def __init__(self, announced, computed):
+ msg = '\n'.join((
+ 'Invalid tag:',
+ announced.hex().upper()+' (announced)',
+ computed.hex().upper()+' (computed)'
+ ))
+
+ super().__init__(msg)
+ self._announced = announced
+ self._computed = computed