Skip to content

Commit d262be4

Browse files
author
Athan Massouras
committed
fix: bugfix, bitstring status list now supports lists with multiple-bit statuses
Signed-off-by: Athan Massouras <[email protected]>
1 parent 8ebfebc commit d262be4

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/bit_array.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ def rand_and_settle(self):
352352
byte_idx = self._rand_settle(
353353
len(self.allocated.lst), lambda index: self.allocated.lst[index] < 255
354354
)
355+
print("byte_idx:\t", byte_idx)
356+
print(len(self.allocated.lst))
355357
start = byte_idx << 3
356358
end = start + 8
359+
print("start, end:\t", start, end)
357360
index = choice(self.linear_scan(start, end, lambda i: self.allocated[i] == 0))
358361
self.allocated[index] = 1
359362
self.num_allocated += 1

src/bitstring_status_list/issuer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def new(cls, size: int, bits: Bits = 1, strategy: Literal["linear", "random"] =
8383
allocator = LinearIndexAllocator(size)
8484
elif strategy == "random":
8585
allocator = RandomIndexAllocator(
86-
BitArray.with_at_least(bits, size), num_allocated=0
86+
BitArray.with_at_least(1, size), num_allocated=0
8787
)
8888
else:
8989
raise ValueError(f"Invalid strategy: {strategy}")

tests/test_bitstring_status_list.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_verify_jwt_basic_enveloping(status: BitstringStatusListIssuer):
6565
}
6666
}
6767

68-
for i in range(len(status)):
68+
for i in range(status.status_list.size):
6969
assert verifier.get_status(i) == {
7070
"status": status[i],
7171
"valid": not bool(status[i])
@@ -106,8 +106,18 @@ def test_verify_jwt_basic_embedding(status: BitstringStatusListIssuer):
106106
},
107107
}
108108

109-
for i in range(len(status)):
109+
for i in range(status.status_list.size):
110110
assert verifier.get_status(i) == {
111111
"status": status[i],
112112
"valid": not bool(status[i])
113113
}
114+
115+
def test_status_message():
116+
# Create a bitstring status list with a variety of different statuses
117+
bitstring = BitstringStatusListIssuer.new(MIN_LIST_LENGTH, bits=2)
118+
for idx in bitstring.take_n(50):
119+
bitstring[idx] = 1
120+
for idx in bitstring.take_n(50):
121+
bitstring[idx] = 2
122+
for idx in bitstring.take_n(50):
123+
bitstring[idx] = 3

0 commit comments

Comments
 (0)