"""Logical keys for encrypted AEAT browser-session objects.:func:`aeat_auth_session_storage_state_path` composes the active bucket idand provider storage stem into the durable logical key consumed by the encryptedAEAT browser-session store. The returned :class:`~pathlib.Path` is an objectkey, not a plaintext filesystem destination.This module is the core-side authority for the auth-session object-key grammarintroduced when AEAT browser sessions moved from plaintext token-directorypaths to encrypted secure-object storage. Application probes and provideradapters call the same helper so certificate and Cl@ve Móvil session reads,writes, and deletes agree on one active-bucket/provider partition. The key isdeliberately independent of ``Settings.cadrumo_token_dir``; the secure repositorydigests the logical key before persistence."""from__future__importannotationsfrompathlibimportPathfrom.product_identityimportPRODUCT_IDENTITYAEAT_AUTH_SESSION_LOGICAL_ROOT=Path(f".{PRODUCT_IDENTITY.python_package}")/"auth"/"sessions""""Stable logical root for encrypted AEAT browser-session object keys.The root is part of the secure-object logical key. It names the auth-sessionnamespace for humans and tests, but it is not a directory this module creates orwrites."""_FORMER_PRODUCT_AUTH_SESSION_LOGICAL_ROOT=Path(".aeat")/"auth"/"sessions"
[docs]defformer_product_auth_session_path_for(path:Path)->Path|None:"""Map a canonical Cadrumo session key to its refusal-only former key."""candidate=Path(path)ifnotcandidate.is_relative_to(AEAT_AUTH_SESSION_LOGICAL_ROOT):returnNonerelative=candidate.relative_to(AEAT_AUTH_SESSION_LOGICAL_ROOT)return_FORMER_PRODUCT_AUTH_SESSION_LOGICAL_ROOT/relative
[docs]defaeat_auth_session_storage_state_path(bucket_id:str,storage_stem:str)->Path:"""Return the stable logical session key for ``bucket_id`` and provider stem. The returned path is not a filesystem destination. It is a durable logical object key consumed by the encrypted browser-session store. The caller owns resolving the active bucket id and selecting the provider stem (for example ``"storage"`` for certificate auth or ``"clave-movil-storage"`` for Cl@ve Móvil). Args: bucket_id: Active bucket/profile identifier that partitions session state between operator profiles. storage_stem: Provider-specific storage-state stem. Returns: A :class:`~pathlib.Path` under :data:`AEAT_AUTH_SESSION_LOGICAL_ROOT` suitable for the encrypted browser-session store. """returnAEAT_AUTH_SESSION_LOGICAL_ROOT/f"{bucket_id}-{storage_stem}.json"