Skip to content

Commit 3164d9c

Browse files
committed
fix: allot/unify must check all shares have the same type
1 parent 6c5939c commit 3164d9c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/nilql/nilql.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def allot(
575575
return shares
576576

577577
if isinstance(document, dict):
578-
# Document is an array of shares obtained from the ``encrypt`` function
578+
# Document contains shares obtained from the ``encrypt`` function
579579
# that must be allotted to nodes.
580580
if '$allot' in document:
581581
if len(document.keys()) != 1:
@@ -585,10 +585,13 @@ def allot(
585585
if isinstance(items, list):
586586

587587
# Simple allotment.
588-
if all(isinstance(item, (int, str)) for item in items):
588+
if (
589+
all(isinstance(item, int) for item in items) or
590+
all(isinstance(item, str) for item in items)
591+
):
589592
return [{'$share': item} for item in document['$allot']]
590593

591-
# More complex allotment with list of share lists.
594+
# More complex allotment with nested lists of shares.
592595
return [
593596
{'$share': [share['$share'] for share in shares]}
594597
for shares in allot([{'$allot': item} for item in items])
@@ -684,17 +687,17 @@ def unify(
684687
# Documents are shares.
685688
if all('$share' in document for document in documents):
686689

687-
# Simple share.
688-
if all(
689-
isinstance(document['$share'], (int, str))
690-
for document in documents
690+
# Simple document shares.
691+
if (
692+
all(isinstance(d['$share'], int) for d in documents) or
693+
all(isinstance(d['$share'], str) for d in documents)
691694
):
692695
return decrypt(
693696
secret_key,
694697
[document['$share'] for document in documents]
695698
)
696699

697-
# Share consisting of list of shares.
700+
# Document shares consisting of nested lists of shares.
698701
return [
699702
unify(
700703
secret_key,

0 commit comments

Comments
 (0)