--- /dev/null
+<?php
+/**
+ * @category Horde
+ * @package Core
+ */
+class Horde_Core_Binder_Crypt implements Horde_Injector_Binder
+{
+ public function create(Horde_Injector $injector)
+ {
+ return new Horde_Core_Factory_Crypt($injector);
+ }
+
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based Horde_Crypt:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+
+/**
+ * A Horde_Injector:: based Horde_Crypt:: factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+class Horde_Core_Factory_Crypt
+{
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(Horde_Injector $injector)
+ {
+ $this->_injector = $injector;
+ }
+
+ /**
+ * Return the Horde_Crypt:: instance.
+ *
+ * @param string $driver The driver name.
+ * @param array $params Any parameters needed by the driver.
+ *
+ * @return Horde_Crypt The instance.
+ * @throws Horde_Exception
+ */
+ public function getCrypt($driver, $params = array())
+ {
+ global $registry;
+
+ $params = array_merge(array(
+ 'charset' => $registry->getCharset(),
+ 'email_charset' => $registry->getEmailCharset(),
+ 'external_charset' => $registry->getExternalCharset(),
+ 'temp' => Horde::getTempDir()
+ ), $params);
+
+ return Horde_Crypt::factory($driver, $params);
+ }
+
+}
// 'Horde_Browser' - initialized below
'Horde_Cache' => new Horde_Core_Binder_Cache(),
'Horde_Core_Auth_Signup' => new Horde_Core_Binder_AuthSignup(),
+ 'Horde_Crypt' => new Horde_Core_Binder_Crypt(),
'Horde_Data' => new Horde_Core_Binder_Data(),
'Horde_Db' => new Horde_Core_Binder_Db(),
'Horde_Db_Adapter_Base' => new Horde_Core_Binder_DbBase(),
<file name="Auth.php" role="php" />
<file name="AuthSignup.php" role="php" />
<file name="Cache.php" role="php" />
+ <file name="Crypt.php" role="php" />
<file name="Data.php" role="php" />
<file name="Db.php" role="php" />
<file name="DbBase.php" role="php" />
</dir> <!-- /lib/Horde/Core/Binder -->
<dir name="Factory">
<file name="Auth.php" role="php" />
+ <file name="Crypt.php" role="php" />
<file name="Data.php" role="php" />
<file name="Db.php" role="php" />
<file name="DbPear.php" role="php" />
<channel>pear.horde.org</channel>
</package>
<package>
+ <name>Crypt</name>
+ <channel>pear.php.net</channel>
+ </package>
+ <package>
<name>DB</name>
<channel>pear.php.net</channel>
</package>
<install as="Horde/Core/Binder/Auth.php" name="lib/Horde/Core/Binder/Auth.php" />
<install as="Horde/Core/Binder/AuthSignup.php" name="lib/Horde/Core/Binder/AuthSignup.php" />
<install as="Horde/Core/Binder/Cache.php" name="lib/Horde/Core/Binder/Cache.php" />
+ <install as="Horde/Core/Binder/Crypt.php" name="lib/Horde/Core/Binder/Crypt.php" />
<install as="Horde/Core/Binder/Data.php" name="lib/Horde/Core/Binder/Data.php" />
<install as="Horde/Core/Binder/Db.php" name="lib/Horde/Core/Binder/Db.php" />
<install as="Horde/Core/Binder/DbBase.php" name="lib/Horde/Core/Binder/DbBase.php" />
<install as="Horde/Core/Binder/Twitter.php" name="lib/Horde/Core/Binder/Twitter.php" />
<install as="Horde/Core/Binder/Vfs.php" name="lib/Horde/Core/Binder/Vfs.php" />
<install as="Horde/Core/Factory/Auth.php" name="lib/Horde/Core/Factory/Auth.php" />
+ <install as="Horde/Core/Factory/Crypt.php" name="lib/Horde/Core/Factory/Crypt.php" />
<install as="Horde/Core/Factory/Data.php" name="lib/Horde/Core/Factory/Data.php" />
<install as="Horde/Core/Factory/Db.php" name="lib/Horde/Core/Factory/Db.php" />
<install as="Horde/Core/Factory/DbPear.php" name="lib/Horde/Core/Factory/DbPear.php" />
class Horde_Crypt
{
/**
+ * Configuration parameters.
+ *
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
* The temporary directory to use.
*
* @var string
*
* @param array $params Configuration parameters:
* <pre>
+ * 'charset' - (string) The default charset.
+ * DEFAULT: NONE
+ * 'email_charset' - (string) The default email charset.
+ * DEFAULT: NONE
+ * 'external_charset' - (string) The default external charset.
+ * DEFAULT: NONE
* 'temp' - (string) [REQUIRED] Location of temporary directory.
* </pre>
*
* @throws InvalidArgumentException
*/
- public function __construct($params = array())
+ public function __construct(array $params = array())
{
if (empty($params['temp'])) {
throw new InvalidArgumentException('A temporary directory must be provided.');
}
$this->_tempdir = Horde_Util::createTempDir(true, $params['temp']);
+
+ $this->_params = array_merge(array(
+ 'charset' => null,
+ 'email_charset' => null,
+ 'external_charset' => null,
+ ), $params);
}
/**
if ($errno == 0) {
throw new Horde_Exception(_("Connection refused to the public keyserver."));
} else {
- throw new Horde_Exception(sprintf(_("Connection refused to the public keyserver. Reason: %s (%s)"), Horde_String::convertCharset($errstr, $GLOBALS['registry']->getExternalCharset()), $errno));
+ throw new Horde_Exception(sprintf(_("Connection refused to the public keyserver. Reason: %s (%s)"), Horde_String::convertCharset($errstr, $this->_params['external_charset']), $errno));
}
}
'--armor',
'--always-trust',
'--batch',
- '--charset ' . $GLOBALS['registry']->getCharset(),
+ '--charset ' . $this->_params['charset'],
$keyring,
'--verify'
);
$msg_sign = $this->encrypt($mime_part->toString(array('headers' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT)), $params);
/* Add the PGP signature. */
- $charset = $GLOBALS['registry']->getEmailCharset();
$pgp_sign = new Horde_Mime_Part();
$pgp_sign->setType('application/pgp-signature');
- $pgp_sign->setCharset($charset);
+ $pgp_sign->setCharset($this->_params['email_charset']);
$pgp_sign->setDisposition('inline');
- $pgp_sign->setDescription(Horde_String::convertCharset(_("PGP Digital Signature"), $GLOBALS['registry']->getCharset(), $charset));
+ $pgp_sign->setDescription(Horde_String::convertCharset(_("PGP Digital Signature"), $this->_params['charset'], $this->_params['email_charset']));
$pgp_sign->setContents($msg_sign);
/* Get the algorithim information from the signature. Since we are
$message_encrypt = $this->encrypt($signenc_body, $params);
/* Set up MIME Structure according to RFC 3156. */
- $charset = $GLOBALS['registry']->getEmailCharset();
$part = new Horde_Mime_Part();
$part->setType('multipart/encrypted');
- $part->setCharset($charset);
+ $part->setCharset($this->_params['email_charset']);
$part->setContentTypeParameter('protocol', 'application/pgp-encrypted');
- $part->setDescription(Horde_String::convertCharset(_("PGP Encrypted Data"), $GLOBALS['registry']->getCharset(), $charset));
+ $part->setDescription(Horde_String::convertCharset(_("PGP Encrypted Data"), $this->_params['charset'], $this->_params['email_charset']));
$part->setContents("This message is in MIME format and has been PGP encrypted.\n");
$part1 = new Horde_Mime_Part();
$part = $this->encryptMIMEPart($part, $encrypt_params);
$part->setContents("This message is in MIME format and has been PGP signed and encrypted.\n");
- $charset = $GLOBALS['registry']->getEmailCharset();
- $part->setCharset($charset);
- $part->setDescription(Horde_String::convertCharset(_("PGP Signed/Encrypted Data"), $GLOBALS['registry']->getCharset(), $charset));
+ $part->setCharset($this->_params['email_charset']);
+ $part->setDescription(Horde_String::convertCharset(_("PGP Signed/Encrypted Data"), $this->_params['charset'], $this->_params['email_charset']));
return $part;
}
*/
public function publicKeyMIMEPart($key)
{
- $charset = $GLOBALS['registry']->getEmailCharset();
$part = new Horde_Mime_Part();
$part->setType('application/pgp-keys');
- $part->setCharset($charset);
- $part->setDescription(Horde_String::convertCharset(_("PGP Public Key"), $GLOBALS['registry']->getCharset(), $charset));
+ $part->setCharset($this->_params['email_charset']);
+ $part->setDescription(Horde_String::convertCharset(_("PGP Public Key"), $this->_params['charset'], $this->_params['charset']));
$part->setContents($key);
return $part;
/* Sign the part as a message */
$message = $this->encrypt($mime_part->toString(array('headers' => true, 'canonical' => true)), $params);
- /* Get charset for mime part description. */
- $charset = $GLOBALS['registry']->getEmailCharset();
-
$msg = new Horde_Mime_Part();
- $msg->setCharset($charset);
- $msg->setDescription(Horde_String::convertCharset(_("S/MIME Encrypted Message"), $GLOBALS['registry']->getCharset(), $charset));
+ $msg->setCharset($this->_params['email_charset']);
+ $msg->setDescription(Horde_String::convertCharset(_("S/MIME Encrypted Message"), $this->_params['charset'], $this->_params['email_charset']));
$msg->setDisposition('inline');
$msg->setType('application/pkcs7-mime');
$msg->setContentTypeParameter('smime-type', 'enveloped-data');
if (empty($key)) {
return '';
}
- $pgp = Horde_Crypt::factory('pgp', $var->type->getPGPParams());
- return '<pre>' . $pgp->pgpPrettyKey($key) . '</pre>';
+ return '<pre>' .
+ $GLOBALS['injector']->getInstance('Horde_Crypt')->getCrypr('Pgp', $var->type->getPGPParams())->pgpPrettyKey($key) .
+ '</pre>';
}
protected function _renderVarDisplay_smime($form, &$var, &$vars)
if (empty($cert)) {
return '';
}
- $smime = Horde_Crypt::factory('smime', $var->type->getSMIMEParams());
- return $smime->certToHTML($cert);
+ return $GLOBALS['injector']->getInstance('Horde_Crypt')->getCrypt('Smime', $var->type->getSMIMEParams())->certToHTML($cert);
}
protected function _renderVarDisplay_country($form, &$var, &$vars)
public function create(Horde_Injector $injector)
{
$params = array(
- 'program' => $GLOBALS['conf']['gnupg']['path'],
- 'temp' => Horde::getTempDir()
+ 'program' => $GLOBALS['conf']['gnupg']['path']
);
if (isset($GLOBALS['conf']['http']['proxy']['proxy_host'])) {
}
}
- return Horde_Crypt::factory('IMP_Crypt_Pgp', $params);
+ return $injector->getInstance('Horde_Crypt')->getCrypt('IMP_Crypt_Pgp', $params);
}
/**
*/
public function create(Horde_Injector $injector)
{
- return Horde_Crypt::factory('IMP_Crypt_Smime', array(
- 'temp' => Horde::getTempDir()
- ));
+ return $injector->getInstance('Horde_Crypt')->getCrypt('IMP_Crypt_Smime');
}
/**
$this->_pgp = PEAR::raiseError(_("Encryption support has not been configured, please contact your administrator."));
return;
}
- require_once 'Horde/Crypt.php';
- $this->_pgp = Horde_Crypt::factory('pgp',
- array('program' => $GLOBALS['conf']['utils']['gnupg'],
- 'temp' => Horde::getTempDir()));
+
+ $this->_pgp = $GLOBALS['injector']->getInstance('Horde_Crypt')->getCrypt('pgp', array(
+ 'program' => $GLOBALS['conf']['utils']['gnupg']
+ ));
}
/**