Return sha256 string for group of FTP listings.
425613
def get_file_listing_sha(listing_paths: Iterable) -> str:
    """"""

    return sha256(''.join(sorted(listing_paths)).encode('utf-8')).hexdigest()
767526
def hash_file(path, block_size=65536):
    
    sha256 = hashlib.sha256()
    with open(path, 'rb') as f:
        for block in iter(lambda: f.read(block_size), b''):
            sha256.update(block)
    return sha256.hexdigest()
435507
def hash_str(data, hasher=None):
    """"""
    hasher = hasher or hashlib.sha1()
    hasher.update(data)
    return hasher
156470
def hash_contents(contents):
    
    assert isinstance(contents, GroupNode)

    result = hashlib.sha256()

    def _hash_int(value):
        result.update(struct.pack(">L", value))

    def _hash_str(string):
        assert isinstance(string, string_types)
        _hash_int(len(string))
        result.update(string.encode())

    def _hash_object(obj):
        _hash_str(obj.json_type)
        if isinstance(obj, (TableNode, FileNode)):
            hashes = obj.hashes
            _hash_int(len(hashes))
            for hval in hashes:
                _hash_str(hval)
        elif isinstance(obj, GroupNode):
            children = obj.children
            _hash_int(len(children))
            for key, child in sorted(iteritems(children)):
                _hash_str(key)
                _hash_object(child)
        else:
            assert False, "Unexpected object: %r" % obj

        # Backward compatibility: only hash metadata_hash if it's present.
        if obj.metadata_hash is not None:
            _hash_str(obj.metadata_hash)

    _hash_object(contents)

    return result.hexdigest()
140918
def sha256_file(path):
    
    h = hashlib.sha256()

    with open(path, 'rb') as f:
        for chunk in iter(lambda: f.read(CHUNK_SIZE), b''):
            h.update(chunk)

    return h.hexdigest()
872637
def hash(self, index_func=os.path.getmtime):
        
        # TODO alternative to filehash => mtime as a faster alternative
        shadir = hashlib.sha256()
        for f in self.files():
            try:
                shadir.update(str(index_func(os.path.join(self.path, f))))
            except (IOError, OSError):
                pass
        return shadir.hexdigest()
103075
def crypto_hash_sha256(message):
    
    digest = ffi.new("unsigned char[]", crypto_hash_sha256_BYTES)
    rc = lib.crypto_hash_sha256(digest, message, len(message))
    ensure(rc == 0,
           'Unexpected library error',
           raising=exc.RuntimeError)
    return ffi.buffer(digest, crypto_hash_sha256_BYTES)[:]
1297778
def getGroupsURL(certfile, group):
    """"""

    GMS = "https://" + _SERVER + _GMS

    certfile.seek(0)
    buf = certfile.read()

    x509 = crypto.load_certificate(crypto.FILETYPE_PEM, buf)
    sep = ""
    dn = ""
    parts = []
    for i in x509.get_issuer().get_components():
        #print i
        if i[0] in parts:
            continue
        parts.append(i[0])
        dn = i[0] + "=" + i[1] + sep + dn
        sep = ","

    return GMS + "/" + group + "/" + urllib.quote(dn)
71118
def sha1_of_file(filepath):
    
    import hashlib
    try:
        with open(filepath, 'rb') as file_to_hash:
            return hashlib.sha1(file_to_hash.read()).hexdigest()
    except:  # pylint: disable=bare-except
        return None
1271036
def _hash_of_file(path, algorithm):
    """"""
    with open(path, 'rb') as archive:
        hash = hashlib.new(algorithm)
        for chunk in read_chunks(archive):
            hash.update(chunk)
    return hash.hexdigest()
158121
def _get_url_hashes(path):
  """"""
  urls = _read_text_file(path)
  def url_hash(u):
    h = hashlib.sha1()
    try:
      u = u.encode('utf-8')
    except UnicodeDecodeError:
      logging.error('Cannot hash url: %s', u)
    h.update(u)
    return h.hexdigest()
  return {url_hash(u): True for u in urls}
918282
def get_hash(self, salt, plain_password):
        """"""
        return hashlib.sha256(salt.encode() + plain_password.encode()).hexdigest()
220073
def hash_file(filename):
    
    sha256 = hashlib.sha256()
    with open(filename, 'rb') as f:
        for chunk in iter(lambda: f.read(8192), b''):
            sha256.update(chunk)
    return 'sha256:' + sha256.hexdigest()
549170
def grab_checksums_file(entry):
    """"""
    http_url = convert_ftp_url(entry['ftp_path'])
    full_url = '{}/md5checksums.txt'.format(http_url)
    req = requests.get(full_url)
    return req.text
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')
1326278
def info_hash(self):
        """"""
        info = self._struct.get('info')

        if not info:
            return None

        return sha1(Bencode.encode(info)).hexdigest()
813883
def hash(filename):
    ''''''
    buffer_size = 10*1024*1024
    m = hashlib.md5()
    with open(filename) as f:
        buff = f.read(buffer_size)
        while len(buff)>0:
            m.update(buff)
            buff = f.read(buffer_size)
    dig = m.digest()
    return ''.join(['%x' % ord(x) for x in dig])