~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""GPG signing and checking logic."""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
20
import os
23
21
import sys
24
22
from StringIO import StringIO
29
27
import subprocess
30
28
 
31
29
from bzrlib import (
32
 
    config,
33
30
    errors,
34
31
    trace,
35
32
    ui,
36
33
    )
37
 
from bzrlib.i18n import (
38
 
    gettext, 
39
 
    ngettext,
40
 
    )
41
34
""")
42
35
 
43
 
from bzrlib.symbol_versioning import (
44
 
    deprecated_in,
45
 
    deprecated_method,
46
 
    )
 
36
class i18n:
 
37
    """this class is ready to use bzrlib.i18n but bzrlib.i18n is not ready to
 
38
    use so here is a stub until it is"""
 
39
    @staticmethod
 
40
    def gettext(string):
 
41
        return string
 
42
        
 
43
    @staticmethod
 
44
    def ngettext(single, plural, number):
 
45
        if number == 1:
 
46
            return single
 
47
        else:
 
48
            return plural
47
49
 
48
50
#verification results
49
51
SIGNATURE_VALID = 0
50
52
SIGNATURE_KEY_MISSING = 1
51
53
SIGNATURE_NOT_VALID = 2
52
54
SIGNATURE_NOT_SIGNED = 3
53
 
SIGNATURE_EXPIRED = 4
54
 
 
55
 
 
56
 
def bulk_verify_signatures(repository, revids, strategy,
57
 
        process_events_callback=None):
58
 
    """Do verifications on a set of revisions
59
 
 
60
 
    :param repository: repository object
61
 
    :param revids: list of revision ids to verify
62
 
    :param strategy: GPG strategy to use
63
 
    :param process_events_callback: method to call for GUI frontends that
64
 
        want to keep their UI refreshed
65
 
 
66
 
    :return: count dictionary of results of each type,
67
 
             result list for each revision,
68
 
             boolean True if all results are verified successfully
69
 
    """
70
 
    count = {SIGNATURE_VALID: 0,
71
 
             SIGNATURE_KEY_MISSING: 0,
72
 
             SIGNATURE_NOT_VALID: 0,
73
 
             SIGNATURE_NOT_SIGNED: 0,
74
 
             SIGNATURE_EXPIRED: 0}
75
 
    result = []
76
 
    all_verifiable = True
77
 
    total = len(revids)
78
 
    pb = ui.ui_factory.nested_progress_bar()
79
 
    try:
80
 
        for i, (rev_id, verification_result, uid) in enumerate(
81
 
                repository.verify_revision_signatures(
82
 
                    revids, strategy)):
83
 
            pb.update("verifying signatures", i, total)
84
 
            result.append([rev_id, verification_result, uid])
85
 
            count[verification_result] += 1
86
 
            if verification_result != SIGNATURE_VALID:
87
 
                all_verifiable = False
88
 
            if process_events_callback is not None:
89
 
                process_events_callback()
90
 
    finally:
91
 
        pb.finished()
92
 
    return (count, result, all_verifiable)
93
55
 
94
56
 
95
57
class DisabledGPGStrategy(object):
114
76
 
115
77
 
116
78
class LoopbackGPGStrategy(object):
117
 
    """A GPG Strategy that acts like 'cat' - data is just passed through.
118
 
    Used in tests.
119
 
    """
 
79
    """A GPG Strategy that acts like 'cat' - data is just passed through."""
120
80
 
121
81
    @staticmethod
122
82
    def verify_signatures_available():
142
102
                else:
143
103
                    self.acceptable_keys.append(pattern)
144
104
 
145
 
    @deprecated_method(deprecated_in((2, 6, 0)))
146
105
    def do_verifications(self, revisions, repository):
147
 
        return bulk_verify_signatures(repository, revisions, self)
 
106
        count = {SIGNATURE_VALID: 0,
 
107
                 SIGNATURE_KEY_MISSING: 0,
 
108
                 SIGNATURE_NOT_VALID: 0,
 
109
                 SIGNATURE_NOT_SIGNED: 0}
 
110
        result = []
 
111
        all_verifiable = True
 
112
        for rev_id in revisions:
 
113
            verification_result, uid =\
 
114
                                repository.verify_revision(rev_id,self)
 
115
            result.append([rev_id, verification_result, uid])
 
116
            count[verification_result] += 1
 
117
            if verification_result != SIGNATURE_VALID:
 
118
                all_verifiable = False
 
119
        return (count, result, all_verifiable)
