Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Jun 25, 2012
2 parents 2ffbf07 + 78f9a51 commit 82367e5
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 220 deletions.
57 changes: 28 additions & 29 deletions src/BlockCipher.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class BlockCipher
protected $cipher;

/**
* Symmetric cipher broker
* Symmetric cipher plugin manager
*
* @var SymmetricBroker
* @var SymmetricPluginManager
*/
protected static $symmetricBroker = null;
protected static $symmetricPlugins = null;

/**
* Hash algorithm fot HMAC
Expand Down Expand Up @@ -87,51 +87,50 @@ public function __construct(SymmetricInterface $cipher)
*/
public static function factory($adapter, $options = array())
{
$broker = self::getSymmetricBroker();
$adapter = $broker->load($adapter, array($options));
$plugins = self::getSymmetricPluginManager();
$adapter = $plugins->get($adapter, (array) $options);
return new self($adapter);
}

/**
* Returns the symmetric cipher broker. If it doesn't exist it's created.
* Returns the symmetric cipher plugin manager. If it doesn't exist it's created.
*
* @return SymmetricBroker
* @return SymmetricPluginManager
*/
public static function getSymmetricBroker()
public static function getSymmetricPluginManager()
{
if (self::$symmetricBroker === null) {
self::setSymmetricBroker(new SymmetricBroker());
if (self::$symmetricPlugins === null) {
self::setSymmetricPluginManager(new SymmetricPluginManager());
}

return self::$symmetricBroker;
return self::$symmetricPlugins;
}

/**
* Set the symmetric cipher broker
* Set the symmetric cipher plugin manager
*
* @param string|SymmetricBroker $broker
* @param string|SymmetricPluginManager $plugins
* @throws Exception\InvalidArgumentException
*/
public static function setSymmetricBroker($broker)
public static function setSymmetricPluginManager($plugins)
{
if (is_string($broker)) {
if (!class_exists($broker)) {
throw new Exception\InvalidArgumentException(
sprintf(
'Unable to locate symmetric cipher broker of class "%s"',
$broker
));
if (is_string($plugins)) {
if (!class_exists($plugins)) {
throw new Exception\InvalidArgumentException(sprintf(
'Unable to locate symmetric cipher plugins using class "%s"; class does not exist',
$plugins
));
}
$broker = new $broker();
$plugins = new $plugins();
}
if (!$broker instanceof SymmetricBroker) {
throw new Exception\InvalidArgumentException(
sprintf(
'Symmetric cipher broker must extend SymmetricBroker; received "%s"',
(is_object($broker) ? get_class($broker) : gettype($broker))
));
if (!$plugins instanceof SymmetricPluginManager) {
throw new Exception\InvalidArgumentException(sprintf(
'Expected an instance or extension of %s\SymmetricPluginManager; received "%s"',
__NAMESPACE__,
(is_object($plugins) ? get_class($plugins) : gettype($plugins))
));
}
self::$symmetricBroker = $broker;
self::$symmetricPlugins = $plugins;
}

/**
Expand Down
Binary file added src/Symmetric/.Mcrypt.php.swp
Binary file not shown.
51 changes: 26 additions & 25 deletions src/Symmetric/Mcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class Mcrypt implements SymmetricInterface
protected $padding;

/**
* Padding broker
* Padding plugins
*
* @var PaddingBroker
* @var PaddingPluginManager
*/
protected static $paddingBroker = null;
protected static $paddingPlugins = null;

/**
* Supported cipher algorithms
Expand Down Expand Up @@ -143,8 +143,8 @@ public function __construct($options = array())
$this->setSalt($value);
break;
case 'padding':
$broker = self::getPaddingBroker();
$padding = $broker->load($value, array());
$plugins = self::getPaddingPluginManager();
$padding = $plugins->get($value);
$this->padding = $padding;
break;
}
Expand All @@ -165,51 +165,52 @@ protected function setDefaultOptions($options = array())
return;
}
if (!isset($options['padding'])) {
$broker = self::getPaddingBroker();
$padding = $broker->load(self::DEFAULT_PADDING, array());
$plugins = self::getPaddingPluginManager();
$padding = $plugins->get(self::DEFAULT_PADDING);
$this->padding = $padding;
}
}

/**
* Returns the padding broker. If it doesn't exist it's created.
* Returns the padding plugin manager. If it doesn't exist it's created.
*
* @return PaddingBroker
* @return PaddingPluginManager
*/
public static function getPaddingBroker()
public static function getPaddingPluginManager()
{
if (self::$paddingBroker === null) {
self::setPaddingBroker(new PaddingBroker());
if (self::$paddingPlugins === null) {
self::setPaddingPluginManager(new PaddingPluginManager());
}

return self::$paddingBroker;
return self::$paddingPlugins;
}

/**
* Set the symmetric cipher broker
* Set the padding plugin manager
*
* @param string|PaddingBroker $broker
* @param string|PaddingPluginManager $plugins
* @throws Exception\InvalidArgumentException
* @return void
*/
public static function setPaddingBroker($broker)
public static function setPaddingPluginManager($plugins)
{
if (is_string($broker)) {
if (!class_exists($broker)) {
if (is_string($plugins)) {
if (!class_exists($plugins)) {
throw new Exception\InvalidArgumentException(sprintf(
'Unable to locate padding broker of class "%s"',
$broker
'Unable to locate padding plugin manager via class "%s"; class does not exist',
$plugins
));
}
$broker = new $broker();
$plugins = new $plugins();
}
if (!$broker instanceof PaddingBroker) {
if (!$plugins instanceof PaddingPluginManager) {
throw new Exception\InvalidArgumentException(sprintf(
'Padding broker must extend PaddingBroker; received "%s"',
(is_object($broker) ? get_class($broker) : gettype($broker))
'Padding plugins must extend %s\PaddingPluginManager; received "%s"',
__NAMESPACE__,
(is_object($plugins) ? get_class($plugins) : gettype($plugins))
));
}
self::$paddingBroker = $broker;
self::$paddingPlugins = $plugins;
}

/**
Expand Down
51 changes: 0 additions & 51 deletions src/Symmetric/PaddingBroker.php

This file was deleted.

32 changes: 0 additions & 32 deletions src/Symmetric/PaddingLoader.php

This file was deleted.

79 changes: 79 additions & 0 deletions src/Symmetric/PaddingPluginManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Symmetric
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Crypt\Symmetric;

use Zend\ServiceManager\AbstractPluginManager;

/**
* Plugin manager implementation for the padding adapter instances.
*
* Enforces that padding adapters retrieved are instances of
* Padding\PaddingInterface. Additionally, it registers a number of default
* padding adapters available.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Symmetric
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class PaddingPluginManager extends AbstractPluginManager
{
/**
* Default set of padding adapters
*
* @var array
*/
protected $invokableClasses = array(
'pkcs7' => 'Zend\Crypt\Symmetric\Padding\Pkcs7'
);

/**
* Do not share by default
*
* @var bool
*/
protected $shareByDefault = false;

/**
* Validate the plugin
*
* Checks that the padding adaper loaded is an instance of Padding\PaddingInterface.
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException if invalid
*/
public function validatePlugin($plugin)
{
if ($plugin instanceof Padding\PaddingInterface) {
// we're okay
return;
}

throw new Exception\InvalidArgumentException(sprintf(
'Plugin of type %s is invalid; must implement %s\Padding\PaddingInterface',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
}
}
Loading

0 comments on commit 82367e5

Please sign in to comment.