~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Robert Collins
  • Date: 2005-10-17 08:15:09 UTC
  • mto: This revision was merged to the branch mainline in revision 1459.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051017081509-f108fef422640aba
gpg signing of content

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""GPG signing and checking logic."""
19
19
 
 
20
import errno
20
21
import subprocess
21
22
 
 
23
import bzrlib.errors as errors
22
24
 
23
25
class GPGStrategy(object):
24
26
    """GPG Signing and checking facilities."""
25
27
        
26
28
    def _command_line(self):
27
 
        return self._config.gpg_signing_command() + ' --clearsign'
 
29
        return [self._config.gpg_signing_command(), '--clearsign']
28
30
 
29
31
    def __init__(self, config):
30
32
        self._config = config
 
33
 
 
34
    def sign(self, content):
 
35
        try:
 
36
            process = subprocess.Popen(self._command_line(),
 
37
                                       stdin=subprocess.PIPE,
 
38
                                       stdout=subprocess.PIPE)
 
39
            try:
 
40
                result = process.communicate(content)[0]
 
41
                if process.returncode is None:
 
42
                    process.wait()
 
43
                if process.returncode != 0:
 
44
                    raise errors.SigningFailed(self._command_line())
 
45
                return result
 
46
            except IOError, e:
 
47
                if e.errno == errno.EPIPE:
 
48
                    raise errors.SigningFailed(self._command_line())
 
49
        except ValueError:
 
50
            # bad subprocess parameters, should never happen.
 
51
            raise
 
52
        except OSError, e:
 
53
            if e.errno == errno.ENOENT:
 
54
                # gpg is not installed
 
55
                raise errors.SigningFailed(self._command_line())
 
56
            else:
 
57
                raise