Exemple #1
0
    def verify(self):
        """Verifies that the MAC stored in this node is correct,
        assuming that left/right have correct MACs; also verifies the
        BST property."""
        mac = setmac.compress(self.tree.key2, {self.value: self.row_key})
        
        if self.left:
            assert(self.left.key < self.key)
            mac = setmac.xor_hashes(mac, setmac.extract_compressed_MAC(self.tree.key1, self.left.mac))
            
        if self.right:
            assert(not (self.right.key < self.key))
            mac = setmac.xor_hashes(mac, setmac.extract_compressed_MAC(self.tree.key1, self.right.mac))

        assert(setmac.extract_compressed_MAC(self.tree.key1, self.mac) == mac)
Exemple #2
0
    def update_hook(self):
        """Rehashes child nodes."""
        mac = setmac.compress(self.tree.key2, {self.value: self.row_key})

        if self.left:
            mac = setmac.xor_hashes(mac, setmac.extract_compressed_MAC(self.tree.key1, self.left.mac))
            
        if self.right:
            mac = setmac.xor_hashes(mac, setmac.extract_compressed_MAC(self.tree.key1, self.right.mac))

        self.mac = setmac.encrypt_compressed_MAC(self.tree.key1, mac)

        left_id = self.left_id if self.left_id else -1
        right_id = self.right_id if self.right_id else -1

        c = self.tree.local_conn.cursor()
        c.execute("UPDATE %s SET left = ?, right = ?, mac = ? WHERE row_id = ?" % self.tree.table_name,
                  (left_id, right_id,
                   setmac.marshall_MAC(self.mac), self.value))
        self.tree.conn.commit()
        #self.tree.transaction.commit_unless_managed()
        c.close()
Exemple #3
0
    def verify(self, resultset, rmin, rmax, include_rmin=True, include_rmax=True):
        self.check_root()

        compressed_value = self.range_compressed_MAC(rmin, rmax, include_rmin, include_rmax)
        obtained_value = setmac.compress(self.key2, dict([(row.id, getattr(row, self.field_name)) for row in resultset]))
        return compressed_value == obtained_value