From 8ab04be4d0ff1dddeb731ac671d65c82218e5eb6 Mon Sep 17 00:00:00 2001 From: Sven Meierhans Date: Tue, 2 Apr 2019 16:56:09 +0200 Subject: [PATCH] Removed unnecessary Contao <= 4.0 requirements * refactoring --- src/DiffieHellman.php | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/DiffieHellman.php b/src/DiffieHellman.php index e0c1b03..8478336 100644 --- a/src/DiffieHellman.php +++ b/src/DiffieHellman.php @@ -220,9 +220,8 @@ public function generateKeys() */ public function getPublicKey($type = self::NUMBER) { - if (is_null($this->_publicKey)) { - require_once TL_ROOT . '/system/modules/DiffieHellman/DiffieHellman/Exception.php'; - throw new Crypt_DiffieHellman_Exception('A public key has not yet been generated using a prior call to generateKeys()'); + if (is_null($this->_publicKey)) { + throw new Exception('A public key has not yet been generated using a prior call to generateKeys()'); } if ($type == self::BINARY) { return $this->_math->toBinary($this->_publicKey); @@ -249,9 +248,8 @@ public function computeSecretKey($publicKey, $type = self::NUMBER) if ($type == self::BINARY) { $publicKey = $this->_math->fromBinary($publicKey); } - if (!preg_match("/^\d+$/", $publicKey)) { - require_once TL_ROOT . '/system/modules/DiffieHellman/DiffieHellman/Exception.php'; - throw new Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number'); + if (!preg_match("/^\d+$/", $publicKey)) { + throw new Exception('invalid parameter; not a positive natural number'); } $this->_secretKey = $this->_math->powmod($publicKey, $this->getPrivateKey(), $this->getPrime()); return $this; @@ -265,9 +263,8 @@ public function computeSecretKey($publicKey, $type = self::NUMBER) */ public function getSharedSecretKey($type = self::NUMBER) { - if (!isset($this->_secretKey)) { - require_once TL_ROOT . '/system/modules/DiffieHellman/DiffieHellman/Exception.php'; - throw new Crypt_DiffieHellman_Exception('A secret key has not yet been computed; call computeSecretKey()'); + if (!isset($this->_secretKey)) { + throw new Exception('A secret key has not yet been computed; call computeSecretKey()'); } if ($type == self::BINARY) { return $this->_math->toBinary($this->_secretKey); @@ -301,9 +298,8 @@ public function setPrime($number) */ public function getPrime($type = self::NUMBER) { - if (!isset($this->_prime)) { - require_once TL_ROOT . '/system/modules/DiffieHellman/DiffieHellman/Exception.php'; - throw new Crypt_DiffieHellman_Exception('No prime number has been set'); + if (!isset($this->_prime)) { + throw new Exception('No prime number has been set'); } if ($type == self::NUMBER) { @@ -323,9 +319,8 @@ public function getPrime($type = self::NUMBER) */ public function setGenerator($number) { - if (!preg_match("/^\d+$/", $number) || $number < 2) { - require_once TL_ROOT . '/system/modules/DiffieHellman/DiffieHellman/Exception.php'; - throw new Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number greater than 1'); + if (!preg_match("/^\d+$/", $number) || $number < 2) { + throw new Exception('invalid parameter; not a positive natural number greater than 1'); } $this->_generator = (string) $number; return $this; @@ -339,9 +334,8 @@ public function setGenerator($number) */ public function getGenerator($type = self::NUMBER) { - if (!isset($this->_generator)) { - require_once TL_ROOT . '/system/modules/DiffieHellman/DiffieHellman/Exception.php'; - throw new Crypt_DiffieHellman_Exception('No generator number has been set'); + if (!isset($this->_generator)) { + throw new Exception('No generator number has been set'); } if ($type == self::NUMBER) { return $this->_generator; @@ -364,8 +358,7 @@ public function setPrivateKey($number, $type = self::NUMBER) $number = $this->_math->fromBinary($number); } if (!preg_match("/^\d+$/", $number)) { - require_once TL_ROOT . '/system/modules/DiffieHellman/DiffieHellman/Exception.php'; - throw new Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number'); + throw new Exception('invalid parameter; not a positive natural number'); } $this->_privateKey = (string) $number; return $this;