12bde8e466a4451c7319e3a072d118917957d6554Steve Block#!/usr/bin/env python 22bde8e466a4451c7319e3a072d118917957d6554Steve Block# Copyright (c) 2011 Google Inc. All rights reserved. 32bde8e466a4451c7319e3a072d118917957d6554Steve Block# 42bde8e466a4451c7319e3a072d118917957d6554Steve Block# Redistribution and use in source and binary forms, with or without 52bde8e466a4451c7319e3a072d118917957d6554Steve Block# modification, are permitted provided that the following conditions are 62bde8e466a4451c7319e3a072d118917957d6554Steve Block# met: 72bde8e466a4451c7319e3a072d118917957d6554Steve Block# 82bde8e466a4451c7319e3a072d118917957d6554Steve Block# * Redistributions of source code must retain the above copyright 92bde8e466a4451c7319e3a072d118917957d6554Steve Block# notice, this list of conditions and the following disclaimer. 102bde8e466a4451c7319e3a072d118917957d6554Steve Block# * Redistributions in binary form must reproduce the above 112bde8e466a4451c7319e3a072d118917957d6554Steve Block# copyright notice, this list of conditions and the following disclaimer 122bde8e466a4451c7319e3a072d118917957d6554Steve Block# in the documentation and/or other materials provided with the 132bde8e466a4451c7319e3a072d118917957d6554Steve Block# distribution. 142bde8e466a4451c7319e3a072d118917957d6554Steve Block# * Neither the name of Google Inc. nor the names of its 152bde8e466a4451c7319e3a072d118917957d6554Steve Block# contributors may be used to endorse or promote products derived from 162bde8e466a4451c7319e3a072d118917957d6554Steve Block# this software without specific prior written permission. 172bde8e466a4451c7319e3a072d118917957d6554Steve Block# 182bde8e466a4451c7319e3a072d118917957d6554Steve Block# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 192bde8e466a4451c7319e3a072d118917957d6554Steve Block# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 202bde8e466a4451c7319e3a072d118917957d6554Steve Block# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 212bde8e466a4451c7319e3a072d118917957d6554Steve Block# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 222bde8e466a4451c7319e3a072d118917957d6554Steve Block# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 232bde8e466a4451c7319e3a072d118917957d6554Steve Block# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 242bde8e466a4451c7319e3a072d118917957d6554Steve Block# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 252bde8e466a4451c7319e3a072d118917957d6554Steve Block# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 262bde8e466a4451c7319e3a072d118917957d6554Steve Block# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 272bde8e466a4451c7319e3a072d118917957d6554Steve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 282bde8e466a4451c7319e3a072d118917957d6554Steve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292bde8e466a4451c7319e3a072d118917957d6554Steve Block 302bde8e466a4451c7319e3a072d118917957d6554Steve Block 312bde8e466a4451c7319e3a072d118917957d6554Steve Blockdef read_checksum(filehandle): 322bde8e466a4451c7319e3a072d118917957d6554Steve Block # We expect the comment to be at the beginning of the file. 332bde8e466a4451c7319e3a072d118917957d6554Steve Block data = filehandle.read(2048) 342bde8e466a4451c7319e3a072d118917957d6554Steve Block comment_key = 'tEXtchecksum\x00' 352bde8e466a4451c7319e3a072d118917957d6554Steve Block comment_pos = data.find(comment_key) 362bde8e466a4451c7319e3a072d118917957d6554Steve Block if comment_pos == -1: 372bde8e466a4451c7319e3a072d118917957d6554Steve Block return 382bde8e466a4451c7319e3a072d118917957d6554Steve Block 392bde8e466a4451c7319e3a072d118917957d6554Steve Block checksum_pos = comment_pos + len(comment_key) 402bde8e466a4451c7319e3a072d118917957d6554Steve Block return data[checksum_pos:checksum_pos + 32] 41