Source code for cadrumo.application.modelo.review_package_recipient_encryption
"""Application use-case boundary for recipient-encrypted review packages.The recipient-encryption capability is defined in:mod:`cadrumo.application.modelo.recipient_encryption`. This module keeps theapplication-level errors and the use-case-shaped wrappers; the concretepersistence and cryptographic implementation is supplied by an outer adapter."""from__future__importannotationsfromdatetimeimportdatetime,timedeltafromtypingimportTYPE_CHECKINGfrom...core.errors.hierarchyimportCadrumoErrorifTYPE_CHECKING:from.recipient_encryptionimport(RecipientDecryptedPackage,RecipientEncryptedPackage,RecipientEncryptionCapability,RecipientEncryptionKeypair,)
[docs]classRecipientEncryptionError(CadrumoError):"""Base error for review-package recipient-encryption failures."""
[docs]classRecipientDecryptionError(RecipientEncryptionError):"""Raised when a recipient-encrypted package cannot be opened."""
[docs]classRecipientPackageExpiredError(RecipientDecryptionError):"""Raised when an envelope is presented at or after its validity deadline."""
[docs]defensure_recipient_encryption_keypair(*,bucket_id:str,recipient_encryption:RecipientEncryptionCapability,generated_at:datetime|None=None,)->RecipientEncryptionKeypair:"""Return the bucket's recipient-encryption keypair through its capability."""returnrecipient_encryption.ensure_keypair(bucket_id=bucket_id,generated_at=generated_at)
[docs]defencrypt_review_package_for_recipient(package_bytes:bytes,*,recipient_public_key_hex:str,recipient_encryption:RecipientEncryptionCapability,review_only:bool=False,valid_for:timedelta|None=None,issued_at:datetime|None=None,)->RecipientEncryptedPackage:"""Seal package bytes through the composed recipient-encryption capability."""returnrecipient_encryption.encrypt(package_bytes,recipient_public_key_hex=recipient_public_key_hex,review_only=review_only,valid_for=valid_for,issued_at=issued_at,)
[docs]defdecrypt_review_package_for_recipient(envelope:RecipientEncryptedPackage,*,recipient_private_key_hex:str,recipient_encryption:RecipientEncryptionCapability,now:datetime|None=None,)->RecipientDecryptedPackage:"""Open an envelope through the composed recipient-encryption capability."""returnrecipient_encryption.decrypt(envelope,recipient_private_key_hex=recipient_private_key_hex,now=now,)