Skip to content

Commit

Permalink
No reason to extend Horde_Crypt_Pgp in IMP_Crypt_Pgp
Browse files Browse the repository at this point in the history
We can do everything we need by wrapping.
  • Loading branch information
slusarz committed Apr 9, 2015
1 parent 1eff8d4 commit 5891b5d
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 84 deletions.
4 changes: 2 additions & 2 deletions imp/lib/Ajax/Application/Handler/Passphrase.php
Expand Up @@ -49,11 +49,11 @@ public function checkPassphrase()

switch ($this->vars->type) {
case 'pgpPersonal':
$result = $injector->getInstance('IMP_Crypt_Pgp')->storePassphrase('personal', $this->vars->dialog_input);
$result = $injector->getInstance('IMP_Pgp')->storePassphrase('personal', $this->vars->dialog_input);
break;

case 'pgpSymmetric':
$result = $injector->getInstance('IMP_Crypt_Pgp')->storePassphrase('symmetric', $this->vars->dialog_input, $this->vars->symmetricid);
$result = $injector->getInstance('IMP_Pgp')->storePassphrase('symmetric', $this->vars->dialog_input, $this->vars->symmetricid);
break;

case 'smimePersonal':
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Ajax/Imple/ImportEncryptKey.php
Expand Up @@ -73,7 +73,7 @@ protected function _handle(Horde_Variables $vars)
/* Add the public key to the storage system. */
switch ($vars->type) {
case 'pgp':
$injector->getInstance('IMP_Crypt_Pgp')->addPublicKey($mime_part->getContents());
$injector->getInstance('IMP_Pgp')->addPublicKey($mime_part->getContents());
$notification->push(_("Successfully added public key from message."), 'horde.success');
break;

Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Application.php
Expand Up @@ -96,7 +96,7 @@ protected function _bootstrap()
$factories = array(
'IMP_AuthImap' => 'IMP_Factory_AuthImap',
'IMP_Contacts' => 'IMP_Factory_Contacts',
'IMP_Crypt_Pgp' => 'IMP_Factory_Pgp',
'IMP_Pgp' => 'IMP_Factory_Pgp',
'IMP_Crypt_Smime' => 'IMP_Factory_Smime',
'IMP_Flags' => 'IMP_Factory_Flags',
'IMP_Identity' => 'IMP_Factory_Identity',
Expand Down
4 changes: 2 additions & 2 deletions imp/lib/Basic/Pgp.php
Expand Up @@ -23,7 +23,7 @@
class IMP_Basic_Pgp extends IMP_Basic_Base
{
/**
* @var IMP_Crypt_Pgp
* @var IMP_Pgp
*/
protected $_pgp;

Expand All @@ -33,7 +33,7 @@ protected function _init()
{
global $browser, $injector, $notification;

$this->_pgp = $injector->getInstance('IMP_Crypt_Pgp');
$this->_pgp = $injector->getInstance('IMP_Pgp');

/* Run through the action handlers */
switch ($this->vars->actionID) {
Expand Down
56 changes: 28 additions & 28 deletions imp/lib/Compose.php
Expand Up @@ -718,8 +718,8 @@ public function hasDrafts()
* following keys:
* - encrypt: (integer) A flag whether to encrypt or sign the message.
* One of:
* - IMP_Crypt_Pgp::ENCRYPT</li>
* - IMP_Crypt_Pgp::SIGNENC</li>
* - IMP_Pgp::ENCRYPT</li>
* - IMP_Pgp::SIGNENC</li>
* - IMP_Crypt_Smime::ENCRYPT</li>
* - IMP_Crypt_Smime::SIGNENC</li>
* - html: (boolean) Whether this is an HTML message.
Expand Down Expand Up @@ -997,10 +997,10 @@ protected function _encryptMessage(

/* Add personal address to encrypted message. */
switch ($encrypt) {
case IMP_Crypt_Pgp::ENCRYPT:
case IMP_Crypt_Pgp::SIGNENC:
case IMP_Crypt_Pgp::SYM_ENCRYPT:
case IMP_Crypt_Pgp::SYM_SIGNENC:
case IMP_Pgp::ENCRYPT:
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_ENCRYPT:
case IMP_Pgp::SYM_SIGNENC:
case IMP_Crypt_Smime::ENCRYPT:
case IMP_Crypt_Smime::SIGNENC:
$recip2 = clone $recip;
Expand All @@ -1009,21 +1009,21 @@ protected function _encryptMessage(
}

switch ($encrypt) {
case IMP_Crypt_Pgp::ENCRYPT:
case IMP_Crypt_Pgp::SIGN:
case IMP_Crypt_Pgp::SIGNENC:
case IMP_Crypt_Pgp::SYM_ENCRYPT:
case IMP_Crypt_Pgp::SYM_SIGNENC:
if (!IMP_Crypt_Pgp::enabled()) {
case IMP_Pgp::ENCRYPT:
case IMP_Pgp::SIGN:
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_ENCRYPT:
case IMP_Pgp::SYM_SIGNENC:
if (IMP_Pgp::enabled()) {
break;
}

$imp_pgp = $injector->getInstance('IMP_Crypt_Pgp');
$imp_pgp = $injector->getInstance('IMP_Pgp');

switch ($encrypt) {
case IMP_Crypt_Pgp::SIGN:
case IMP_Crypt_Pgp::SIGNENC:
case IMP_Crypt_Pgp::SYM_SIGNENC:
case IMP_Pgp::SIGN:
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_SIGNENC:
/* Check to see if we have the user's passphrase yet. */
$passphrase = $imp_pgp->getPassphrase('personal');
if (empty($passphrase)) {
Expand All @@ -1035,8 +1035,8 @@ protected function _encryptMessage(
}
break;

case IMP_Crypt_Pgp::SYM_ENCRYPT:
case IMP_Crypt_Pgp::SYM_SIGNENC:
case IMP_Pgp::SYM_ENCRYPT:
case IMP_Pgp::SYM_SIGNENC:
/* Check to see if we have the user's symmetric passphrase
* yet. */
$symmetric_passphrase = $imp_pgp->getPassphrase(
Expand All @@ -1056,25 +1056,25 @@ protected function _encryptMessage(
/* Do the encryption/signing requested. */
try {
switch ($encrypt) {
case IMP_Crypt_Pgp::SIGN:
$msg2 = $imp_pgp->impSignMimePart($msg);
case IMP_Pgp::SIGN:
$msg2 = $imp_pgp->signMimePart($msg);
$this->_setMetadata('encrypt_sign', true);
return $msg2;

case IMP_Crypt_Pgp::ENCRYPT:
case IMP_Crypt_Pgp::SYM_ENCRYPT:
return $imp_pgp->IMPencryptMIMEPart(
case IMP_Pgp::ENCRYPT:
case IMP_Pgp::SYM_ENCRYPT:
return $imp_pgp->encryptMimePart(
$msg,
$recip2,
($encrypt == IMP_Crypt_Pgp::SYM_ENCRYPT) ? $symmetric_passphrase : null
($encrypt == IMP_Pgp::SYM_ENCRYPT) ? $symmetric_passphrase : null
);

case IMP_Crypt_Pgp::SIGNENC:
case IMP_Crypt_Pgp::SYM_SIGNENC:
return $imp_pgp->IMPsignAndEncryptMIMEPart(
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_SIGNENC:
return $imp_pgp->signAndEncryptMimePart(
$msg,
$recip2,
($encrypt == IMP_Crypt_Pgp::SYM_SIGNENC) ? $symmetric_passphrase : null
($encrypt == IMP_Pgp::SYM_SIGNENC) ? $symmetric_passphrase : null
);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions imp/lib/Compose/Ui.php
Expand Up @@ -43,8 +43,8 @@ public function encryptList($default = null, $returnList = false)
$enc_opts = array();
$output = '';

if (IMP_Crypt_Pgp::enabled()) {
$enc_opts += $injector->getInstance('IMP_Crypt_Pgp')->encryptList();
if (IMP_Pgp::enabled()) {
$enc_opts += $injector->getInstance('IMP_Pgp')->encryptList();
}

if (IMP_Crypt_Smime::enabled()) {
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Dynamic/Compose/Common.php
Expand Up @@ -134,7 +134,7 @@ protected function _compose($base, $view, $args)

$view->priority = $prefs->getValue('set_priority');
if (!$prefs->isLocked('default_encrypt') &&
(IMP_Crypt_Pgp::enabled() || IMP_Crypt_Smime::enabled())) {
(IMP_Pgp::enabled() || IMP_Crypt_Smime::enabled())) {
$view->encrypt = $prefs->getValue('default_encrypt');
}

Expand Down
14 changes: 9 additions & 5 deletions imp/lib/Factory/Pgp.php
Expand Up @@ -12,7 +12,7 @@
*/

/**
* A Horde_Injector based factory for the IMP_Crypt_Pgp object.
* A Horde_Injector based factory for the IMP_Pgp object.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
Expand All @@ -23,9 +23,9 @@
class IMP_Factory_Pgp extends Horde_Core_Factory_Injector
{
/**
* Return the IMP_Crypt_Pgp instance.
* Return the IMP_Pgp instance.
*
* @return IMP_Crypt_Pgp The singleton instance.
* @return IMP_Pgp The singleton instance.
*/
public function create(Horde_Injector $injector)
{
Expand All @@ -42,8 +42,12 @@ public function create(Horde_Injector $injector)
}
}

return $injector->getInstance('Horde_Core_Factory_Crypt')
->create('IMP_Crypt_Pgp', $params);
return new IMP_Pgp(
$injector->getInstance('Horde_Core_Factory_Crypt')->create(
'Horde_Crypt_Pgp',
$params
)
);
}

}
17 changes: 9 additions & 8 deletions imp/lib/Mime/Viewer/Pgp.php
Expand Up @@ -82,7 +82,7 @@ protected function _render()
// Throws exception on error.
return array(
$this->_mimepart->getMimeId() => array(
'data' => '<html><body><tt>' . nl2br(str_replace(' ', '&nbsp;', $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->pgpPrettyKey($this->_mimepart->getContents()))) . '</tt></body></html>',
'data' => '<html><body><tt>' . nl2br(str_replace(' ', '&nbsp;', $GLOBALS['injector']->getInstance('IMP_Pgp')->pgpPrettyKey($this->_mimepart->getContents()))) . '</tt></body></html>',
'type' => 'text/html; charset=' . $this->getConfigParam('charset')
)
);
Expand Down Expand Up @@ -111,7 +111,8 @@ protected function _renderRaw()

switch ($this->_mimepart->getType()) {
case 'application/pgp-signature':
$parts = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp_Parse')->parse($this->_mimepart->getContents());
$parse = new Horde_Crypt_Pgp_Parse();
$parts = $parse->parse($this->_mimepart->getContents());
foreach (array_keys($parts) as $key) {
if ($parts[$key]['type'] == Horde_Crypt_Pgp::ARMOR_SIGNATURE) {
$ret['data'] = implode("\r\n", $parts[$key]['data']);
Expand Down Expand Up @@ -201,7 +202,7 @@ protected function _getEmbeddedMimeParts()
);

/* Is PGP active? */
if (!IMP_Crypt_Pgp::enabled()) {
if (!IMP_Pgp::enabled()) {
$status->addText(
_("The data in this part has been encrypted via PGP, however, PGP support is disabled so the message cannot be decrypted.")
);
Expand All @@ -220,7 +221,7 @@ protected function _getEmbeddedMimeParts()

/* Check if this a symmetrically encrypted message. */
try {
$imp_pgp = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp');
$imp_pgp = $GLOBALS['injector']->getInstance('IMP_Pgp');
$symmetric = $imp_pgp->encryptedSymmetrically($encrypted_data);
if ($symmetric) {
$symmetric_id = $this->_getSymmetricID();
Expand Down Expand Up @@ -353,7 +354,7 @@ protected function _getEmbeddedMimeParts()
protected function _outputPGPKey()
{
/* Is PGP active? */
if (!IMP_Crypt_Pgp::enabled()) {
if (!IMP_Pgp::enabled()) {
return array();
}

Expand Down Expand Up @@ -406,7 +407,7 @@ protected function _outputPGPSigned()
$id_ob = new Horde_Mime_Id($signed_id);
$sig_id = $id_ob->idArithmetic($id_ob::ID_NEXT);

if (!IMP_Crypt_Pgp::enabled()) {
if (!IMP_Pgp::enabled()) {
return array(
$sig_id => null
);
Expand Down Expand Up @@ -444,7 +445,7 @@ protected function _outputPGPSigned()
$session->close();

try {
$imp_pgp = $injector->getInstance('IMP_Crypt_Pgp');
$imp_pgp = $injector->getInstance('IMP_Pgp');
if ($sig_raw = $sig_part->getMetadata(Horde_Crypt_Pgp_Parse::SIG_RAW)) {
$sig_result = $imp_pgp->verifySignature($sig_raw, $this->_getSender()->bare_address, null, $sig_part->getMetadata(Horde_Crypt_Pgp_Parse::SIG_CHARSET));
} else {
Expand Down Expand Up @@ -492,7 +493,7 @@ protected function _outputPGPSigned()
*/
protected function _getSymmetricID()
{
return $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->getSymmetricID($this->getConfigParam('imp_contents')->getMailbox(), $this->getConfigParam('imp_contents')->getUid(), $this->_mimepart->getMimeId());
return $GLOBALS['injector']->getInstance('IMP_Pgp')->getSymmetricID($this->getConfigParam('imp_contents')->getMailbox(), $this->getConfigParam('imp_contents')->getUid(), $this->_mimepart->getMimeId());
}

/**
Expand Down

0 comments on commit 5891b5d

Please sign in to comment.