Improve invalidation checking to InvalidatableMixin.
Review Request #15189 — Created July 21, 2026 and updated
Initially, invalidation support was limited to
BaseKey, though it
was moved out early in development toInvalidatableMixin. The one
piece remaining inBaseKeywascheck_valid(), which raised a
KeyInvalidatedErrorif no longer valid.This change renames the exception to
InvalidatedErrorand moves
check_valid()out into the mixin, so that any invalidatable object can
perform these validity checks. It's been renamed toassert_valid(), to
make its purpose more clear.When used as a context manager, invalidatable objects will now start
with a validity assertion, to avoid any surprises and catch problems
early.
Unit tests pass.
| Summary | ID |
|---|---|
| 2f02f59a7e0c9e5ffbf0fcd726fa2162335de3d3 |
| Description | From | Last Updated |
|---|---|---|
|
Since this is now happening in the mixin and the error is really generic, it's hard to know what's wrong … |
|
|
|
'cryptozoology.errors.InvalidatedError' imported but unused Column: 1 Error code: F401 |
|
|
|
In modern python we can use with self.assertRaises(InvalidatedError, msg=message): Same for others below. |
|
|
|
This was copied over straight from check_valid(). Probably should say "Assert that the object is still valid" now. |
|
|
|
Same about assertRaises in this file. |
|
- Change Summary:
-
Removed an unused import.
- Commits:
-
Summary ID 726f1805cff2dda9f452a8518ce3e1da2dec1051 51b16ff5594badd0014a6349d507d4cd5b22acd6 - Diff:
-
Revision 2 (+180 -114)
Checks run (2 succeeded)
-
-
Since this is now happening in the mixin and the error is really generic, it's hard to know what's wrong if we get
InvalidatedError. A traceback coming from a decryption operation would just tell the caller that something was invalid, but it's hard to know if it was the key or theSensitiveBytesinstance. As this library grows that just becomes even less clear.Can we include
type(self).__name__in the exception's message somehow? -
This was copied over straight from
check_valid(). Probably should say "Assert that the object is still valid" now.
- Change Summary:
-
- Added an error message for
InvalidatedErrorand updated tests. - Improved the docstring for
assert_valid().
- Added an error message for
- Commits:
-
Summary ID 51b16ff5594badd0014a6349d507d4cd5b22acd6 2f02f59a7e0c9e5ffbf0fcd726fa2162335de3d3 - Diff:
-
Revision 3 (+322 -114)