Revision 7301127c

b/pithos/api/util.py
48 48
from django.core.files.uploadedfile import UploadedFile
49 49

  
50 50
from pithos.lib.compat import parse_http_date_safe, parse_http_date
51
from pithos.lib.hashmap import HashMap
51 52

  
52 53
from pithos.api.faults import (Fault, NotModified, BadRequest, Unauthorized, Forbidden, ItemNotFound,
53 54
                                Conflict, LengthRequired, PreconditionFailed, RequestEntityTooLarge,
......
742 743
def hashmap_hash(request, hashmap):
743 744
    """Produce the root hash, treating the hashmap as a Merkle-like tree."""
744 745
    
745
    def subhash(d):
746
        h = hashlib.new(request.backend.hash_algorithm)
747
        h.update(d)
748
        return h.digest()
749
    
750
    if len(hashmap) == 0:
751
        return hexlify(subhash(''))
752
    if len(hashmap) == 1:
753
        return hashmap[0]
754
    
755
    s = 2
756
    while s < len(hashmap):
757
        s = s * 2
758
    h = [unhexlify(x) for x in hashmap]
759
    h += [('\x00' * len(h[0]))] * (s - len(hashmap))
760
    while len(h) > 1:
761
        h = [subhash(h[x] + h[x + 1]) for x in range(0, len(h), 2)]
762
    return hexlify(h[0])
746
    map = HashMap(request.backend.block_size, request.backend.hash_algorithm)
747
    map.extend([unhexlify(x) for x in hashmap])
748
    return hexlify(map.hash())
763 749

  
764 750
def update_request_headers(request):
765 751
    # Handle URL-encoded keys and values.

Also available in: Unified diff