Pass use_agent to GPG init instead of overwrite

This commit is contained in:
Philipp Hörist 2017-06-08 18:55:05 +02:00
parent b5e9b07a07
commit 92b0a15521
2 changed files with 8 additions and 11 deletions

View File

@ -132,7 +132,7 @@ class CommonConnection:
self.USE_GPG = False
if gajim.HAVE_GPG:
self.USE_GPG = True
self.gpg = gpg.GnuPG(gajim.config.get('use_gpg_agent'))
self.gpg = gpg.GnuPG()
self.status = ''
self.old_show = ''
self.priority = gajim.get_priority(name, 'offline')
@ -234,8 +234,7 @@ class CommonConnection:
signed = ''
keyID = gajim.config.get_per('accounts', self.name, 'keyid')
if keyID and self.USE_GPG:
use_gpg_agent = gajim.config.get('use_gpg_agent')
if self.gpg.passphrase is None and not use_gpg_agent:
if self.gpg.passphrase is None and not self.gpg.use_agent:
# We didn't set a passphrase
return None
signed = self.gpg.sign(msg, keyID)
@ -566,8 +565,7 @@ class CommonConnection:
def gpg_passphrase(self, passphrase):
if self.gpg:
use_gpg_agent = gajim.config.get('use_gpg_agent')
if use_gpg_agent:
if self.gpg.use_agent:
self.gpg.passphrase = None
else:
self.gpg.passphrase = passphrase
@ -614,7 +612,7 @@ class CommonConnection:
self.server_resource = self._compute_resource()
if gajim.HAVE_GPG:
self.USE_GPG = True
self.gpg = gpg.GnuPG(gajim.config.get('use_gpg_agent'))
self.gpg = gpg.GnuPG()
gajim.nec.push_incoming_event(BeforeChangeShowEvent(None,
conn=self, show=show, message=msg))
self.connect_and_init(show, msg, sign_msg)
@ -892,8 +890,7 @@ class Connection(CommonConnection, ConnectionHandlers):
return
if gajim.HAVE_GPG:
self.USE_GPG = True
self.gpg = gpg.GnuPG(gajim.config.get(
'use_gpg_agent'))
self.gpg = gpg.GnuPG()
gajim.nec.push_incoming_event(
AccountCreatedEvent(None, conn=self,
account_info = self.new_account_info))

View File

@ -32,14 +32,14 @@ if HAVE_GPG:
gnupg.logger = logging.getLogger('gajim.c.gnupg')
class GnuPG(gnupg.GPG):
def __init__(self, use_agent=False):
gnupg.GPG.__init__(self, gpgbinary=GPG_BINARY)
def __init__(self):
use_agent = gajim.config.get('use_gpg_agent')
gnupg.GPG.__init__(self, gpgbinary=GPG_BINARY, use_agent=use_agent)
encoding = gajim.config.get('pgp_encoding')
if encoding:
self.encoding = encoding
self.decode_errors = 'replace'
self.passphrase = None
self.use_agent = use_agent
self.always_trust = [] # list of keyID to always trust
def _setup_my_options(self):