paycheck: unit tests + fixes to checker module
This adds missing unit tests for the checker module, bundled with fixes
to some bugs that surfaced due to unit tests. This includes:
* A fake extent (signified by start_block == UINT64_MAX) that
accompanies a signature data blob bears different requirements than
previously implemented. Specifically, the extent sequence must have
exactly one extent; and the number of blocks is not necessarily one,
rather it is the correct number that corresponds to the actual length
of the signature blob.
* REPLACE/REPLACE_BZ operations must contain data.
* MOVE operation validation must ensure that all of the actual message
extents are being used.
* BSDIFF operation must contain data (the diff).
* Signature pseudo-operation should be a REPLACE.
BUG=chromium-os:34911,chromium-os:33607,chromium-os:7597
TEST=Passes unittests (upcoming); works with actual payloads.
Change-Id: I4d839d1d4da1fbb4a493b208958a139368e2c8ca
Reviewed-on: https://gerrit.chromium.org/gerrit/45429
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/scripts/update_payload/payload.py b/scripts/update_payload/payload.py
index 6dda644..dbb385a 100644
--- a/scripts/update_payload/payload.py
+++ b/scripts/update_payload/payload.py
@@ -19,7 +19,7 @@
# Helper functions.
#
def _ReadInt(file_obj, size, is_unsigned, hasher=None):
- """Read a binary-encoded integer from a file.
+ """Reads a binary-encoded integer from a file.
It will do the correct conversion based on the reported size and whether or
not a signed number is expected. Assumes a network (big-endian) byte
@@ -36,24 +36,8 @@
PayloadError if an read error occurred.
"""
- # Determine the base conversion format.
- if size == 2:
- fmt = 'h'
- elif size == 4:
- fmt = 'i'
- elif size == 8:
- fmt = 'q'
- else:
- raise PayloadError('unsupport numeric field size (%s)' % size)
-
- # Signed or unsigned?
- if is_unsigned:
- fmt = fmt.upper()
-
- # Our numeric values are in network byte order (big-endian).
- fmt = '!' + fmt
-
- return struct.unpack(fmt, common.Read(file_obj, size, hasher=hasher))[0]
+ return struct.unpack(common.IntPackingFmtStr(size, is_unsigned),
+ common.Read(file_obj, size, hasher=hasher))[0]
#