Exemplo n.º 1
0
def compute_hash(data, size):
    """
    compute hash of storage item's data file, return hexdigest
    """
    hasher = hash_new()
    offset = 0
    while offset < size:
        buf = data.read(SIZE, offset)
        offset += len(buf)
        hasher.update(buf)
    return hasher.hexdigest()
Exemplo n.º 2
0
def compute_hash(data, size):
    """
    compute hash of storage item's data file, return hexdigest
    """
    hasher = hash_new()
    offset = 0
    while offset < size:
        buf = data.read(SIZE, offset)
        offset += len(buf)
        hasher.update(buf)
    return hasher.hexdigest()
    def to_native(self, value, context=None):
        value = super(HashType, self).to_native(value, context)

        if ':' not in value:
            raise ValidationError(self.messages['hash_invalid'])

        hash_type, hash_value = value.split(':', 1)

        if hash_type not in algorithms:
            raise ValidationError(self.messages['hash_invalid'])

        if len(hash_value) != hash_new(hash_type).digest_size * 2:
            raise ValidationError(self.messages['hash_length'])
        try:
            int(hash_value, 16)
        except ValueError:
            raise ConversionError(self.messages['hash_hex'])
        return value
Exemplo n.º 4
0
    def to_native(self, value, context=None):
        value = super(HashType, self).to_native(value, context)

        if ':' not in value:
            raise ValidationError(self.messages['hash_invalid'])

        hash_type, hash_value = value.split(':', 1)

        if hash_type not in algorithms:
            raise ValidationError(self.messages['hash_invalid'])

        if len(hash_value) != hash_new(hash_type).digest_size * 2:
            raise ValidationError(self.messages['hash_length'])
        try:
            int(hash_value, 16)
        except ValueError:
            raise ConversionError(self.messages['hash_hex'])
        return value
Exemplo n.º 5
0
def hash160(payload: bytes) -> bytes:
    return hash_new('ripemd160', sha256(payload).digest()).digest()
Exemplo n.º 6
0
def h160(inp):
    h1 = sha256(inp).digest()
    return hash_new('ripemd160', h1).digest()
Exemplo n.º 7
0
def h160(inp):
    h1 = sha256(inp).digest()
    return hash_new('ripemd160', h1).digest()