1
# Copyright (C) 2005 by Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""GPG signing and checking logic."""
23
import bzrlib.errors as errors
25
class DisabledGPGStrategy(object):
26
"""A GPG Strategy that makes everything fail."""
28
def __init__(self, ignored):
29
"""Real strategies take a configuration."""
31
def sign(self, content):
32
raise errors.SigningFailed('Signing is disabled.')
35
class LoopbackGPGStrategy(object):
36
"""A GPG Strategy that acts like 'cat' - data is just passed through."""
38
def __init__(self, ignored):
39
"""Real strategies take a configuration."""
41
def sign(self, content):
45
class GPGStrategy(object):
46
"""GPG Signing and checking facilities."""
48
def _command_line(self):
49
return [self._config.gpg_signing_command(), '--clearsign']
51
def __init__(self, config):
54
def sign(self, content):
56
process = subprocess.Popen(self._command_line(),
57
stdin=subprocess.PIPE,
58
stdout=subprocess.PIPE)
60
result = process.communicate(content)[0]
61
if process.returncode is None:
63
if process.returncode != 0:
64
raise errors.SigningFailed(self._command_line())
67
if e.errno == errno.EPIPE:
68
raise errors.SigningFailed(self._command_line())
72
# bad subprocess parameters, should never happen.
75
if e.errno == errno.ENOENT:
76
# gpg is not installed
77
raise errors.SigningFailed(self._command_line())