Parcourir la source

Bypassed exception when a Diffie-hellman private key is missing - fixes ZF-9432

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22052 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic il y a 15 ans
Parent
commit
cc65204161

+ 2 - 2
library/Zend/Crypt/DiffieHellman.php

@@ -324,7 +324,7 @@ class Zend_Crypt_DiffieHellman
     public function getPrivateKey($type = self::NUMBER)
     {
         if (!$this->hasPrivateKey()) {
-            $this->setPrivateKey($this->_generatePrivateKey());
+            $this->setPrivateKey($this->_generatePrivateKey(), self::BINARY);
         }
         if ($type == self::BINARY) {
             return $this->_math->toBinary($this->_privateKey);
@@ -377,4 +377,4 @@ class Zend_Crypt_DiffieHellman
         return $rand;
     }
 
-}
+}

+ 8 - 0
tests/Zend/Crypt/DiffieHellmanTest.php

@@ -133,4 +133,12 @@ class Zend_Crypt_DiffieHellmanTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($expectedSharedSecret, $aliceSecretKey);
         $this->assertEquals($expectedSharedSecret, $bobSecretKey);
     }
+
+    public function testGenerateKeysWithUnsetPrivateKey()
+    {
+        $dh = new Zend_Crypt_DiffieHellman(563, 5);
+        $dh->generateKeys();
+        $privateKey = $dh->getPrivateKey();
+        $this->assertNotNull($privateKey);
+    }
 }