From ddefd86b2b8e8e06cdcaadc5f33d76125332d2fc Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 16 Oct 2019 10:41:40 -0400
Subject: [PATCH] Accept None for sharenums to get all the information

This helps the client a lot with lease operations
---
 src/_zkapauthorizer/_storage_server.py           | 5 +++--
 src/_zkapauthorizer/foolscap.py                  | 5 +++--
 src/_zkapauthorizer/tests/test_storage_server.py | 6 ++++--
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/_zkapauthorizer/_storage_server.py b/src/_zkapauthorizer/_storage_server.py
index 2455cc6..f76443a 100644
--- a/src/_zkapauthorizer/_storage_server.py
+++ b/src/_zkapauthorizer/_storage_server.py
@@ -459,7 +459,8 @@ def get_share_sizes(storage_server, storage_index_or_slot, sharenums):
 
     :param sharenums: A container of share numbers to use to filter the
         results.  Only information about share numbers in this container is
-        included in the result.
+        included in the result.  Or, ``None`` to get sizes for all shares
+        which exist.
 
     :return: A generator of tuples of (int, int) where the first element is a
         share number and the second element is the data size for that share
@@ -475,7 +476,7 @@ def get_share_sizes(storage_server, storage_index_or_slot, sharenums):
                     get_size = get_slot_share_size
                 else:
                     get_size = get_storage_index_share_size
-        if sharenum in sharenums:
+        if sharenums is None or sharenum in sharenums:
             yield sharenum, get_size(sharepath)
 
 
diff --git a/src/_zkapauthorizer/foolscap.py b/src/_zkapauthorizer/foolscap.py
index 0b704b7..4e77b5a 100644
--- a/src/_zkapauthorizer/foolscap.py
+++ b/src/_zkapauthorizer/foolscap.py
@@ -6,8 +6,9 @@ from foolscap.constraint import (
     ByteStringConstraint,
 )
 from foolscap.api import (
-    DictOf,
+    ChoiceOf,
     SetOf,
+    DictOf,
     ListOf,
 )
 from foolscap.remoteinterface import (
@@ -124,7 +125,7 @@ class RIPrivacyPassAuthorizedStorageServer(RemoteInterface):
 
     def share_sizes(
             storage_index_or_slot=StorageIndex,
-            sharenums=SetOf(int, maxLength=MAX_BUCKETS),
+            sharenums=ChoiceOf(None, SetOf(int, maxLength=MAX_BUCKETS)),
     ):
         """
         Get the size of the given shares in the given storage index or slot.  If a
diff --git a/src/_zkapauthorizer/tests/test_storage_server.py b/src/_zkapauthorizer/tests/test_storage_server.py
index 07cc6e1..d74fa0a 100644
--- a/src/_zkapauthorizer/tests/test_storage_server.py
+++ b/src/_zkapauthorizer/tests/test_storage_server.py
@@ -44,6 +44,8 @@ from hypothesis.strategies import (
     integers,
     lists,
     tuples,
+    one_of,
+    just,
 )
 from privacypass import (
     RandomToken,
@@ -470,7 +472,7 @@ class PassValidationTests(TestCase):
             lease_renew_secrets(),
             lease_cancel_secrets(),
         ),
-        sharenums=sharenum_sets(),
+        sharenums=one_of(just(None), sharenum_sets()),
         test_and_write_vectors_for_shares=test_and_write_vectors_for_shares(),
     )
     def test_mutable_share_sizes(self, slot, secrets, sharenums, test_and_write_vectors_for_shares):
@@ -523,7 +525,7 @@ class PassValidationTests(TestCase):
             sharenum: get_implied_data_length(data_vector, new_length)
             for (sharenum, (testv, data_vector, new_length))
             in tw_vectors.items()
-            if sharenum in sharenums
+            if sharenums is None or sharenum in sharenums
         }
 
         actual_sizes = self.storage_server.doRemoteCall(
-- 
GitLab