Source code for cadrumo.adapters.persistence.storage.custody._recovery_secret_codec
"""Exact, policy-free representation for profile recovery secrets.Imported by the supervised key-derivation worker, which starts afresh forevery wrap and unwrap. The typed refusal is therefore imported only when asecret is actually refused, so the success path never loads the errorhierarchy."""from__future__importannotationsfrom._kdf_codecimportKDF_TRANSPORT_ENCODING
[docs]defencode_recovery_secret(secret:str)->bytes:"""Encode a recovery secret exactly, without password policy or rewriting."""try:returnsecret.encode(KDF_TRANSPORT_ENCODING,errors="strict")exceptUnicodeEncodeError:from.errorsimportProfileCustodyRecoverySecretErrorraiseProfileCustodyRecoverySecretError("profile recovery secret is not strict UTF-8")fromNone
[docs]defdecode_recovery_secret(value:bytes)->str:"""Decode exact recovery transport bytes or refuse malformed UTF-8."""try:returnvalue.decode(KDF_TRANSPORT_ENCODING,errors="strict")exceptUnicodeDecodeError:from.errorsimportProfileCustodyRecoverySecretErrorraiseProfileCustodyRecoverySecretError("profile recovery secret transport is not strict UTF-8")fromNone