• 
      

    Improve invalidation checking to InvalidatableMixin.

    Review Request #15189 — Created July 21, 2026 and updated

    Information

    cryptozoology
    master

    Reviewers

    Initially, invalidation support was limited to BaseKey, though it
    was moved out early in development to InvalidatableMixin. The one
    piece remaining in BaseKey was check_valid(), which raised a
    KeyInvalidatedError if no longer valid.

    This change renames the exception to InvalidatedError and moves
    check_valid() out into the mixin, so that any invalidatable object can
    perform these validity checks. It's been renamed to assert_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
    Improve invalidation checking to InvalidatableMixin.
    Initially, invalidation support was limited to `BaseKey`, though it was moved out early in development to `InvalidatableMixin`. The one piece remaining in `BaseKey` was `check_valid()`, which raised a `KeyInvalidatedError` if no longer valid. This change renames the exception to `InvalidatedError` and moves `check_valid()` out into the mixin, so that any invalidatable object can perform these validity checks. It's been renamed to `assert_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.
    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 …

    david david

    'cryptozoology.errors.InvalidatedError' imported but unused Column: 1 Error code: F401

    reviewbot reviewbot

    In modern python we can use with self.assertRaises(InvalidatedError, msg=message): Same for others below.

    david david

    This was copied over straight from check_valid(). Probably should say "Assert that the object is still valid" now.

    david david

    Same about assertRaises in this file.

    david david
    Checks run (1 failed, 1 succeeded)
    flake8 failed.
    JSHint passed.

    flake8

    chipx86
    david
    1. 
        
    2. Show all issues

      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 the SensitiveBytes instance. As this library grows that just becomes even less clear.

      Can we include type(self).__name__ in the exception's message somehow?

    3. cryptozoology/utils/invalidation.py (Diff revision 2)
       
       
      Show all issues

      This was copied over straight from check_valid(). Probably should say "Assert that the object is still valid" now.

    4. 
        
    chipx86
    Review request changed
    Change Summary:
    • Added an error message for InvalidatedError and updated tests.
    • Improved the docstring for assert_valid().
    Commits:
    Summary ID
    Improve invalidation checking to InvalidatableMixin.
    Initially, invalidation support was limited to `BaseKey`, though it was moved out early in development to `InvalidatableMixin`. The one piece remaining in `BaseKey` was `check_valid()`, which raised a `KeyInvalidatedError` if no longer valid. This change renames the exception to `InvalidatedError` and moves `check_valid()` out into the mixin, so that any invalidatable object can perform these validity checks. It's been renamed to `assert_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.
    51b16ff5594badd0014a6349d507d4cd5b22acd6
    Improve invalidation checking to InvalidatableMixin.
    Initially, invalidation support was limited to `BaseKey`, though it was moved out early in development to `InvalidatableMixin`. The one piece remaining in `BaseKey` was `check_valid()`, which raised a `KeyInvalidatedError` if no longer valid. This change renames the exception to `InvalidatedError` and moves `check_valid()` out into the mixin, so that any invalidatable object can perform these validity checks. It's been renamed to `assert_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.
    2f02f59a7e0c9e5ffbf0fcd726fa2162335de3d3

    Checks run (2 succeeded)

    flake8 passed.
    JSHint passed.
    david
    1. 
        
    2. cryptozoology/keys/tests/test_aes_key.py (Diff revisions 2 - 3)
       
       
      Show all issues

      In modern python we can use with self.assertRaises(InvalidatedError, msg=message):

      Same for others below.

      1. No, this provides a custom message if the validation fails. It doesn't check against the message. It's equivalent to assertEqual(..., msg=...).

      2. Oh, right you are.

      3. I really wish it did do that though :(

    3. Show all issues

      Same about assertRaises in this file.

    4. 
        
    david
    1. Ship It!
    2.