Skip to content

Commit

Permalink
Removed unnecessary Contao <= 4.0 requirements
Browse files Browse the repository at this point in the history
* refactoring
  • Loading branch information
SvenMeierhans authored Apr 2, 2019
1 parent 57ca730 commit 8ab04be
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/DiffieHellman.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8ab04be

Please sign in to comment.