148
120
 
149
 
    @deprecated_method(deprecated_in((2, 6, 0)))
150
121
    def valid_commits_message(self, count):
151
 
        return valid_commits_message(count)
 
122
        return i18n.gettext("{0} commits with valid signatures").format(
 
123
                                        count[SIGNATURE_VALID])            
152
124
 
153
 
    @deprecated_method(deprecated_in((2, 6, 0)))
154
125
    def unknown_key_message(self, count):
155
 
        return unknown_key_message(count)
 
126
        return i18n.ngettext("{0} commit with unknown key",
 
127
                             "{0} commits with unknown keys",
 
128
                             count[SIGNATURE_KEY_MISSING]).format(
 
129
                                        count[SIGNATURE_KEY_MISSING])
156
130
 
157
 
    @deprecated_method(deprecated_in((2, 6, 0)))
158
131
    def commit_not_valid_message(self, count):
159
 
        return commit_not_valid_message(count)
 
132
        return i18n.ngettext("{0} commit not valid",
 
133
                             "{0} commits not valid",
 
134
                             count[SIGNATURE_NOT_VALID]).format(
 
135
                                            count[SIGNATURE_NOT_VALID])
160
136
 
161
 
    @deprecated_method(deprecated_in((2, 6, 0)))
162
137
    def commit_not_signed_message(self, count):
163
 
        return commit_not_signed_message(count)
164
 
 
165
 
    @deprecated_method(deprecated_in((2, 6, 0)))
166
 
    def expired_commit_message(self, count):
167
 
        return expired_commit_message(count)
 
138
        return i18n.ngettext("{0} commit not signed",
 
139
                             "{0} commits not signed",
 
140
                             count[SIGNATURE_NOT_SIGNED]).format(
 
141
                                        count[SIGNATURE_NOT_SIGNED])
168
142
 
169
143
 
170
144
def _set_gpg_tty():
185
159
 
186
160
    acceptable_keys = None
187
161
 
188
 
    def __init__(self, config_stack):
189
 
        self._config_stack = config_stack
190
 
        try:
191
 
            import gpgme
192
 
            self.context = gpgme.Context()
193
 
        except ImportError, error:
194
 
            pass # can't use verify()
195
 
 
196
162
    @staticmethod
197
163
    def verify_signatures_available():
198
 
        """
199
 
        check if this strategy can verify signatures
200
 
 
201
 
        :return: boolean if this strategy can verify signatures
202
 
        """
203
164
        try:
204
165
            import gpgme
205
166
            return True
207
168
            return False
208
169
 
209
170
    def _command_line(self):
210
 
        key = self._config_stack.get('gpg_signing_key')
211
 
        if key is None or key == 'default':
212
 
            # 'default' or not setting gpg_signing_key at all means we should
213
 
            # use the user email address
214
 
            key = config.extract_email_address(self._config_stack.get('email'))
215
 
        return [self._config_stack.get('gpg_signing_command'), '--clearsign',
216
 
                '-u', key]
 
171
        return [self._config.gpg_signing_command(), '--clearsign']
 
172
 
 
173
    def __init__(self, config):
 
174
        self._config = config
 
175
        try:
 
176
            import gpgme
 
177
            self.context = gpgme.Context()
 
178
        except ImportError, error:
 
179
            pass # can't use verify()
217
180
 
218
181
    def sign(self, content):
219
182
        if isinstance(content, unicode):
253
216
 
254
217
    def verify(self, content, testament):
255
218
        """Check content has a valid signature.
256
 
 
 
219
        
257
220
        :param content: the commit signature
258
221
        :param testament: the valid testament string for the commit
259
 
 
 
222
        
260
223
        :return: SIGNATURE_VALID or a failed SIGNATURE_ value, key uid if valid
261
224
        """
262
225
        try:
266
229
 
267
230
        signature = StringIO(content)
268
231
        plain_output = StringIO()
 
232
        
269
233
        try:
270
234
            result = self.context.verify(signature, None, plain_output)
271
235
        except gpgme.GpgmeError,error:
272
236
            raise errors.SignatureVerificationFailed(error[2])
273
237
 
274
 
        # No result if input is invalid.
275
 
        # test_verify_invalid()
276
238
        if len(result) == 0:
277
239
            return SIGNATURE_NOT_VALID, None
278
 
        # User has specified a list of acceptable keys, check our result is in
279
 
        # it.  test_verify_unacceptable_key()
280
240
        fingerprint = result[0].fpr
