1
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ã524_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ     ‹      Õ•QoÓ0Çß÷)Œxk/iÇ �c4šJTtmÕ!„rb·±–Ø•í¶”O�Ó¤´L+b<ù|ùûî~—ÄGžÄãÞìý¤�^Ï®‡hòöÕpÐC¸ð®Ýˆgqõà¼„ ýF8snÙØl6ÍM»©ÍfSÈ\‘ŸƒuF¦®ÉÇôŒ”>z†H&÷+"Nº\Ð�ââ3Òszå¬äÂŸÛZàb-SaKÛ‰
Qh³­—mPš‹ Þv:`WI%$PEõy NDÍ·eþð�çò!w ,Ù¥,MC‰ËÐšår¡"ìôS"‹²&�0ÈT+IÎÔms!ç±ÜEøÃ 7þèuà²ò4%eFÌ#ü²�.ÇQŒéˆ‚ »_sí5W˜™u¨Ð\Î¥à'Å7•øF~90®4±°©‘K'µ:HÁ#£¦:·KæYŸy‚Ì«*	ÿY7Xú]3&WÓþh¦UKxâPÝï¼9L'ÌåP,�H�wÖXUŽ§*±ËËýÕE¹È¦5Ð½Ê_ �ëœsÌzŠrÏ…éÞ:®ôNi­ uÑÃFØAáónp�Ðã`0r-ÌŽ¡¶ÃJÝ*½QÇþƒþÄ'¶ò¡ŒNÄ7šƒëX­ÝVpË_¨oþÖ¤ÿg%Öþ·Æ´Zÿ>À¯?¨�Ý"P�À¯AÏ'çe    B   ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þZq÷ÖnQðÈ0„¤óÆ„ÀuŸÅ_ŠI|¥�+Wé3ž¯ÅÄ ?÷     # Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012, 2013, 2016 Canonical Ltd
#   Authors: Robert Collins <robert.collins@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""GPG signing and checking logic."""

import os
from typing import Optional, Dict, List

from . import (
    config,
    errors,
    trace,
    ui,
    )
from .i18n import (
    gettext,
    ngettext,
    )

# verification results
SIGNATURE_VALID = 0
SIGNATURE_KEY_MISSING = 1
SIGNATURE_NOT_VALID = 2
SIGNATURE_NOT_SIGNED = 3
SIGNATURE_EXPIRED = 4

MODE_NORMAL = 0
MODE_DETACH = 1
MODE_CLEAR = 2


class GpgNotInstalled(errors.DependencyNotPresent):

    _fmt = ('python-gpg is not installed, it is needed to create or '
            'verify signatures. %(error)s')

    def __init__(self, error):
        errors.DependencyNotPresent.__init__(self, 'gpg', error)


class SigningFailed(errors.BzrError):

    _fmt = 'Failed to GPG sign data: "%(error)s"'

    def __init__(self, error):
        errors.BzrError.__init__(self, error=error)


class SignatureVerificationFailed(errors.BzrError):

    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'

    def __init__(self, error):
        errors.BzrError.__init__(self, error=error)


def bulk_verify_signatures(repository, revids, strategy,
                           process_events_callback=None):
    """Do verifications on a set of revisions

    :param repository: repository object
    :param revids: list of revision ids to verify
    :param strategy: GPG strategy to use
    :param process_events_callback: method to call for GUI frontends that
        want to keep their UI refreshed

    :return: count dictionary of results of each type,
             result list for each revision,
             boolean True if all results are verified successfully
    """
    count = {SIGNATURE_VALID: 0,
             SIGNATURE_KEY_MISSING: 0,
             SIGNATURE_NOT_VALID: 0,
             SIGNATURE_NOT_SIGNED: 0,
             SIGNATURE_EXPIRED: 0}
    result = []
    all_verifiable = True
    total = len(revids)
    with ui.ui_factory.nested_progress_bar() as pb:
        for i, (rev_id, verification_result, uid) in enumerate(
                repository.verify_revision_signatures(
                    revids, strategy)):
            pb.update("verifying signatures", i, total)
            result.append([rev_id, verification_result, uid])
            count[verification_result] += 1
            if verification_result != SIGNATURE_VALID:
                all_verifiable = False
            if process_events_callback is not None:
                process_events_callback()
    return (count, result, all_verifiable)


class DisabledGPGStrategy:
    """A GPG Strategy that makes everything fail."""

    @stati