def test_optimal_path(self):
'''
Test the optimal path functionality
'''
expressions = [('a&b',['a','b'],'a&b'),
('a&b&c', ['a','b'],''),
('a|b', ['a'], 'a'),
('a|b|c',['a','b'], 'a'),
('(a&b)|c',['a','b'], '(a&b)'),
('(a&b)|c',['c'], 'c'),
('(a|b)&c',['a','c'], '(a)&c'),
('(a|b)&c',['a'], ''),
('(a&b)|(b&c)',['b','c'],'(b&c)'),
('(a|b)&(c|d)',['a','d'],'(a)&(d)'),
('((a&b)|c)&(d|e)',['c','e'],'(c)&(e)')]
parser = VisParser()
share_parser = SecretVisParser()
for (e, t, g) in expressions:
vis_tree = parser.parse(e)
share_tree = SecretVisTree(vis_tree.root,
vis_tree.expression,
secret=Random.get_random_bytes(16))
share_tree.compute_shares()
share_tree.set_attributes(vis_tree)
(match, opt_tree, keys) = share_tree.optimal_decryption_tree(Keytor('VIS_AES_CBC',DummyKeys(terms=t),16),
encrypted=False)
self.assertEqual(g, opt_tree.__str__(),
"Optimal tree for %s: %s should be %s" %
(e,opt_tree.__str__(),g))
评论列表
文章目录