|
7 | 7 | import hashlib |
8 | 8 | import hmac |
9 | 9 |
|
10 | | -BYTES_PER_PAIR = 3 |
11 | | -BYTES_PER_PAIRB64 = 4 |
12 | | -PAIRS_PER_DEMI = 2 |
13 | | -BYTES_PER_DEMI = BYTES_PER_PAIRB64 * PAIRS_PER_DEMI |
| 10 | +BYTES_PER_PAIR = 3 #: The number of bytes in each decoded Pair. |
| 11 | +BYTES_PER_PAIRB64 = 4 #: The number of bytes in each base64 encoded Pair. |
| 12 | +PAIRS_PER_DEMI = 2 #: The number of pairs in each 8-byte demi. |
| 13 | +BYTES_PER_DEMI = BYTES_PER_PAIRB64 * PAIRS_PER_DEMI #: The number of bytes in each demi. |
| 14 | + |
14 | 15 |
|
15 | 16 | class HashType(Enum): |
16 | 17 | MD5 = 1 |
17 | 18 | HMAC_MD5 = 2 |
18 | 19 |
|
| 20 | + |
19 | 21 | class Pair: |
20 | 22 | """ |
21 | 23 | Class representing a pair of 12-bit sensor readings. |
@@ -100,23 +102,23 @@ def readings(self): |
100 | 102 |
|
101 | 103 |
|
102 | 104 | class PairsURL(CircularBufferURL): |
103 | | - def __init__(self, *args, usehmac: bool = False, secretkey: str = None, **kwargs): |
104 | | - """ |
105 | | - This takes the payload of the linearised buffer, which is a long string of base64 characters. It decodes this |
106 | | - into a list of pairs. The hash (MD5 or HMAC-MD5) is taken and compared with that supplied in the URL by the |
107 | | - encoder. If the hashes match then the decode has been successful. If not, an exception is raised. |
| 105 | + """ |
| 106 | + This takes the payload of the linearised buffer, which is a long string of base64 characters. It decodes this |
| 107 | + into a list of pairs. The hash (MD5 or HMAC-MD5) is taken and compared with that supplied in the URL by the |
| 108 | + encoder. If the hashes match then the decode has been successful. If not, an exception is raised. |
108 | 109 |
|
109 | | - Parameters |
110 | | - ---------- |
111 | | - *args |
112 | | - Variable length argument list. |
113 | | - usehmac: bool |
114 | | - True if the hash inside the circular buffer endstop is HMAC-MD5. False if it is MD5. |
115 | | - secretkey: str |
116 | | - HMAC secret key as a string. Normally 16 characters long. |
117 | | - **kwargs |
118 | | - Keyword arguments to be passed to parent class constructors. |
119 | | - """ |
| 110 | + Parameters |
| 111 | + ---------- |
| 112 | + *args |
| 113 | + Variable length argument list. |
| 114 | + usehmac: bool |
| 115 | + True if the hash inside the circular buffer endstop is HMAC-MD5. False if it is MD5. |
| 116 | + secretkey: str |
| 117 | + HMAC secret key as a string. Normally 16 characters long. |
| 118 | + **kwargs |
| 119 | + Keyword arguments to be passed to parent class constructors. |
| 120 | + """ |
| 121 | + def __init__(self, *args, usehmac: bool = False, secretkey: str = None, **kwargs): |
120 | 122 | super().__init__(*args, **kwargs) |
121 | 123 |
|
122 | 124 | self._decode_pairs() |
|
0 commit comments