• 
      

    Add a registry for managing key types.

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

    Information

    cryptozoology
    master

    Reviewers

    This introduces KeyTypesRegistry, which tracks all key types supported
    by Cryptozoology. This provides access to keys by key type ID and by
    encryption or keywrap algorithm.

    While this only includes support for AES and EC keys right now, it would
    allow callers to provide or override key types as needed.

    The existing call sites that hard-code knowledge of key types now make
    use of the registry to fetch keys by ID or algorithm, except where
    appropriate (e.g., if explicitly an AES key needs to be created).

    Unit tests pass.

    Summary ID
    Add a registry for managing key types.
    This introduces `KeyTypesRegistry`, which tracks all key types supported by Cryptozoology. This provides access to keys by key type ID and by encryption or keywrap algorithm. While this only includes support for AES and EC keys right now, it would allow callers to provide or override key types as needed. The existing call sites that hard-code knowledge of key types now make use of the registry to fetch keys by ID or algorithm, except where appropriate (e.g., if explicitly an AES key needs to be created).
    908e102286672e8dda1fcd967449e9c176c4e818
    Description From Last Updated

    Do we want to document somewhere that get_key_type('ec') resolves only to the private key class? It feels a little confusing …

    david david

    Do we not want to reexport KeyTypesRegistry as well?

    david david

    We should protect this with the registry's lock so we don't end up with issues across threads: with self._lock: for …

    david david

    This ends up caching None for invalid values, making it so a stream of Secret.decode() calls with random alg= values …

    david david

    Same here regarding self._lock and not caching invalid values. Perhaps we could extract this into a helper?

    david david

    Can we make this use the same typed signature as the base class?

    david david

    This reads a little odd. How about just "This clears the algorithm caches whenever an item is registered"?

    david david

    Can we make this use the same typed signature as the base class?

    david david

    Same here re: "This will be used"

    david david

    If we wrap the cache writes in with self._lock its less of an issue, but this is rebinding rather than …

    david david

    The actual implementation is named "KeyTypesRegistry" (with an s). The name here (and in all the test methods/docstrings) is incorrect. …

    david david

    Can we call registry.populate() here so that this matches more closely with test_get_for_keywrap_alg_uses_cache?

    david david
    Checks run (2 succeeded)
    flake8 passed.
    JSHint passed.
    david
    1. 
        
    2. Show all issues

      Do we want to document somewhere that get_key_type('ec') resolves only to the private key class? It feels a little confusing that we have separate public and private classes but only the private one is registered.

    3. cryptozoology/keys/__init__.py (Diff revision 1)
       
       
       
       
       
       
       
      Show all issues

      Do we not want to reexport KeyTypesRegistry as well?

    4. cryptozoology/keys/registry.py (Diff revision 1)
       
       
       
       
       
       
       
       
      Show all issues

      We should protect this with the registry's lock so we don't end up with issues across threads:

      with self._lock:
          for key_cls in self:
              ...
      
          self._enc_key_cache_map[alg] = key_cls
      
    5. cryptozoology/keys/registry.py (Diff revision 1)
       
       
      Show all issues

      This ends up caching None for invalid values, making it so a stream of Secret.decode() calls with random alg= values grows memory without bound.

      Can we only cache positive results?

      Same for the keywrap algorithm.

    6. cryptozoology/keys/registry.py (Diff revision 1)
       
       
       
       
       
       
       
       
      Show all issues

      Same here regarding self._lock and not caching invalid values. Perhaps we could extract this into a helper?

    7. cryptozoology/keys/registry.py (Diff revision 1)
       
       
      Show all issues

      Can we make this use the same typed signature as the base class?

    8. cryptozoology/keys/registry.py (Diff revision 1)
       
       
       
      Show all issues

      This reads a little odd. How about just "This clears the algorithm caches whenever an item is registered"?

    9. cryptozoology/keys/registry.py (Diff revision 1)
       
       
      Show all issues

      Can we make this use the same typed signature as the base class?

    10. cryptozoology/keys/registry.py (Diff revision 1)
       
       
      Show all issues

      Same here re: "This will be used"

    11. cryptozoology/keys/registry.py (Diff revision 1)
       
       
       
      Show all issues

      If we wrap the cache writes in with self._lock its less of an issue, but this is rebinding rather than clearing. I think it would be better to use self._*_map.clear() here.

    12. cryptozoology/keys/tests/test_registry.py (Diff revision 1)
       
       
       
      Show all issues

      The actual implementation is named "KeyTypesRegistry" (with an s). The name here (and in all the test methods/docstrings) is incorrect.

      That said, all of our other registries are named in the singular, so KeyTypeRegistry is perhaps the better one to use.

    13. Show all issues

      Can we call registry.populate() here so that this matches more closely with test_get_for_keywrap_alg_uses_cache?

    14.