Merge pull request #869 from PR0M3TH3AN/improve-inmemory-secret-error-handling-18204251655789169400

Improve InMemorySecret wiped state error handling and testing
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-16 12:23:12 -05:00
commit 8adc1e7220
2 files changed
+15

No files matched your search

+13
View File
@@ -27,3 +27,16 @@ def test_inmemory_secret_wipe_clears_attributes():
assert secret._nonce is None
assert secret._cipher is None
assert secret._encrypted is None
def test_access_after_wipe_raises_error():
secret = InMemorySecret(b"secret data")
secret.wipe()
with pytest.raises(RuntimeError) as excinfo:
secret.get_bytes()
assert str(excinfo.value) == "Secret has been wiped"
with pytest.raises(RuntimeError) as excinfo:
secret.get_str()
assert str(excinfo.value) == "Secret has been wiped"
+2
View File
@@ -17,6 +17,8 @@ class InMemorySecret:
def get_bytes(self) -> bytes:
"""Decrypt and return the plaintext bytes."""
if self._cipher is None:
raise RuntimeError("Secret has been wiped")
return self._cipher.decrypt(self._nonce, self._encrypted, None)
def wipe(self) -> None: