Exemple #1
0
def obj_sha(type, chunks):
    """Compute the SHA for a numeric type and object chunks."""
    sha = make_sha()
    sha.update(object_header(type, chunks_length(chunks)))
    for chunk in chunks:
        sha.update(chunk)
    return sha.digest()
Exemple #2
0
def iter_sha1(iter):
    """Return the hexdigest of the SHA1 over a set of names.

    :param iter: Iterator over string objects
    :return: 40-byte hex sha1 digest
    """
    sha1 = make_sha()
    for name in iter:
        sha1.update(name)
    return sha1.hexdigest()
Exemple #3
0
 def sha(self):
     """The SHA1 object that is the name of this object."""
     if self._sha is None or self._needs_serialization:
         # this is a local because as_raw_chunks() overwrites self._sha
         new_sha = make_sha()
         new_sha.update(self._header())
         for chunk in self.as_raw_chunks():
             new_sha.update(chunk)
         self._sha = new_sha
     return self._sha
Exemple #4
0
 def sha(self):
     """The SHA1 object that is the name of this object."""
     if self._sha is None or self._needs_serialization:
         # this is a local because as_raw_chunks() overwrites self._sha
         new_sha = make_sha()
         new_sha.update(self._header())
         for chunk in self.as_raw_chunks():
             new_sha.update(chunk)
         self._sha = new_sha
     return self._sha
Exemple #5
0
 def __init__(self, read_all, read_some=None):
     self.read_all = read_all
     if read_some is None:
         self.read_some = read_all
     else:
         self.read_some = read_some
     self.sha = make_sha()
     self._offset = 0
     self._rbuf = StringIO()
     # trailer is a deque to avoid memory allocation on small reads
     self._trailer = deque()
Exemple #6
0
    def calculate_checksum(self):
        """Calculate the checksum for this pack.

        :return: 20-byte binary SHA1 digest
        """
        s = make_sha()
        self._file.seek(0)
        todo = self._get_size() - 20
        while todo > 0:
            x = self._file.read(min(todo, 1<<16))
            s.update(x)
            todo -= len(x)
        return s.digest()
Exemple #7
0
    def calculate_checksum(self):
        """Calculate the SHA1 checksum over this pack index.

        :return: This is a 20-byte binary digest
        """
        return make_sha(self._contents[:-20]).digest()
Exemple #8
0
 def __init__(self, f):
     self.f = f
     self.sha1 = make_sha("")
Exemple #9
0
 def _make_sha(self):
     ret = make_sha()
     ret.update(self._header())
     for chunk in self.as_raw_chunks():
         ret.update(chunk)
     return ret
Exemple #10
0
 def _make_sha(self):
     ret = make_sha()
     ret.update(self._header())
     for chunk in self.as_raw_chunks():
         ret.update(chunk)
     return ret