Last change
on this file was
129c6ec,
checked in by Jean-Paul Calderone <exarkun@…>, at 2023-01-18T18:52:11Z
|
Factor more infrastructure code out of the test module
Test vector saving implementation can go near loading implementation. Also we
can separate out some simple types from the more complex logic. Initially
this was to resolve a circular dependency but that ended up being resolved
mostly by treatming SEGMENT_SIZE more like a parameter than a global. Still,
smaller modules are okay...
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | """ |
---|
2 | Simple data type definitions useful in the definition/verification of test |
---|
3 | vectors. |
---|
4 | """ |
---|
5 | |
---|
6 | from __future__ import annotations |
---|
7 | |
---|
8 | from attrs import frozen |
---|
9 | |
---|
10 | # CHK have a max of 256 shares. SDMF / MDMF have a max of 255 shares! |
---|
11 | # Represent max symbolically and resolve it when we know what format we're |
---|
12 | # dealing with. |
---|
13 | MAX_SHARES = "max" |
---|
14 | |
---|
15 | @frozen |
---|
16 | class Sample: |
---|
17 | """ |
---|
18 | Some instructions for building a long byte string. |
---|
19 | |
---|
20 | :ivar seed: Some bytes to repeat some times to produce the string. |
---|
21 | :ivar length: The length of the desired byte string. |
---|
22 | """ |
---|
23 | seed: bytes |
---|
24 | length: int |
---|
25 | |
---|
26 | @frozen |
---|
27 | class Param: |
---|
28 | """ |
---|
29 | Some ZFEC parameters. |
---|
30 | """ |
---|
31 | required: int |
---|
32 | total: int |
---|
33 | |
---|
34 | @frozen |
---|
35 | class SeedParam: |
---|
36 | """ |
---|
37 | Some ZFEC parameters, almost. |
---|
38 | |
---|
39 | :ivar required: The number of required shares. |
---|
40 | |
---|
41 | :ivar total: Either the number of total shares or the constant |
---|
42 | ``MAX_SHARES`` to indicate that the total number of shares should be |
---|
43 | the maximum number supported by the object format. |
---|
44 | """ |
---|
45 | required: int |
---|
46 | total: int | str |
---|
47 | |
---|
48 | def realize(self, max_total: int) -> Param: |
---|
49 | """ |
---|
50 | Create a ``Param`` from this object's values, possibly |
---|
51 | substituting the given real value for total if necessary. |
---|
52 | |
---|
53 | :param max_total: The value to use to replace ``MAX_SHARES`` if |
---|
54 | necessary. |
---|
55 | """ |
---|
56 | if self.total == MAX_SHARES: |
---|
57 | return Param(self.required, max_total) |
---|
58 | return Param(self.required, self.total) |
---|
Note: See
TracBrowser
for help on using the repository browser.