281
241
        if self.acceptable_keys is not None:
282
242
            if not fingerprint in self.acceptable_keys:
283
243
                return SIGNATURE_KEY_MISSING, fingerprint[-8:]
284
 
        # Check the signature actually matches the testament.
285
 
        # test_verify_bad_testament()
286
244
        if testament != plain_output.getvalue():
287
245
            return SIGNATURE_NOT_VALID, None
288
 
        # Yay gpgme set the valid bit.
289
 
        # Can't write a test for this one as you can't set a key to be
290
 
        # trusted using gpgme.
291
246
        if result[0].summary & gpgme.SIGSUM_VALID:
292
247
            key = self.context.get_key(fingerprint)
293
248
            name = key.uids[0].name
294
249
            email = key.uids[0].email
295
250
            return SIGNATURE_VALID, name + " <" + email + ">"
296
 
        # Sigsum_red indicates a problem, unfortunatly I have not been able
297
 
        # to write any tests which actually set this.
298
251
        if result[0].summary & gpgme.SIGSUM_RED:
299
252
            return SIGNATURE_NOT_VALID, None
300
 
        # GPG does not know this key.
301
 
        # test_verify_unknown_key()
302
253
        if result[0].summary & gpgme.SIGSUM_KEY_MISSING:
303
254
            return SIGNATURE_KEY_MISSING, fingerprint[-8:]
304
 
        # Summary isn't set if sig is valid but key is untrusted but if user
305
 
        # has explicity set the key as acceptable we can validate it.
 
255
        #summary isn't set if sig is valid but key is untrusted
306
256
        if result[0].summary == 0 and self.acceptable_keys is not None:
307
257
            if fingerprint in self.acceptable_keys:
308
 
                # test_verify_untrusted_but_accepted()
309
258
                return SIGNATURE_VALID, None
310
 
        # test_verify_valid_but_untrusted()
311
 
        if result[0].summary == 0 and self.acceptable_keys is None:
312
 
            return SIGNATURE_NOT_VALID, None
313
 
        if result[0].summary & gpgme.SIGSUM_KEY_EXPIRED:
314
 
            expires = self.context.get_key(result[0].fpr).subkeys[0].expires
315
 
            if expires > result[0].timestamp:
316
 
                # The expired key was not expired at time of signing.
317
 
                # test_verify_expired_but_valid()
318
 
                return SIGNATURE_EXPIRED, fingerprint[-8:]
319
 
            else:
320
 
                # I can't work out how to create a test where the signature
321
 
                # was expired at the time of signing.
322
 
                return SIGNATURE_NOT_VALID, None
323
 
        # A signature from a revoked key gets this.
324
 
        # test_verify_revoked_signature()
325
 
        if result[0].summary & gpgme.SIGSUM_SYS_ERROR:
326
 
            return SIGNATURE_NOT_VALID, None
327
 
        # Other error types such as revoked keys should (I think) be caught by
328
 
        # SIGSUM_RED so anything else means something is buggy.
 
259
        else:
 
260
            return SIGNATURE_KEY_MISSING, None
329
261
        raise errors.SignatureVerificationFailed("Unknown GnuPG key "\
330
262
                                                 "verification result")
331
263
 
332
264
    def set_acceptable_keys(self, command_line_input):
333
 
        """Set the acceptable keys for verifying with this GPGStrategy.
334
 
 
 
265
        """sets the acceptable keys for verifying with this GPGStrategy
 
266
        
335
267
        :param command_line_input: comma separated list of patterns from
336
268
                                command line
337
269
        :return: nothing
