

def _download_log(self, log):
    ' Download a log, decompress, and compare SHA256 checksums'
    try:
        client = self.s3_client_provider.get_client(log['s3Bucket'])
        response = client.get_object(Bucket=log['s3Bucket'], Key=log['s3Object'])
        gzip_inflater = zlib.decompressobj((zlib.MAX_WBITS | 16))
        rolling_hash = hashlib.sha256()
        for chunk in iter((lambda : response['Body'].read(2048)), b''):
            data = gzip_inflater.decompress(chunk)
            rolling_hash.update(data)
        remaining_data = gzip_inflater.flush()
        if remaining_data:
            rolling_hash.update(remaining_data)
        computed_hash = rolling_hash.hexdigest()
        if (computed_hash != log['hashValue']):
            self._on_log_invalid(log)
        else:
            self._valid_logs += 1
            self._write_status(('Log file\ts3://%s/%s\tvalid' % (log['s3Bucket'], log['s3Object'])))
    except ClientError as e:
        if (e.response['Error']['Code'] != 'NoSuchKey'):
            raise
        self._on_missing_log(log)
    except Exception:
        self._on_invalid_log_format(log)

dataset/ETHPy150Open aws/aws-cli/awscli/customizations/cloudtrail/validation.py CloudTrailValidateLogs._download_log/original