o d@sHdZddlZddlZddlZGdddeZddZddZd d ZdS) z* Cryptographic and hashing functionality. Nc@seZdZdZdS)SignatureVerifyErrorzD Exception raised when the signature verification returns an error. N)__name__ __module__ __qualname____doc__rr/usr/share/dput/dput/crypto.pyrsrcCsL|jtjj@r d}|S|jtjj@rd}|S|jtjj@r!d}|St|j)a Make a phrase characterising a GnuPG signature. :param signature: A `gpg.results.Signature` instance. :return: A simple text phrase characterising the `signature`. * If the signature is valid, the result is "valid". * If the signature is not valid, but is good, the result is "good". * If the signature is not good, the result is "bad". validbadgood)summarygpg constants SIGSUM_VALID SIGSUM_RED SIGSUM_GREENr) signaturetextrrrcharacterise_signatures  rc Csnd}d}d}zt|}Wnty"}z |}d}WYd}~nd}~wwd}|j|||j| dd}|S)am Make a message describing a GnuPG signature. :param signature: A `gpg.result.Signature` instance. :return: A text description of the salient points of the `signature`. The description includes the signature's character (whether it is valid, good, or bad); and the key ID used to create the signature. UNKNOWNNzHError checking signature from {fpr}: {error.__class__.__name__}: {error}z {character} signature from {fpr})error characterfpr)rrformattitler)r fpr_lengthrrexc text_templaterrrrdescribe_signature,s$  rc Cst}z|||\}}Wdn1swYWntjjy>}ztjdj|j | |j dd}~ww|j D]}t |}tjdj|j ||dqBdS)aW Verify the GnuPG signature on a file. :param infile: The file containing a signed message. :return: ``None``. :raise gpg.errors.GPGMEError: When the signature verification fails. The `infile` is a file-like object, open for reading, that contains a message signed with OpenPGP (e.g. GnuPG). Nz%gpg: {path}: error {code}: {message} )pathcodemessagezgpg: {path}: {description} )r sig description)r Contextverifyerrors GPGMEErrorsysstderrwriternamegetcoder" signaturesr)infilecontext_ verify_resultrrr$rrrcheck_file_signatureOs*   r3) rr)r gpg.results RuntimeErrorrrrr3rrrrs #