338
270
        """
339
 
        patterns = None
340
 
        acceptable_keys_config = self._config_stack.get('acceptable_keys')
 
271
        key_patterns = None
 
272
        acceptable_keys_config = self._config.acceptable_keys()
 
273
        try:
 
274
            if isinstance(acceptable_keys_config, unicode):
 
275
                acceptable_keys_config = str(acceptable_keys_config)
 
276
        except UnicodeEncodeError:
 
277
            raise errors.BzrCommandError('Only ASCII permitted in option names')
 
278
 
341
279
        if acceptable_keys_config is not None:
342
 
            patterns = acceptable_keys_config
343
 
        if command_line_input is not None: # command line overrides config
344
 
            patterns = command_line_input.split(',')
 
280
            key_patterns = acceptable_keys_config
 
281
        if command_line_input is not None: #command line overrides config
 
282
            key_patterns = command_line_input
 
283
        if key_patterns is not None:
 
284
            patterns = key_patterns.split(",")
345
285
 
346
 
        if patterns:
347
286
            self.acceptable_keys = []
348
287
            for pattern in patterns:
349
288
                result = self.context.keylist(pattern)
353
292
                    self.acceptable_keys.append(key.subkeys[0].fpr)
354
293
                    trace.mutter("Added acceptable key: " + key.subkeys[0].fpr)
355
294
                if not found_key:
356
 
                    trace.note(gettext(
357
 
                            "No GnuPG key results for pattern: {0}"
 
295
                    trace.note(i18n.gettext(
 
296
                            "No GnuPG key results for pattern: {}"
358
297
                                ).format(pattern))
359
298
 
360
 
    @deprecated_method(deprecated_in((2, 6, 0)))
361
 
    def do_verifications(self, revisions, repository,
362
 
                            process_events_callback=None):
 
299
    def do_verifications(self, revisions, repository):
363
300
        """do verifications on a set of revisions
364
 
 
 
301
        
365
302
        :param revisions: list of revision ids to verify
366
303
        :param repository: repository object
367
 
        :param process_events_callback: method to call for GUI frontends that
368
 
            want to keep their UI refreshed
369
 
 
 
304
        
370
305
        :return: count dictionary of results of each type,
371
306
                 result list for each revision,
372
307
                 boolean True if all results are verified successfully
