~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Jonathan Riddell
  • Date: 2011-06-23 11:34:56 UTC
  • mto: This revision was merged to the branch mainline in revision 6003.
  • Revision ID: jriddell@canonical.com-20110623113456-42jg3xpphkymwraf
move some code from cmd_verify to gpg.set_acceptable_keys

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
        raise errors.SignatureVerificationFailed('Signature verification is \
59
59
disabled.')
60
60
 
61
 
    def set_acceptable_keys(self, key_patterns):
 
61
    def set_acceptable_keys(self, command_line_input):
62
62
        pass
63
63
 
64
64
 
79
79
    def verify(self, content, testament):
80
80
        return SIGNATURE_VALID, None
81
81
 
82
 
    def set_acceptable_keys(self, key_patterns):
83
 
        patterns = key_patterns.split(",")
84
 
        self.acceptable_keys = []
85
 
        for pattern in patterns:
86
 
            if pattern == "unknown":
87
 
                pass
88
 
            else:
89
 
                self.acceptable_keys.append(pattern)
 
82
    def set_acceptable_keys(self, command_line_input):
 
83
        if command_line_input is not None:
 
84
            patterns = command_line_input.split(",")
 
85
            self.acceptable_keys = []
 
86
            for pattern in patterns:
 
87
                if pattern == "unknown":
 
88
                    pass
 
89
                else:
 
90
                    self.acceptable_keys.append(pattern)
90
91
 
91
92
 
92
93
def _set_gpg_tty():
209
210
        raise errors.SignatureVerificationFailed("Unknown GnuPG key "\
210
211
                                                 "verification result")
211
212
 
212
 
    def set_acceptable_keys(self, key_patterns):
213
 
        patterns = key_patterns.split(",")
214
 
 
215
 
        self.acceptable_keys = []
216
 
        for pattern in patterns:
217
 
            result = self.context.keylist(pattern)
218
 
            found_key = False
219
 
            for key in result:
220
 
                found_key = True
221
 
                self.acceptable_keys.append(key.subkeys[0].fpr)
222
 
                trace.mutter("Added acceptable key: " + key.subkeys[0].fpr)
223
 
            if not found_key:
224
 
                trace.note(i18n.gettext(
225
 
                           "No GnuPG key results for pattern: {}"
226
 
                            ).format(pattern))
 
213
    def set_acceptable_keys(self, command_line_input):
 
214
        """sets the acceptable keys for verifying with this GPGStrategy
 
215
        
 
216
        :param command_line_input: comma separated list of patterns from
 
217
                                command line
 
218
        :return: nothing
 
219
        """
 
220
        key_patterns = None
 
221
        acceptable_keys_config = self._config.acceptable_keys()
 
222
        try:
 
223
            if isinstance(acceptable_keys_config, unicode):
 
224
                acceptable_keys_config = str(acceptable_keys_config)
 
225
        except UnicodeEncodeError:
 
226
            raise errors.BzrCommandError('Only ASCII permitted in option names')
 
227
 
 
228
        if acceptable_keys_config is not None:
 
229
            key_patterns = acceptable_keys_config
 
230
        if command_line_input is not None: #command line overrides config
 
231
            key_patterns = command_line_input
 
232
        if key_patterns is not None:
 
233
            patterns = key_patterns.split(",")
 
234
 
 
235
            self.acceptable_keys = []
 
236
            for pattern in patterns:
 
237
                result = self.context.keylist(pattern)
 
238
                found_key = False
 
239
                for key in result:
 
240
                    found_key = True
 
241
                    self.acceptable_keys.append(key.subkeys[0].fpr)
 
242
                    trace.mutter("Added acceptable key: " + key.subkeys[0].fpr)
 
243
                if not found_key:
 
244
                    trace.note(i18n.gettext(
 
245
                            "No GnuPG key results for pattern: {}"
 
246
                                ).format(pattern))