Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for label, content in claims:
state[label] = content
for reader_dh_pk, label in (caps or []):
state.grant_access(reader_dh_pk, label)
store = {}
chain = hippiehug.Chain(store)
head = state.commit(chain)
block = store[head]
block_content = block.items[0]
nonce = ascii2bytes(block_content['nonce'])
# Get associated Merkle tree
mtr_hash = ascii2bytes(block_content['mtr_hash'])
tree = hippiehug.Tree(store, root_hash=mtr_hash)
return nonce, chain, tree
def main():
t = Tree()
from os import urandom
rep = 100000
print("For %s repetitions:" % rep)
X = [str(x) for x in xrange(rep)]
bulk = ["x" + str(x) for x in xrange(rep)]
t.multi_add(bulk)
with Timer() as tim:
t.multi_add(X)
print "Time per add: %.4f ms (total: %.2f sec)" % (tim.interval * 1000 / float(rep), tim.interval)
with Timer() as tim:
t.multi_is_in(X)
def main():
r = RedisStore()
t = Tree(store=r)
from os import urandom
for _ in range(1000):
item = urandom(32)
t.add(item)
assert t.is_in(item)
assert not t.is_in(urandom(32))
c0 += 1
claim_label = labels[fof]
vrf_value = vrfs[fof]
cap_lookup_key, encrypted_cap = encode_capability(
friend_dh_pk, nonce, claim_label, vrf_value)
capabilities += [(cap_lookup_key, encrypted_cap)]
cap_index[(friend, fof)] = (cap_lookup_key, encrypted_cap)
t1 = time.time()
print("\t\tTiming per encoded capab: %1.1f ms" % ((t1-t0) / c0 * 1000))
data = encode([enc_claims, capabilities])
print("\t\tData length: %1.1f kb" % (len(data) / 1024.0))
# Build our non-equivocable tree
t0 = time.time()
tree = Tree()
for lookup_key, enc_item in enc_claims + capabilities:
tree.add(key=lookup_key, item=enc_item)
_, evidence = tree.evidence(key=lookup_key)
assert tree.is_in(enc_item, key=lookup_key)
enc_item_hash = evidence[-1].item
tree.store[enc_item_hash] = enc_item
t1 = time.time()
print("\t\tTiming for building non-equiv. tree: %1.1f ms" % ((t1-t0) * 1000))
# Build a chain and a block
t0 = time.time()
c0 = 200
for _ in range(c0):
chain = Chain(tree.store)
payload = Payload.build(tree, nonce).export()
def main():
t = Tree()
from os import urandom
for _ in range(1000):
item = urandom(32)
t.add(item)
assert t.is_in(item)
assert not t.is_in(urandom(32))
def _build_tree(store, enc_items_map):
if not isinstance(store, ObjectStore):
store = ObjectStore(store)
tree = Tree(store)
enc_blob_map = {key: Blob(enc_item)
for key, enc_item in enc_items_map.items()
if not isinstance(enc_item, Blob)}
tree.update(enc_blob_map)
return tree
def __init__(self, object_store=None, root_hash=None):
self.object_store = object_store
if object_store is None:
self.object_store = ObjectStore()
self.tree = hippiehug.Tree(self.object_store, root_hash=root_hash)