Progress reporter for checksum verification.
778755
def progress_updater(size, total):
    """"""
    current_task.update_state(
        state=state('PROGRESS'),
        meta=dict(size=size, total=total)
    )
824994
def checksums(self, install):
        
        check_md5(pkg_checksum(install, self.repo), self.tmp_path + install)
354315
def valid_checksum(file, hash_file):
    
    bits = 4096
    # calc md5 hash
    hash_md5 = hashlib.md5()
    with open(file, "rb") as f:
        for chunk in iter(lambda: f.read(bits), b""):
            hash_md5.update(chunk)
    # locate hash signature for file, validate
    with open(hash_file) as c:
        for line in c.readlines():
            if line.strip():
                check_list = line.split()
                if file == check_list[1]:
                    if check_list[0] == hash_md5.hexdigest():
                        return True
    return False
1281777
def checksum(self, path, hashtype='sha1'):
        """"""
        return self._handler.checksum(hashtype, posix_path(path))
684625
def get_checksum(self, encoder=base64.b64encode, hasher=hashlib.sha256):
        """"""
        assert self._closed, "Archive not closed"
        with open(self._temp_archive_file.name, 'rb') as fh:
            return encoder(checksum(fh, hasher())).decode('ascii')
1039028
def verify_checksum(*lines):
    
    for line in lines:
        checksum = line[68:69]
        if not checksum.isdigit():
            continue
        checksum = int(checksum)
        computed = compute_checksum(line)
        if checksum != computed:
            complaint = ('TLE line gives its checksum as {}'
                         ' but in fact tallies to {}:\n{}')
            raise ValueError(complaint.format(checksum, computed, line))
1221904
function computeChecksums(out, filenames) {
	var result = {};
	filenames.forEach(function (filename) {
		var fullPath = path.join(process.cwd(), out, filename);
		result[filename] = computeChecksum(fullPath);
	});
	return result;
}
396950
def _checksum(self):
        """"""
        for line in [self._line1, self._line2]:
            check = 0
            for char in line[:-1]:
                if char.isdigit():
                    check += int(char)
                if char == "-":
                    check += 1

            if (check % 10) != int(line[-1]):
                raise ChecksumError(self._platform + " " + line)
103570
function checkSum(buffer, offset, length) {
            if (buffer instanceof ArrayBuffer) {
                return checkSumArrayBuffer(buffer, offset, length);
            }
            else if (buffer instanceof Array) {
                return checkSumArray(buffer, offset, length);
            }

            throw new Error('not support checksum buffer type');
        }
1013073
def main():
    
    # vars
    tar_file = TMPDIR + '/' + BINARY_URL.split('/')[-1]
    chksum = TMPDIR + '/' + MD5_URL.split('/')[-1]
    # pre-run validation + execution
    if precheck() and os_packages(distro.linux_distribution()):
        stdout_message('begin download')
        download()
        stdout_message('begin valid_checksum')
        valid_checksum(tar_file, chksum)
        return compile_binary(tar_file)
    logger.warning('%s: Pre-run dependency check fail - Exit' % inspect.stack()[0][3])
    return False
630806
def file_checksum(fname):
    
    size = os.path.getsize(fname)
    with open(fname, "r+") as f:
        checksum = hashlib.md5(mmap.mmap(f.fileno(), size)).hexdigest()
    return checksum
748719
def old_checksum(self):
        """"""
        if self.context.is_file(self.checksum_file):
            logger.debug("Reading saved checksum from %s ..", format_path(self.checksum_file))
            checksum = self.context.read_file(self.checksum_file).decode('ascii')
            logger.debug("Saved checksum is %s.", checksum)
            return checksum
1135743
function validateChecksum(fileName, checksum, cb) {
   if (isUndefined(checksum) || isUndefined(checksum.hashAlgorithm)) {
      cb();
      return;
   }

   if (isUndefined(checksum.inline) || isUndefined(checksum.inline.value)) {
      cb(new Error('Installed jobs agent only supports inline checksum value provided in job document'));
      return;
   }

   var hash;
   try {
      hash = crypto.createHash(checksum.hashAlgorithm);
   } catch (err) {
      cb(new Error('Unsupported checksum hash algorithm: ' + checksum.hashAlgorithm));
      return;
   }

   var stream = fs.createReadStream(fileName);

   stream.on('data', function (data) {
      hash.update(data, 'utf8');
   }).on('end', function () {
      if (hash.digest('hex') !== checksum.inline.value) {
         var err = new Error('Checksum mismatch');
         err.fileName = fileName;
         cb(err);
      } else {
         cb();
      }
   }).on('error', function (err) {
      err.fileName = fileName;
      cb(err);
   });
}
1090144
def _checksum_paths():
  """"""
  dataset2path = {}
  for dir_path in _CHECKSUM_DIRS:
    for fname in _list_dir(dir_path):
      if not fname.endswith(_CHECKSUM_SUFFIX):
        continue
      fpath = os.path.join(dir_path, fname)
      dataset_name = fname[:-len(_CHECKSUM_SUFFIX)]
      dataset2path[dataset_name] = fpath
  return dataset2path
1070442
private static int computeChecksum(byte[] buf, int offset, int length, String channel) {
        Hasher hasher = Hashing.murmur3_32().newHasher();
        hasher.putBytes(buf, offset, length);
        hasher.putUnencodedChars(channel);
        return hasher.hash().asInt() & 0xffff;
    }
974913
def _do_watch_progress(filename, sock, handler):
    """"""
    connection, client_address = sock.accept()
    data = b''
    try:
        while True:
            more_data = connection.recv(16)
            if not more_data:
                break
            data += more_data
            lines = data.split(b'\n')
            for line in lines[:-1]:
                line = line.decode()
                parts = line.split('=')
                key = parts[0] if len(parts) > 0 else None
                value = parts[1] if len(parts) > 1 else None
                handler(key, value)
            data = lines[-1]
    finally:
        connection.close()
1290704
def parse_checksums(checksums_string):
    """"""
    checksums_list = []
    for line in checksums_string.split('\n'):
        try:
            # skip empty lines
            if line == '':
                continue

            checksum, filename = line.split()
            # strip leading ./
            if filename.startswith('./'):
                filename = filename[2:]
            checksums_list.append({'checksum': checksum, 'file': filename})
        except ValueError:
            logging.debug('Skipping over unexpected checksum line %r', line)
            continue

    return checksums_list