MCPcopy
hub / github.com/pyca/cryptography / test_rotate_bytes

Method test_rotate_bytes

tests/test_fernet.py:214–232  ·  view source on GitHub ↗
(self, backend)

Source from the content-addressed store, hash-verified

212 MultiFernet(None) # type: ignore[arg-type]
213
214 def test_rotate_bytes(self, backend):
215 f1 = Fernet(base64.urlsafe_b64encode(b"\x00" * 32), backend=backend)
216 f2 = Fernet(base64.urlsafe_b64encode(b"\x01" * 32), backend=backend)
217
218 mf1 = MultiFernet([f1])
219 mf2 = MultiFernet([f2, f1])
220
221 plaintext = b"abc"
222 mf1_ciphertext = mf1.encrypt(plaintext)
223
224 assert mf2.decrypt(mf1_ciphertext) == plaintext
225
226 rotated = mf2.rotate(mf1_ciphertext)
227
228 assert rotated != mf1_ciphertext
229 assert mf2.decrypt(rotated) == plaintext
230
231 with pytest.raises(InvalidToken):
232 mf1.decrypt(rotated)
233
234 def test_rotate_str(self, backend):
235 f1 = Fernet(base64.urlsafe_b64encode(b"\x00" * 32), backend=backend)

Callers

nothing calls this directly

Calls 5

encryptMethod · 0.95
decryptMethod · 0.95
rotateMethod · 0.95
FernetClass · 0.90
MultiFernetClass · 0.90

Tested by

no test coverage detected