Просмотр исходного кода

[ZF-8804; ZF-8805] Zend_Filter_Encrypt:

- allowed all options on creation (ZF-8805)
- allowed to use unknown options
- fixed methodname (ZF-8804)


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20288 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 лет назад
Родитель
Сommit
f6fa31fd32
2 измененных файлов с 42 добавлено и 12 удалено
  1. 22 12
      library/Zend/Filter/Encrypt/Openssl.php
  2. 20 0
      tests/Zend/Filter/Encrypt/OpensslTest.php

+ 22 - 12
library/Zend/Filter/Encrypt/Openssl.php

@@ -57,11 +57,13 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
 
     /**
      * Class constructor
+     * Available options
+     *   'public'     => public key
+     *   'private'    => private key
+     *   'envelope'   => envelope key
+     *   'passphrase' => passphrase
      *
-     * @param string|array $oldfile   File which should be renamed/moved
-     * @param string|array $newfile   New filename, when not set $oldfile will be used as new filename
-     *                                for $value when filtering
-     * @param boolean      $overwrite If set to true, it will overwrite existing files
+     * @param string|array $options Options for this adapter
      */
     public function __construct($options = array())
     {
@@ -74,16 +76,25 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
             $options = $options->toArray();
         }
 
-        $this->setPublicKey($options);
+        if (!is_array($options)) {
+            $options = array('public' => $options);
+        }
+
+        if (array_key_exists('passphrase', $options)) {
+            $this->setPassphrase($options['passphrase']);
+            unset($options['passphrase']);
+        }
+
+        $this->_setKeys($options);
     }
 
     /**
-     * Returns the set encryption options
+     * Sets the encryption keys
      *
      * @param  string|array $keys Key with type association
      * @return Zend_Filter_Encrypt_Openssl
      */
-    protected function setKeys($keys)
+    protected function _setKeys($keys)
     {
         if (!is_array($keys)) {
             require_once 'Zend/Filter/Exception.php';
@@ -125,8 +136,7 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
                     $this->_keys['envelope'][$key] = $cert;
                     break;
                 default:
-                    require_once 'Zend/Filter/Exception.php';
-                    throw new Zend_Filter_Exception("Unknown key type '{$type}'");
+                    break;
             }
         }
 
@@ -162,7 +172,7 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
             $key = array('public' => $key);
         }
 
-        return $this->setKeys($key);
+        return $this->_setKeys($key);
     }
 
     /**
@@ -199,7 +209,7 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
             $this->setPassphrase($passphrase);
         }
 
-        return $this->setKeys($key);
+        return $this->_setKeys($key);
     }
 
     /**
@@ -231,7 +241,7 @@ class Zend_Filter_Encrypt_Openssl implements Zend_Filter_Encrypt_Interface
             $key = array('envelope' => $key);
         }
 
-        return $this->setKeys($key);
+        return $this->_setKeys($key);
     }
 
     /**

+ 20 - 0
tests/Zend/Filter/Encrypt/OpensslTest.php

@@ -241,4 +241,24 @@ d/fxzPfuO/bLpADozTAnYT9Hu3wPrQVLeAfCp0ojqH7DYg==
             $this->assertContains('without public key', $e->getMessage());
         }
     }
+
+    /**
+     * @return void
+     */
+    public function testMultipleOptionsAtInitiation()
+    {
+        $passphrase = 'zPUp9mCzIrM7xQOEnPJZiDkBwPBV9UlITY0Xd3v4bfIwzJ12yPQCAkcR5BsePGVw
+RK6GS5RwXSLrJu9Qj8+fk0wPj6IPY5HvA9Dgwh+dptPlXppeBm3JZJ+92l0DqR2M
+ccL43V3Z4JN9OXRAfGWXyrBJNmwURkq7a2EyFElBBWK03OLYVMevQyRJcMKY0ai+
+tmnFUSkH2zwnkXQfPUxg9aV7TmGQv/3TkK1SziyDyNm7GwtyIlfcigCCRz3uc77U
+Izcez5wgmkpNElg/D7/VCd9E+grTfPYNmuTVccGOes+n8ISJJdW0vYX1xwWv5l
+bK22CwD/l7SMBOz4M9XH0Jb0OhNxLza4XMDu0ANMIpnkn1KOcmQ4gB8fmAbBt';
+        $filter = new Zend_Filter_Encrypt_Openssl(array(
+            'public' => dirname(__FILE__) . '/../_files/publickey.pem',
+            'passphrase' => $passphrase,
+            'private' => dirname(__FILE__) . '/../_files/privatekey.pem'));
+        $public = $filter->getPublicKey();
+        $this->assertFalse(empty($public));
+        $this->assertEquals($passphrase, $filter->getPassphrase());
+    }
 }