diff options
author | Gilad Arnold <garnold@chromium.org> | 2013-03-08 13:22:31 -0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-04-05 17:02:56 -0700 |
commit | 5502b56f34f9703cf053be46e4ea5685c0c9ac26 (patch) | |
tree | 5d1eb5c4d0fb8016ae03698d5a89451fcde5bde7 /scripts/update_payload/payload.py | |
parent | 857223b4118d7b4d9bd988d996db00d7ea313029 (diff) |
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>
Diffstat (limited to 'scripts/update_payload/payload.py')
-rw-r--r-- | scripts/update_payload/payload.py | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/scripts/update_payload/payload.py b/scripts/update_payload/payload.py index 6dda644a..dbb385a1 100644 --- a/scripts/update_payload/payload.py +++ b/scripts/update_payload/payload.py @@ -19,7 +19,7 @@ import update_metadata_pb2 # 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 @@ def _ReadInt(file_obj, size, is_unsigned, hasher=None): 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] # |