diff --git a/lib/Crypto/CryptArgon2.php b/lib/Crypto/CryptArgon2.php
index 3c198d4..a1a22e3 100644
--- a/lib/Crypto/CryptArgon2.php
+++ b/lib/Crypto/CryptArgon2.php
@@ -21,6 +21,7 @@
namespace OCA\UserSQL\Crypto;
+use OCA\UserSQL\Model\CryptoParam;
use OCP\IL10N;
/**
@@ -106,18 +107,14 @@ class CryptArgon2 extends AbstractAlgorithm
public function configuration()
{
return [
- [
- "name" => "memoryCost", "visible_name" => "Memory cost (KiB)",
- "default" => PASSWORD_ARGON2_DEFAULT_MEMORY_COST, "min" => 1, "max" => 1048576
- ],
- [
- "name" => "timeCost", "visible_name" => "Time cost",
- "default" => PASSWORD_ARGON2_DEFAULT_TIME_COST, "min" => 1, "max" => 1024
- ],
- [
- "name" => "threads", "visible_name" => "Threads",
- "default" => PASSWORD_ARGON2_DEFAULT_THREADS, "min" => 1, "max" => 1024
- ]
+ new CryptoParam(
+ "Memory cost (KiB)", PASSWORD_ARGON2_DEFAULT_MEMORY_COST, 1,
+ 1048576
+ ),
+ new CryptoParam(
+ "Time cost", PASSWORD_ARGON2_DEFAULT_TIME_COST, 1, 1024
+ ),
+ new CryptoParam("Threads", PASSWORD_ARGON2_DEFAULT_THREADS, 1, 1024)
];
}
diff --git a/lib/Crypto/CryptBlowfish.php b/lib/Crypto/CryptBlowfish.php
index 3d48ade..a76d187 100644
--- a/lib/Crypto/CryptBlowfish.php
+++ b/lib/Crypto/CryptBlowfish.php
@@ -21,6 +21,7 @@
namespace OCA\UserSQL\Crypto;
+use OCA\UserSQL\Model\CryptoParam;
use OCP\IL10N;
/**
@@ -72,12 +73,7 @@ class CryptBlowfish extends AbstractAlgorithm
*/
public function configuration()
{
- return [
- [
- "name" => "cost", "visible_name" => "Cost", "default" => 10,
- "min" => 4, "max" => 31
- ]
- ];
+ return [new CryptoParam("Cost", 10, 4, 31)];
}
/**
diff --git a/lib/Crypto/CryptExtendedDES.php b/lib/Crypto/CryptExtendedDES.php
index 235e563..6bd2f30 100644
--- a/lib/Crypto/CryptExtendedDES.php
+++ b/lib/Crypto/CryptExtendedDES.php
@@ -21,6 +21,7 @@
namespace OCA\UserSQL\Crypto;
+use OCA\UserSQL\Model\CryptoParam;
use OCP\IL10N;
/**
@@ -53,12 +54,7 @@ class CryptExtendedDES extends AbstractCrypt
*/
public function configuration()
{
- return [
- [
- "name" => "iterations", "visible_name" => "Iterations", "default" => 1000,
- "min" => 0, "max" => 16777215
- ]
- ];
+ return [new CryptoParam("Iterations", 1000, 0, 16777215)];
}
/**
diff --git a/lib/Crypto/CryptSHA256.php b/lib/Crypto/CryptSHA256.php
index 75515eb..72a372d 100644
--- a/lib/Crypto/CryptSHA256.php
+++ b/lib/Crypto/CryptSHA256.php
@@ -21,6 +21,7 @@
namespace OCA\UserSQL\Crypto;
+use OCA\UserSQL\Model\CryptoParam;
use OCP\IL10N;
/**
@@ -54,12 +55,7 @@ class CryptSHA256 extends AbstractCrypt
*/
public function configuration()
{
- return [
- [
- "name" => "rounds", "visible_name" => "Rounds", "default" => 5000,
- "min" => 1000, "max" => 999999999
- ]
- ];
+ return [new CryptoParam("Rounds", 5000, 1000, 999999999)];
}
/**
diff --git a/lib/Crypto/CryptSHA512.php b/lib/Crypto/CryptSHA512.php
index b638175..2cc9a33 100644
--- a/lib/Crypto/CryptSHA512.php
+++ b/lib/Crypto/CryptSHA512.php
@@ -21,6 +21,7 @@
namespace OCA\UserSQL\Crypto;
+use OCA\UserSQL\Model\CryptoParam;
use OCP\IL10N;
/**
@@ -54,12 +55,7 @@ class CryptSHA512 extends AbstractCrypt
*/
public function configuration()
{
- return [
- [
- "name" => "rounds", "visible_name" => "Rounds", "default" => 5000,
- "min" => 1000, "max" => 999999999
- ]
- ];
+ return [new CryptoParam("Rounds", 5000, 1000, 999999999)];
}
/**
diff --git a/lib/Crypto/IPasswordAlgorithm.php b/lib/Crypto/IPasswordAlgorithm.php
index 5650c17..54c70b1 100644
--- a/lib/Crypto/IPasswordAlgorithm.php
+++ b/lib/Crypto/IPasswordAlgorithm.php
@@ -61,8 +61,7 @@ interface IPasswordAlgorithm
/**
* Configuration for the algorithm.
- * The return array should contain entries which define keys:
- * name, visible_name, default, min, max.
+ * The return array should contain entries of class CryptoParam
*
* @return array The configuration array.
*/
diff --git a/lib/Crypto/Phpass.php b/lib/Crypto/Phpass.php
index 3693a6e..b038d3f 100644
--- a/lib/Crypto/Phpass.php
+++ b/lib/Crypto/Phpass.php
@@ -21,6 +21,7 @@
namespace OCA\UserSQL\Crypto;
+use OCA\UserSQL\Model\CryptoParam;
use OCP\IL10N;
/**
@@ -160,12 +161,7 @@ class Phpass extends AbstractAlgorithm
*/
public function configuration()
{
- return [
- [
- "name" => "iterations", "visible_name" => "Iterations (log2)",
- "default" => 8, "min" => 4, "max" => 31
- ]
- ];
+ return [new CryptoParam("Iterations (log2)", 8, 4, 31)];
}
/**
diff --git a/lib/Model/CryptoParam.php b/lib/Model/CryptoParam.php
new file mode 100644
index 0000000..81a24fc
--- /dev/null
+++ b/lib/Model/CryptoParam.php
@@ -0,0 +1,63 @@
+
+ * @author Marcin Łojewski
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+namespace OCA\UserSQL\Model;
+
+/**
+ * A parameter of a hash algorithm.
+ *
+ * @author Marcin Łojewski
+ */
+class CryptoParam
+{
+ /**
+ * @var string Parameter name.
+ */
+ public $name;
+ /**
+ * @var int Parameter default value.
+ */
+ public $value;
+ /**
+ * @var int Minimal value for parameter.
+ */
+ public $min;
+ /**
+ * @var int Maximum value for parameter.
+ */
+ public $max;
+
+ /**
+ * Class constructor.
+ *
+ * @param $name string Parameter name.
+ * @param $value int Parameter default value.
+ * @param $min int Minimal value for parameter.
+ * @param $max int Maximum value for parameter.
+ */
+ public function __construct($name, $value, $min, $max)
+ {
+ $this->name = $name;
+ $this->value = $value;
+ $this->min = $min;
+ $this->max = $max;
+ }
+}