373
308
        """
374
 
        return bulk_verify_signatures(repository, revisions, self,
375
 
            process_events_callback)
 
309
        count = {SIGNATURE_VALID: 0,
 
310
                 SIGNATURE_KEY_MISSING: 0,
 
311
                 SIGNATURE_NOT_VALID: 0,
 
312
                 SIGNATURE_NOT_SIGNED: 0}
 
313
        result = []
 
314
        all_verifiable = True
 
315
        for rev_id in revisions:
 
316
            verification_result, uid =\
 
317
                                repository.verify_revision(rev_id,self)
 
318
            result.append([rev_id, verification_result, uid])
 
319
            count[verification_result] += 1
 
320
            if verification_result != SIGNATURE_VALID:
 
321
                all_verifiable = False
 
322
        return (count, result, all_verifiable)
376
323
 
377
 
    @deprecated_method(deprecated_in((2, 6, 0)))
378
324
    def verbose_valid_message(self, result):
379
325
        """takes a verify result and returns list of signed commits strings"""
380
 
        return verbose_valid_message(result)
381
 
 
382
 
    @deprecated_method(deprecated_in((2, 6, 0)))
 
326
        signers = {}
 
327
        for rev_id, validity, uid in result:
 
328
            if validity == SIGNATURE_VALID:
 
329
                signers.setdefault(uid, 0)
 
330
                signers[uid] += 1
 
331
        result = []
 
332
        for uid, number in signers.items():
 
333
             result.append( i18n.ngettext("{0} signed {1} commit", 
 
334
                             "{0} signed {1} commits",
 
335
                             number).format(uid, number) )
 
336
        return result
 
337
 
 
338
 
383
339
    def verbose_not_valid_message(self, result, repo):
384
340
        """takes a verify result and returns list of not valid commit info"""
385
 
        return verbose_not_valid_message(result, repo)
 
341
        signers = {}
 
342
        for rev_id, validity, empty in result:
 
343
            if validity == SIGNATURE_NOT_VALID:
 
344
                revision = repo.get_revision(rev_id)
 
345
                authors = ', '.join(revision.get_apparent_authors())
 
346
                signers.setdefault(authors, 0)
 
347
                signers[authors] += 1
 
348
        result = []
 
349
        for authors, number in signers.items():
 
350
            result.append( i18n.ngettext("{0} commit by author {1}", 
 
351
                                 "{0} commits by author {1}",
 
352
                                 number).format(number, authors) )
 
353
        return result
386
354
 
387
 
    @deprecated_method(deprecated_in((2, 6, 0)))
388
355
    def verbose_not_signed_message(self, result, repo):
389
356
        """takes a verify result and returns list of not signed commit info"""
390
 
        return verbose_not_valid_message(result, repo)
 
357
        signers = {}
 
358
        for rev_id, validity, empty in result:
 
359
            if validity == SIGNATURE_NOT_SIGNED:
 
360
                revision = repo.get_revision(rev_id)
 
361
                authors = ', '.join(revision.get_apparent_authors())
 
362
                signers.setdefault(authors, 0)
 
363
                signers[authors] += 1
 
364
        result = []
 
365
        for authors, number in signers.items():
 
366
            result.append( i18n.ngettext("{0} commit by author {1}", 
 
367
                                 "{0} commits by author {1}",
 
368
                                 number).format(number, authors) )
 
369
        return result
391
370
 
392
 
    @deprecated_method(deprecated_in((2, 6, 0)))
393
371
    def verbose_missing_key_message(self, result):
394
372
        """takes a verify result and returns list of missing key info"""
395
 
        return verbose_missing_key_message(result)
396
 
 
397
 
    @deprecated_method(deprecated_in((2, 6, 0)))
398
 
    def verbose_expired_key_message(self, result, repo):
399
 
        """takes a verify result and returns list of expired key info"""
400
 
        return verbose_expired_key_message(result, repo)
401
 
 
402
 
    @deprecated_method(deprecated_in((2, 6, 0)))
 
373
        signers = {}
 
374
        for rev_id, validity, fingerprint in result:
 
375
            if validity == SIGNATURE_KEY_MISSING:
 
376
                signers.setdefault(fingerprint, 0)
 
377
                signers[fingerprint] += 1
 
378
        result = []
 
379
        for fingerprint, number in signers.items():
 
380
            result.append( i18n.ngettext("Unknown key {0} signed {1} commit", 
 
381
                                 "Unknown key {0} signed {1} commits",
 
382
                                 number).format(fingerprint, number) )
 
383
        return result
 
384
 
403
385
    def valid_commits_message(self, count):
404
386
        """returns message for number of commits"""
405
 
        return valid_commits_message(count)
 
387
        return i18n.gettext("{0} commits with valid signatures").format(
 
388
                                        count[SIGNATURE_VALID])
406
389
 
407
 
    @deprecated_method(deprecated_in((2, 6, 0)))
408
390
    def unknown_key_message(self, count):
409
391
        """returns message for number of commits"""
410
 
        return unknown_key_message(count)
 
392
        return i18n.ngettext("{0} commit with unknown key",
 
393
                             "{0} commits with unknown keys",
 
394
                             count[SIGNATURE_KEY_MISSING]).format(
 
395
                                        count[SIGNATURE_KEY_MISSING])
411
396
 
412
 
    @deprecated_method(deprecated_in((2, 6, 0)))
413
397
    def commit_not_valid_message(self, count):
414
398
        """returns message for number of commits"""
415
 
        return commit_not_valid_message(count)
 
399
        return i18n.ngettext("{0} commit not valid",
 
400
                             "{0} commits not valid",
 
401
                             count[SIGNATURE_NOT_VALID]).format(
 
402
                                            count[SIGNATURE_NOT_VALID])
416
403
 
417
 
    @deprecated_method(deprecated_in((2, 6, 0)))
418
404
    def commit_not_signed_message(self, count):
419
405
        """returns message for number of commits"""
420
 
        return commit_not_signed_message(count)
421
 
 
422
 
    @deprecated_method(deprecated_in((2, 6, 0)))
423
 
    def expired_commit_message(self, count):
424
 
        """returns message for number of commits"""
425
 
        return expired_commit_message(count)
426
 
 
427
 
 
428
 
def valid_commits_message(count):
429
 
    """returns message for number of commits"""
430
 
    return gettext(u"{0} commits with valid signatures").format(
431
 
                                    count[SIGNATURE_VALID])
432
 
 
433
 
 
434
 
def unknown_key_message(count):
435
 
    """returns message for number of commits"""
436
 
    return ngettext(u"{0} commit with unknown key",
437
 
                    u"{0} commits with unknown keys",
438
 
                    count[SIGNATURE_KEY_MISSING]).format(
439
 
                                    count[SIGNATURE_KEY_MISSING])
440
 
 
441
 
 
442
 
def commit_not_valid_message(count):
443
 
    """returns message for number of commits"""
444
 
    return ngettext(u"{0} commit not valid",
445
 
                    u"{0} commits not valid",
446
 
                    count[SIGNATURE_NOT_VALID]).format(
447
 
                                        count[SIGNATURE_NOT_VALID])
448
 
 
449
 
 
450
 
def commit_not_signed_message(count):
451
 
    """returns message for number of commits"""
452
 
    return ngettext(u"{0} commit not signed",
453
 
                    u"{0} commits not signed",
454
 
                    count[SIGNATURE_NOT_SIGNED]).format(
455
 
                                    count[SIGNATURE_NOT_SIGNED])
456
 
 
457
 
 
458
 
def expired_commit_message(count):
459
 
    """returns message for number of commits"""
460
 
    return ngettext(u"{0} commit with key now expired",
461
 
                    u"{0} commits with key now expired",
462
 
                    count[SIGNATURE_EXPIRED]).format(
463
 
                                count[SIGNATURE_EXPIRED])
464
 
 
465
 
 
466
 
def verbose_expired_key_message(result, repo):
467
 
    """takes a verify result and returns list of expired key info"""
468
 
    signers = {}
469
 
    fingerprint_to_authors = {}
470
 
    for rev_id, validity, fingerprint in result:
471
 
        if validity == SIGNATURE_EXPIRED:
472
 
            revision = repo.get_revision(rev_id)
473
 
            authors = ', '.join(revision.get_apparent_authors())
474
 
            signers.setdefault(fingerprint, 0)
475
 
            signers[fingerprint] += 1
476
 
            fingerprint_to_authors[fingerprint] = authors
477
 
    result = []
478
 
    for fingerprint, number in signers.items():
479
 
        result.append(
480
 
            ngettext(u"{0} commit by author {1} with key {2} now expired",
481
 
                     u"{0} commits by author {1} with key {2} now expired",
482
 
                     number).format(
483
 
                number, fingerprint_to_authors[fingerprint], fingerprint))
484
 
    return result
485
 
 
486
 
 
487
 
def verbose_valid_message(result):
488
 
    """takes a verify result and returns list of signed commits strings"""
489
 
    signers = {}
490
 
    for rev_id, validity, uid in result:
491
 
        if validity == SIGNATURE_VALID:
492
 
            signers.setdefault(uid, 0)
493
 
            signers[uid] += 1
494
 
    result = []
495
 
    for uid, number in signers.items():
496
 
         result.append(ngettext(u"{0} signed {1} commit",
497
 
                                u"{0} signed {1} commits",
498
 
                                number).format(uid, number))
499
 
    return result
500
 
 
501
 
 
502
 
def verbose_not_valid_message(result, repo):
503
 
    """takes a verify result and returns list of not valid commit info"""
504
 
    signers = {}
505
 
    for rev_id, validity, empty in result:
506
 
        if validity == SIGNATURE_NOT_VALID:
507
 
            revision = repo.get_revision(rev_id)
508
 
            authors = ', '.join(revision.get_apparent_authors())
509
 
            signers.setdefault(authors, 0)
510
 
            signers[authors] += 1
511
 
    result = []
512
 
    for authors, number in signers.items():
513
 
        result.append(ngettext(u"{0} commit by author {1}",
514
 
                               u"{0} commits by author {1}",
515
 
                               number).format(number, authors))
516
 
    return result
517
 
 
518
 
 
519
 
def verbose_not_signed_message(result, repo):
520
 
    """takes a verify result and returns list of not signed commit info"""
521
 
    signers = {}
522
 
    for rev_id, validity, empty in result:
523
 
        if validity == SIGNATURE_NOT_SIGNED:
524
 
            revision = repo.get_revision(rev_id)
525
 
            authors = ', '.join(revision.get_apparent_authors())
526
 
            signers.setdefault(authors, 0)
527
 
            signers[authors] += 1
528
 
    result = []
529
 
    for authors, number in signers.items():
530
 
        result.append(ngettext(u"{0} commit by author {1}",
531
 
                               u"{0} commits by author {1}",
532
 
                               number).format(number, authors))
533
 
    return result
534
 
 
535
 
 
536
 
def verbose_missing_key_message(result):
537
 
    """takes a verify result and returns list of missing key info"""
538
 
    signers = {}
539
 
    for rev_id, validity, fingerprint in result:
540
 
        if validity == SIGNATURE_KEY_MISSING:
541
 
            signers.setdefault(fingerprint, 0)
542
 
            signers[fingerprint] += 1
543
 
    result = []
544
 
    for fingerprint, number in signers.items():
545
 
        result.append(ngettext(u"Unknown key {0} signed {1} commit",
546
 
                               u"Unknown key {0} signed {1} commits",
547
 
                               number).format(fingerprint, number))
548
 
    return result
 
406
        return i18n.ngettext("{0} commit not signed",
 
407
                             "{0} commits not signed",
 
408
                             count[SIGNATURE_NOT_SIGNED]).format(
 
409
                                        count[SIGNATURE_NOT_SIGNED])