diff --git a/.gitignore b/.gitignore
index 240635d0..e66f928a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
.phpcs-cache
.phpunit.result.cache
+.phpunit.cache
/clover.xml
/coveralls-upload.json
/docs/html/
diff --git a/composer.json b/composer.json
index 95ad6790..86d9f9f8 100644
--- a/composer.json
+++ b/composer.json
@@ -21,19 +21,19 @@
"dealerdirect/phpcodesniffer-composer-installer": true
},
"platform": {
- "php": "8.0.99"
+ "php": "8.1.99"
}
},
"require": {
- "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
+ "php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"ext-mbstring": "*",
"laminas/laminas-math": "^3.4",
"laminas/laminas-stdlib": "^3.8",
"psr/container": "^1.1 || ^2.0"
},
"require-dev": {
- "laminas/laminas-coding-standard": "~2.4.0",
- "phpunit/phpunit": "^9.5.25"
+ "laminas/laminas-coding-standard": "~2.5.0",
+ "phpunit/phpunit": "^10.1"
},
"suggest": {
"ext-openssl": "Required for most features of Laminas\\Crypt"
diff --git a/composer.lock b/composer.lock
index a61a0fb0..0fad6ed0 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "e7317805781232fe01860ac47b8a5a11",
+ "content-hash": "0ca3aa0f5c33b73c4ef6c09dfa8039bc",
"packages": [
{
"name": "laminas/laminas-math",
@@ -257,92 +257,22 @@
},
"time": "2022-02-04T12:51:07+00:00"
},
- {
- "name": "doctrine/instantiator",
- "version": "1.5.0",
- "source": {
- "type": "git",
- "url": "https://github.com/doctrine/instantiator.git",
- "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b",
- "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b",
- "shasum": ""
- },
- "require": {
- "php": "^7.1 || ^8.0"
- },
- "require-dev": {
- "doctrine/coding-standard": "^9 || ^11",
- "ext-pdo": "*",
- "ext-phar": "*",
- "phpbench/phpbench": "^0.16 || ^1",
- "phpstan/phpstan": "^1.4",
- "phpstan/phpstan-phpunit": "^1",
- "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
- "vimeo/psalm": "^4.30 || ^5.4"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Marco Pivetta",
- "email": "ocramius@gmail.com",
- "homepage": "https://ocramius.github.io/"
- }
- ],
- "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
- "homepage": "https://www.doctrine-project.org/projects/instantiator.html",
- "keywords": [
- "constructor",
- "instantiate"
- ],
- "support": {
- "issues": "https://github.com/doctrine/instantiator/issues",
- "source": "https://github.com/doctrine/instantiator/tree/1.5.0"
- },
- "funding": [
- {
- "url": "https://www.doctrine-project.org/sponsorship.html",
- "type": "custom"
- },
- {
- "url": "https://www.patreon.com/phpdoctrine",
- "type": "patreon"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator",
- "type": "tidelift"
- }
- ],
- "time": "2022-12-30T00:15:36+00:00"
- },
{
"name": "laminas/laminas-coding-standard",
- "version": "2.4.0",
+ "version": "2.5.0",
"source": {
"type": "git",
"url": "https://github.com/laminas/laminas-coding-standard.git",
- "reference": "eb076dd86aa93dd424856b150c9b6f76c1fdfabc"
+ "reference": "c1aaa18a7c860c6932677a3e4ec13161f9fc7d61"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/eb076dd86aa93dd424856b150c9b6f76c1fdfabc",
- "reference": "eb076dd86aa93dd424856b150c9b6f76c1fdfabc",
+ "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/c1aaa18a7c860c6932677a3e4ec13161f9fc7d61",
+ "reference": "c1aaa18a7c860c6932677a3e4ec13161f9fc7d61",
"shasum": ""
},
"require": {
- "dealerdirect/phpcodesniffer-composer-installer": "^0.7",
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0",
"php": "^7.4 || ^8.0",
"slevomat/coding-standard": "^7.0",
"squizlabs/php_codesniffer": "^3.6",
@@ -381,20 +311,20 @@
"type": "community_bridge"
}
],
- "time": "2022-08-24T17:45:47+00:00"
+ "time": "2023-01-05T15:53:40+00:00"
},
{
"name": "myclabs/deep-copy",
- "version": "1.11.1",
+ "version": "1.12.0",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c"
+ "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
- "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c",
+ "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c",
"shasum": ""
},
"require": {
@@ -402,11 +332,12 @@
},
"conflict": {
"doctrine/collections": "<1.6.8",
- "doctrine/common": "<2.13.3 || >=3,<3.2.2"
+ "doctrine/common": "<2.13.3 || >=3 <3.2.2"
},
"require-dev": {
"doctrine/collections": "^1.6.8",
"doctrine/common": "^2.13.3 || ^3.2.2",
+ "phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
@@ -432,7 +363,7 @@
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
- "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1"
+ "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0"
},
"funding": [
{
@@ -440,29 +371,31 @@
"type": "tidelift"
}
],
- "time": "2023-03-08T13:26:56+00:00"
+ "time": "2024-06-12T14:39:25+00:00"
},
{
"name": "nikic/php-parser",
- "version": "v4.17.1",
+ "version": "v5.1.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d"
+ "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d",
- "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1",
+ "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1",
"shasum": ""
},
"require": {
+ "ext-ctype": "*",
+ "ext-json": "*",
"ext-tokenizer": "*",
- "php": ">=7.0"
+ "php": ">=7.4"
},
"require-dev": {
"ircmaxell/php-yacc": "^0.0.7",
- "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0"
+ "phpunit/phpunit": "^9.0"
},
"bin": [
"bin/php-parse"
@@ -470,7 +403,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.9-dev"
+ "dev-master": "5.0-dev"
}
},
"autoload": {
@@ -494,26 +427,27 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
- "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1"
+ "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0"
},
- "time": "2023-08-13T19:53:39+00:00"
+ "time": "2024-07-01T20:03:41+00:00"
},
{
"name": "phar-io/manifest",
- "version": "2.0.3",
+ "version": "2.0.4",
"source": {
"type": "git",
"url": "https://github.com/phar-io/manifest.git",
- "reference": "97803eca37d319dfa7826cc2437fc020857acb53"
+ "reference": "54750ef60c58e43759730615a392c31c80e23176"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53",
- "reference": "97803eca37d319dfa7826cc2437fc020857acb53",
+ "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176",
+ "reference": "54750ef60c58e43759730615a392c31c80e23176",
"shasum": ""
},
"require": {
"ext-dom": "*",
+ "ext-libxml": "*",
"ext-phar": "*",
"ext-xmlwriter": "*",
"phar-io/version": "^3.0.1",
@@ -554,9 +488,15 @@
"description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)",
"support": {
"issues": "https://github.com/phar-io/manifest/issues",
- "source": "https://github.com/phar-io/manifest/tree/2.0.3"
+ "source": "https://github.com/phar-io/manifest/tree/2.0.4"
},
- "time": "2021-07-20T11:28:43+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/theseer",
+ "type": "github"
+ }
+ ],
+ "time": "2024-03-03T12:33:53+00:00"
},
{
"name": "phar-io/version",
@@ -655,35 +595,35 @@
},
{
"name": "phpunit/php-code-coverage",
- "version": "9.2.29",
+ "version": "10.1.15",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76"
+ "reference": "5da8b1728acd1e6ffdf2ff32ffbdfd04307f26ae"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76",
- "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5da8b1728acd1e6ffdf2ff32ffbdfd04307f26ae",
+ "reference": "5da8b1728acd1e6ffdf2ff32ffbdfd04307f26ae",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*",
- "nikic/php-parser": "^4.15",
- "php": ">=7.3",
- "phpunit/php-file-iterator": "^3.0.3",
- "phpunit/php-text-template": "^2.0.2",
- "sebastian/code-unit-reverse-lookup": "^2.0.2",
- "sebastian/complexity": "^2.0",
- "sebastian/environment": "^5.1.2",
- "sebastian/lines-of-code": "^1.0.3",
- "sebastian/version": "^3.0.1",
+ "nikic/php-parser": "^4.18 || ^5.0",
+ "php": ">=8.1",
+ "phpunit/php-file-iterator": "^4.0",
+ "phpunit/php-text-template": "^3.0",
+ "sebastian/code-unit-reverse-lookup": "^3.0",
+ "sebastian/complexity": "^3.0",
+ "sebastian/environment": "^6.0",
+ "sebastian/lines-of-code": "^2.0",
+ "sebastian/version": "^4.0",
"theseer/tokenizer": "^1.2.0"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.1"
},
"suggest": {
"ext-pcov": "PHP extension that provides line coverage",
@@ -692,7 +632,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "9.2-dev"
+ "dev-main": "10.1-dev"
}
},
"autoload": {
@@ -721,7 +661,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.15"
},
"funding": [
{
@@ -729,32 +669,32 @@
"type": "github"
}
],
- "time": "2023-09-19T04:57:46+00:00"
+ "time": "2024-06-29T08:25:15+00:00"
},
{
"name": "phpunit/php-file-iterator",
- "version": "3.0.6",
+ "version": "4.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
- "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf"
+ "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
- "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c",
+ "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -781,7 +721,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
- "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6"
+ "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy",
+ "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.1.0"
},
"funding": [
{
@@ -789,28 +730,28 @@
"type": "github"
}
],
- "time": "2021-12-02T12:48:52+00:00"
+ "time": "2023-08-31T06:24:48+00:00"
},
{
"name": "phpunit/php-invoker",
- "version": "3.1.1",
+ "version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-invoker.git",
- "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67"
+ "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67",
- "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7",
+ "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
"ext-pcntl": "*",
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"suggest": {
"ext-pcntl": "*"
@@ -818,7 +759,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.1-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -844,7 +785,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-invoker/issues",
- "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1"
+ "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0"
},
"funding": [
{
@@ -852,32 +793,32 @@
"type": "github"
}
],
- "time": "2020-09-28T05:58:55+00:00"
+ "time": "2023-02-03T06:56:09+00:00"
},
{
"name": "phpunit/php-text-template",
- "version": "2.0.4",
+ "version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
- "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28"
+ "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28",
- "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748",
+ "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.0-dev"
+ "dev-main": "3.0-dev"
}
},
"autoload": {
@@ -903,7 +844,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-text-template/issues",
- "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4"
+ "security": "https://github.com/sebastianbergmann/php-text-template/security/policy",
+ "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1"
},
"funding": [
{
@@ -911,32 +853,32 @@
"type": "github"
}
],
- "time": "2020-10-26T05:33:50+00:00"
+ "time": "2023-08-31T14:07:24+00:00"
},
{
"name": "phpunit/php-timer",
- "version": "5.0.3",
+ "version": "6.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
- "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2"
+ "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2",
- "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d",
+ "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "5.0-dev"
+ "dev-main": "6.0-dev"
}
},
"autoload": {
@@ -962,7 +904,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-timer/issues",
- "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3"
+ "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0"
},
"funding": [
{
@@ -970,54 +912,52 @@
"type": "github"
}
],
- "time": "2020-10-26T13:16:10+00:00"
+ "time": "2023-02-03T06:57:52+00:00"
},
{
"name": "phpunit/phpunit",
- "version": "9.6.13",
+ "version": "10.5.27",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be"
+ "reference": "2425f713b2a5350568ccb1a2d3984841a23e83c5"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be",
- "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2425f713b2a5350568ccb1a2d3984841a23e83c5",
+ "reference": "2425f713b2a5350568ccb1a2d3984841a23e83c5",
"shasum": ""
},
"require": {
- "doctrine/instantiator": "^1.3.1 || ^2",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
- "myclabs/deep-copy": "^1.10.1",
- "phar-io/manifest": "^2.0.3",
- "phar-io/version": "^3.0.2",
- "php": ">=7.3",
- "phpunit/php-code-coverage": "^9.2.28",
- "phpunit/php-file-iterator": "^3.0.5",
- "phpunit/php-invoker": "^3.1.1",
- "phpunit/php-text-template": "^2.0.3",
- "phpunit/php-timer": "^5.0.2",
- "sebastian/cli-parser": "^1.0.1",
- "sebastian/code-unit": "^1.0.6",
- "sebastian/comparator": "^4.0.8",
- "sebastian/diff": "^4.0.3",
- "sebastian/environment": "^5.1.3",
- "sebastian/exporter": "^4.0.5",
- "sebastian/global-state": "^5.0.1",
- "sebastian/object-enumerator": "^4.0.3",
- "sebastian/resource-operations": "^3.0.3",
- "sebastian/type": "^3.2",
- "sebastian/version": "^3.0.2"
+ "myclabs/deep-copy": "^1.12.0",
+ "phar-io/manifest": "^2.0.4",
+ "phar-io/version": "^3.2.1",
+ "php": ">=8.1",
+ "phpunit/php-code-coverage": "^10.1.15",
+ "phpunit/php-file-iterator": "^4.1.0",
+ "phpunit/php-invoker": "^4.0.0",
+ "phpunit/php-text-template": "^3.0.1",
+ "phpunit/php-timer": "^6.0.0",
+ "sebastian/cli-parser": "^2.0.1",
+ "sebastian/code-unit": "^2.0.0",
+ "sebastian/comparator": "^5.0.1",
+ "sebastian/diff": "^5.1.1",
+ "sebastian/environment": "^6.1.0",
+ "sebastian/exporter": "^5.1.2",
+ "sebastian/global-state": "^6.0.2",
+ "sebastian/object-enumerator": "^5.0.0",
+ "sebastian/recursion-context": "^5.0.0",
+ "sebastian/type": "^4.0.0",
+ "sebastian/version": "^4.0.1"
},
"suggest": {
- "ext-soap": "To be able to generate mocks based on WSDL files",
- "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage"
+ "ext-soap": "To be able to generate mocks based on WSDL files"
},
"bin": [
"phpunit"
@@ -1025,7 +965,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "9.6-dev"
+ "dev-main": "10.5-dev"
}
},
"autoload": {
@@ -1057,7 +997,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13"
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.27"
},
"funding": [
{
@@ -1073,32 +1013,32 @@
"type": "tidelift"
}
],
- "time": "2023-09-19T05:39:22+00:00"
+ "time": "2024-07-10T11:48:06+00:00"
},
{
"name": "sebastian/cli-parser",
- "version": "1.0.1",
+ "version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/cli-parser.git",
- "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2"
+ "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2",
- "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2",
+ "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/c34583b87e7b7a8055bf6c450c2c77ce32a24084",
+ "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0-dev"
+ "dev-main": "2.0-dev"
}
},
"autoload": {
@@ -1121,7 +1061,8 @@
"homepage": "https://github.com/sebastianbergmann/cli-parser",
"support": {
"issues": "https://github.com/sebastianbergmann/cli-parser/issues",
- "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1"
+ "security": "https://github.com/sebastianbergmann/cli-parser/security/policy",
+ "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.1"
},
"funding": [
{
@@ -1129,32 +1070,32 @@
"type": "github"
}
],
- "time": "2020-09-28T06:08:49+00:00"
+ "time": "2024-03-02T07:12:49+00:00"
},
{
"name": "sebastian/code-unit",
- "version": "1.0.8",
+ "version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/code-unit.git",
- "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120"
+ "reference": "a81fee9eef0b7a76af11d121767abc44c104e503"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120",
- "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120",
+ "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503",
+ "reference": "a81fee9eef0b7a76af11d121767abc44c104e503",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0-dev"
+ "dev-main": "2.0-dev"
}
},
"autoload": {
@@ -1177,7 +1118,7 @@
"homepage": "https://github.com/sebastianbergmann/code-unit",
"support": {
"issues": "https://github.com/sebastianbergmann/code-unit/issues",
- "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8"
+ "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0"
},
"funding": [
{
@@ -1185,32 +1126,32 @@
"type": "github"
}
],
- "time": "2020-10-26T13:08:54+00:00"
+ "time": "2023-02-03T06:58:43+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
- "version": "2.0.3",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git",
- "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5"
+ "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5",
- "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5",
+ "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d",
+ "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.0-dev"
+ "dev-main": "3.0-dev"
}
},
"autoload": {
@@ -1232,7 +1173,7 @@
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
"support": {
"issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues",
- "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3"
+ "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0"
},
"funding": [
{
@@ -1240,34 +1181,36 @@
"type": "github"
}
],
- "time": "2020-09-28T05:30:19+00:00"
+ "time": "2023-02-03T06:59:15+00:00"
},
{
"name": "sebastian/comparator",
- "version": "4.0.8",
+ "version": "5.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
- "reference": "fa0f136dd2334583309d32b62544682ee972b51a"
+ "reference": "2db5010a484d53ebf536087a70b4a5423c102372"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a",
- "reference": "fa0f136dd2334583309d32b62544682ee972b51a",
+ "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372",
+ "reference": "2db5010a484d53ebf536087a70b4a5423c102372",
"shasum": ""
},
"require": {
- "php": ">=7.3",
- "sebastian/diff": "^4.0",
- "sebastian/exporter": "^4.0"
+ "ext-dom": "*",
+ "ext-mbstring": "*",
+ "php": ">=8.1",
+ "sebastian/diff": "^5.0",
+ "sebastian/exporter": "^5.0"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.3"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.0-dev"
+ "dev-main": "5.0-dev"
}
},
"autoload": {
@@ -1306,7 +1249,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/comparator/issues",
- "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8"
+ "security": "https://github.com/sebastianbergmann/comparator/security/policy",
+ "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1"
},
"funding": [
{
@@ -1314,33 +1258,33 @@
"type": "github"
}
],
- "time": "2022-09-14T12:41:17+00:00"
+ "time": "2023-08-14T13:18:12+00:00"
},
{
"name": "sebastian/complexity",
- "version": "2.0.2",
+ "version": "3.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/complexity.git",
- "reference": "739b35e53379900cc9ac327b2147867b8b6efd88"
+ "reference": "68ff824baeae169ec9f2137158ee529584553799"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88",
- "reference": "739b35e53379900cc9ac327b2147867b8b6efd88",
+ "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68ff824baeae169ec9f2137158ee529584553799",
+ "reference": "68ff824baeae169ec9f2137158ee529584553799",
"shasum": ""
},
"require": {
- "nikic/php-parser": "^4.7",
- "php": ">=7.3"
+ "nikic/php-parser": "^4.18 || ^5.0",
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.0-dev"
+ "dev-main": "3.2-dev"
}
},
"autoload": {
@@ -1363,7 +1307,8 @@
"homepage": "https://github.com/sebastianbergmann/complexity",
"support": {
"issues": "https://github.com/sebastianbergmann/complexity/issues",
- "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2"
+ "security": "https://github.com/sebastianbergmann/complexity/security/policy",
+ "source": "https://github.com/sebastianbergmann/complexity/tree/3.2.0"
},
"funding": [
{
@@ -1371,33 +1316,33 @@
"type": "github"
}
],
- "time": "2020-10-26T15:52:27+00:00"
+ "time": "2023-12-21T08:37:17+00:00"
},
{
"name": "sebastian/diff",
- "version": "4.0.5",
+ "version": "5.1.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
- "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131"
+ "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131",
- "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131",
+ "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/c41e007b4b62af48218231d6c2275e4c9b975b2e",
+ "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3",
- "symfony/process": "^4.2 || ^5"
+ "phpunit/phpunit": "^10.0",
+ "symfony/process": "^6.4"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.0-dev"
+ "dev-main": "5.1-dev"
}
},
"autoload": {
@@ -1429,7 +1374,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/diff/issues",
- "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5"
+ "security": "https://github.com/sebastianbergmann/diff/security/policy",
+ "source": "https://github.com/sebastianbergmann/diff/tree/5.1.1"
},
"funding": [
{
@@ -1437,27 +1383,27 @@
"type": "github"
}
],
- "time": "2023-05-07T05:35:17+00:00"
+ "time": "2024-03-02T07:15:17+00:00"
},
{
"name": "sebastian/environment",
- "version": "5.1.5",
+ "version": "6.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
- "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed"
+ "reference": "8074dbcd93529b357029f5cc5058fd3e43666984"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed",
- "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984",
+ "reference": "8074dbcd93529b357029f5cc5058fd3e43666984",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"suggest": {
"ext-posix": "*"
@@ -1465,7 +1411,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "5.1-dev"
+ "dev-main": "6.1-dev"
}
},
"autoload": {
@@ -1484,7 +1430,7 @@
}
],
"description": "Provides functionality to handle HHVM/PHP environments",
- "homepage": "http://www.github.com/sebastianbergmann/environment",
+ "homepage": "https://github.com/sebastianbergmann/environment",
"keywords": [
"Xdebug",
"environment",
@@ -1492,7 +1438,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/environment/issues",
- "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5"
+ "security": "https://github.com/sebastianbergmann/environment/security/policy",
+ "source": "https://github.com/sebastianbergmann/environment/tree/6.1.0"
},
"funding": [
{
@@ -1500,34 +1447,34 @@
"type": "github"
}
],
- "time": "2023-02-03T06:03:51+00:00"
+ "time": "2024-03-23T08:47:14+00:00"
},
{
"name": "sebastian/exporter",
- "version": "4.0.5",
+ "version": "5.1.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d"
+ "reference": "955288482d97c19a372d3f31006ab3f37da47adf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d",
- "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/955288482d97c19a372d3f31006ab3f37da47adf",
+ "reference": "955288482d97c19a372d3f31006ab3f37da47adf",
"shasum": ""
},
"require": {
- "php": ">=7.3",
- "sebastian/recursion-context": "^4.0"
+ "ext-mbstring": "*",
+ "php": ">=8.1",
+ "sebastian/recursion-context": "^5.0"
},
"require-dev": {
- "ext-mbstring": "*",
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.0-dev"
+ "dev-main": "5.1-dev"
}
},
"autoload": {
@@ -1569,7 +1516,8 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/exporter/issues",
- "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5"
+ "security": "https://github.com/sebastianbergmann/exporter/security/policy",
+ "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.2"
},
"funding": [
{
@@ -1577,38 +1525,35 @@
"type": "github"
}
],
- "time": "2022-09-14T06:03:37+00:00"
+ "time": "2024-03-02T07:17:12+00:00"
},
{
"name": "sebastian/global-state",
- "version": "5.0.6",
+ "version": "6.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
- "reference": "bde739e7565280bda77be70044ac1047bc007e34"
+ "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34",
- "reference": "bde739e7565280bda77be70044ac1047bc007e34",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9",
+ "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9",
"shasum": ""
},
"require": {
- "php": ">=7.3",
- "sebastian/object-reflector": "^2.0",
- "sebastian/recursion-context": "^4.0"
+ "php": ">=8.1",
+ "sebastian/object-reflector": "^3.0",
+ "sebastian/recursion-context": "^5.0"
},
"require-dev": {
"ext-dom": "*",
- "phpunit/phpunit": "^9.3"
- },
- "suggest": {
- "ext-uopz": "*"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "5.0-dev"
+ "dev-main": "6.0-dev"
}
},
"autoload": {
@@ -1627,13 +1572,14 @@
}
],
"description": "Snapshotting of global state",
- "homepage": "http://www.github.com/sebastianbergmann/global-state",
+ "homepage": "https://www.github.com/sebastianbergmann/global-state",
"keywords": [
"global state"
],
"support": {
"issues": "https://github.com/sebastianbergmann/global-state/issues",
- "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6"
+ "security": "https://github.com/sebastianbergmann/global-state/security/policy",
+ "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.2"
},
"funding": [
{
@@ -1641,33 +1587,33 @@
"type": "github"
}
],
- "time": "2023-08-02T09:26:13+00:00"
+ "time": "2024-03-02T07:19:19+00:00"
},
{
"name": "sebastian/lines-of-code",
- "version": "1.0.3",
+ "version": "2.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/lines-of-code.git",
- "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc"
+ "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc",
- "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc",
+ "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/856e7f6a75a84e339195d48c556f23be2ebf75d0",
+ "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0",
"shasum": ""
},
"require": {
- "nikic/php-parser": "^4.6",
- "php": ">=7.3"
+ "nikic/php-parser": "^4.18 || ^5.0",
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0-dev"
+ "dev-main": "2.0-dev"
}
},
"autoload": {
@@ -1690,7 +1636,8 @@
"homepage": "https://github.com/sebastianbergmann/lines-of-code",
"support": {
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
- "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3"
+ "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy",
+ "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.2"
},
"funding": [
{
@@ -1698,34 +1645,34 @@
"type": "github"
}
],
- "time": "2020-11-28T06:42:11+00:00"
+ "time": "2023-12-21T08:38:20+00:00"
},
{
"name": "sebastian/object-enumerator",
- "version": "4.0.4",
+ "version": "5.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
- "reference": "5c9eeac41b290a3712d88851518825ad78f45c71"
+ "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71",
- "reference": "5c9eeac41b290a3712d88851518825ad78f45c71",
+ "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906",
+ "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906",
"shasum": ""
},
"require": {
- "php": ">=7.3",
- "sebastian/object-reflector": "^2.0",
- "sebastian/recursion-context": "^4.0"
+ "php": ">=8.1",
+ "sebastian/object-reflector": "^3.0",
+ "sebastian/recursion-context": "^5.0"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.0-dev"
+ "dev-main": "5.0-dev"
}
},
"autoload": {
@@ -1747,7 +1694,7 @@
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
"support": {
"issues": "https://github.com/sebastianbergmann/object-enumerator/issues",
- "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4"
+ "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0"
},
"funding": [
{
@@ -1755,32 +1702,32 @@
"type": "github"
}
],
- "time": "2020-10-26T13:12:34+00:00"
+ "time": "2023-02-03T07:08:32+00:00"
},
{
"name": "sebastian/object-reflector",
- "version": "2.0.4",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-reflector.git",
- "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7"
+ "reference": "24ed13d98130f0e7122df55d06c5c4942a577957"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7",
- "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7",
+ "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957",
+ "reference": "24ed13d98130f0e7122df55d06c5c4942a577957",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.0-dev"
+ "dev-main": "3.0-dev"
}
},
"autoload": {
@@ -1802,7 +1749,7 @@
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
"support": {
"issues": "https://github.com/sebastianbergmann/object-reflector/issues",
- "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4"
+ "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0"
},
"funding": [
{
@@ -1810,32 +1757,32 @@
"type": "github"
}
],
- "time": "2020-10-26T13:14:26+00:00"
+ "time": "2023-02-03T07:06:18+00:00"
},
{
"name": "sebastian/recursion-context",
- "version": "4.0.5",
+ "version": "5.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
- "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1"
+ "reference": "05909fb5bc7df4c52992396d0116aed689f93712"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1",
- "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712",
+ "reference": "05909fb5bc7df4c52992396d0116aed689f93712",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.0-dev"
+ "dev-main": "5.0-dev"
}
},
"autoload": {
@@ -1865,62 +1812,7 @@
"homepage": "https://github.com/sebastianbergmann/recursion-context",
"support": {
"issues": "https://github.com/sebastianbergmann/recursion-context/issues",
- "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5"
- },
- "funding": [
- {
- "url": "https://github.com/sebastianbergmann",
- "type": "github"
- }
- ],
- "time": "2023-02-03T06:07:39+00:00"
- },
- {
- "name": "sebastian/resource-operations",
- "version": "3.0.3",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/resource-operations.git",
- "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8",
- "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8",
- "shasum": ""
- },
- "require": {
- "php": ">=7.3"
- },
- "require-dev": {
- "phpunit/phpunit": "^9.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "3.0-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
- }
- ],
- "description": "Provides a list of PHP built-in functions that operate on resources",
- "homepage": "https://www.github.com/sebastianbergmann/resource-operations",
- "support": {
- "issues": "https://github.com/sebastianbergmann/resource-operations/issues",
- "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3"
+ "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.0"
},
"funding": [
{
@@ -1928,32 +1820,32 @@
"type": "github"
}
],
- "time": "2020-09-28T06:45:17+00:00"
+ "time": "2023-02-03T07:05:40+00:00"
},
{
"name": "sebastian/type",
- "version": "3.2.1",
+ "version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/type.git",
- "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7"
+ "reference": "462699a16464c3944eefc02ebdd77882bd3925bf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7",
- "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7",
+ "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf",
+ "reference": "462699a16464c3944eefc02ebdd77882bd3925bf",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.5"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.2-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -1976,7 +1868,7 @@
"homepage": "https://github.com/sebastianbergmann/type",
"support": {
"issues": "https://github.com/sebastianbergmann/type/issues",
- "source": "https://github.com/sebastianbergmann/type/tree/3.2.1"
+ "source": "https://github.com/sebastianbergmann/type/tree/4.0.0"
},
"funding": [
{
@@ -1984,29 +1876,29 @@
"type": "github"
}
],
- "time": "2023-02-03T06:13:03+00:00"
+ "time": "2023-02-03T07:10:45+00:00"
},
{
"name": "sebastian/version",
- "version": "3.0.2",
+ "version": "4.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
- "reference": "c6c1022351a901512170118436c764e473f6de8c"
+ "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c",
- "reference": "c6c1022351a901512170118436c764e473f6de8c",
+ "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17",
+ "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17",
"shasum": ""
},
"require": {
- "php": ">=7.3"
+ "php": ">=8.1"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -2029,7 +1921,7 @@
"homepage": "https://github.com/sebastianbergmann/version",
"support": {
"issues": "https://github.com/sebastianbergmann/version/issues",
- "source": "https://github.com/sebastianbergmann/version/tree/3.0.2"
+ "source": "https://github.com/sebastianbergmann/version/tree/4.0.1"
},
"funding": [
{
@@ -2037,7 +1929,7 @@
"type": "github"
}
],
- "time": "2020-09-28T06:39:44+00:00"
+ "time": "2023-02-07T11:34:05+00:00"
},
{
"name": "slevomat/coding-standard",
@@ -2159,16 +2051,16 @@
},
{
"name": "theseer/tokenizer",
- "version": "1.2.1",
+ "version": "1.2.3",
"source": {
"type": "git",
"url": "https://github.com/theseer/tokenizer.git",
- "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e"
+ "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e",
- "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e",
+ "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2",
+ "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2",
"shasum": ""
},
"require": {
@@ -2197,7 +2089,7 @@
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"support": {
"issues": "https://github.com/theseer/tokenizer/issues",
- "source": "https://github.com/theseer/tokenizer/tree/1.2.1"
+ "source": "https://github.com/theseer/tokenizer/tree/1.2.3"
},
"funding": [
{
@@ -2205,7 +2097,7 @@
"type": "github"
}
],
- "time": "2021-07-28T10:34:58+00:00"
+ "time": "2024-03-03T12:36:25+00:00"
},
{
"name": "webimpress/coding-standard",
@@ -2269,12 +2161,12 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
- "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
+ "php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"ext-mbstring": "*"
},
"platform-dev": [],
"platform-overrides": {
- "php": "8.0.99"
+ "php": "8.1.99"
},
"plugin-api-version": "2.6.0"
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 53cca465..186eb279 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,26 +1,20 @@
-
-
-
- ./test
-
-
-
-
-
- ./src
-
-
-
-
-
-
-
+
+
+
diff --git a/src/BlockCipher.php b/src/BlockCipher.php
index 1ec079e5..69caae52 100644
--- a/src/BlockCipher.php
+++ b/src/BlockCipher.php
@@ -1,5 +1,7 @@
cipher = $cipher;
+ public function __construct(
+ /**
+ * Symmetric cipher
+ */
+ protected SymmetricInterface $cipher
+ ) {
}
/**
* Factory
- *
- * @param string $adapter
- * @param array $options
- * @return BlockCipher
*/
- public static function factory($adapter, $options = [])
+ public static function factory(string $adapter, array $options = []): static
{
$plugins = static::getSymmetricPluginManager();
try {
$cipher = $plugins->get($adapter);
- } catch (NotFoundException $e) {
+ } catch (NotFoundException) {
throw new Exception\RuntimeException(sprintf(
'The symmetric adapter %s does not exist',
$adapter
@@ -114,12 +92,10 @@ public static function factory($adapter, $options = [])
/**
* Returns the symmetric cipher plugin manager. If it doesn't exist it's created.
- *
- * @return ContainerInterface
*/
- public static function getSymmetricPluginManager()
+ public static function getSymmetricPluginManager(): ContainerInterface
{
- if (static::$symmetricPlugins === null) {
+ if (! static::$symmetricPlugins instanceof ContainerInterface) {
static::setSymmetricPluginManager(new SymmetricPluginManager());
}
@@ -132,7 +108,7 @@ public static function getSymmetricPluginManager()
* @param string|SymmetricPluginManager $plugins
* @throws Exception\InvalidArgumentException
*/
- public static function setSymmetricPluginManager($plugins)
+ public static function setSymmetricPluginManager(string|ContainerInterface $plugins): void
{
if (is_string($plugins)) {
if (! class_exists($plugins) || ! is_subclass_of($plugins, ContainerInterface::class)) {
@@ -144,21 +120,13 @@ public static function setSymmetricPluginManager($plugins)
}
$plugins = new $plugins();
}
- if (! $plugins instanceof ContainerInterface) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Symmetric plugin must implements Interop\Container\ContainerInterface;; received "%s"',
- is_object($plugins) ? get_class($plugins) : gettype($plugins)
- ));
- }
static::$symmetricPlugins = $plugins;
}
/**
* Set the symmetric cipher
- *
- * @return BlockCipher Provides a fluent interface
*/
- public function setCipher(SymmetricInterface $cipher)
+ public function setCipher(SymmetricInterface $cipher): static
{
$this->cipher = $cipher;
return $this;
@@ -166,33 +134,26 @@ public function setCipher(SymmetricInterface $cipher)
/**
* Get symmetric cipher
- *
- * @return SymmetricInterface
*/
- public function getCipher()
+ public function getCipher(): SymmetricInterface
{
return $this->cipher;
}
/**
* Set the number of iterations for Pbkdf2
- *
- * @param int $num
- * @return BlockCipher Provides a fluent interface
*/
- public function setKeyIteration($num)
+ public function setKeyIteration(int $num): static
{
- $this->keyIteration = (int) $num;
+ $this->keyIteration = $num;
return $this;
}
/**
* Get the number of iterations for Pbkdf2
- *
- * @return int
*/
- public function getKeyIteration()
+ public function getKeyIteration(): int
{
return $this->keyIteration;
}
@@ -200,11 +161,9 @@ public function getKeyIteration()
/**
* Set the salt (IV)
*
- * @param string $salt
- * @return BlockCipher Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setSalt($salt)
+ public function setSalt(string $salt): static
{
try {
$this->cipher->setSalt($salt);
@@ -218,43 +177,34 @@ public function setSalt($salt)
/**
* Get the salt (IV) according to the size requested by the algorithm
- *
- * @return string
*/
- public function getSalt()
+ public function getSalt(): string|null
{
return $this->cipher->getSalt();
}
/**
* Get the original salt value
- *
- * @return string
*/
- public function getOriginalSalt()
+ public function getOriginalSalt(): string
{
return $this->cipher->getOriginalSalt();
}
/**
* Enable/disable the binary output
- *
- * @param bool $value
- * @return BlockCipher Provides a fluent interface
*/
- public function setBinaryOutput($value)
+ public function setBinaryOutput(bool $value): static
{
- $this->binaryOutput = (bool) $value;
+ $this->binaryOutput = $value;
return $this;
}
/**
* Get the value of binary output
- *
- * @return bool
*/
- public function getBinaryOutput()
+ public function getBinaryOutput(): bool
{
return $this->binaryOutput;
}
@@ -262,13 +212,11 @@ public function getBinaryOutput()
/**
* Set the encryption/decryption key
*
- * @param string $key
- * @return BlockCipher Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setKey($key)
+ public function setKey(string $key): static
{
- if (empty($key)) {
+ if ($key === '' || $key === '0') {
throw new Exception\InvalidArgumentException('The key cannot be empty');
}
$this->key = $key;
@@ -278,10 +226,8 @@ public function setKey($key)
/**
* Get the key
- *
- * @return string
*/
- public function getKey()
+ public function getKey(): string
{
return $this->key;
}
@@ -289,11 +235,9 @@ public function getKey()
/**
* Set algorithm of the symmetric cipher
*
- * @param string $algo
- * @return BlockCipher Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setCipherAlgorithm($algo)
+ public function setCipherAlgorithm(string $algo): static
{
try {
$this->cipher->setAlgorithm($algo);
@@ -306,20 +250,16 @@ public function setCipherAlgorithm($algo)
/**
* Get the cipher algorithm
- *
- * @return string|bool
*/
- public function getCipherAlgorithm()
+ public function getCipherAlgorithm(): string
{
return $this->cipher->getAlgorithm();
}
/**
* Get the supported algorithms of the symmetric cipher
- *
- * @return array
*/
- public function getCipherSupportedAlgorithms()
+ public function getCipherSupportedAlgorithms(): array
{
return $this->cipher->getSupportedAlgorithms();
}
@@ -327,11 +267,9 @@ public function getCipherSupportedAlgorithms()
/**
* Set the hash algorithm for HMAC authentication
*
- * @param string $hash
- * @return BlockCipher Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setHashAlgorithm($hash)
+ public function setHashAlgorithm(string $hash): static
{
if (! Hash::isSupported($hash)) {
throw new Exception\InvalidArgumentException(
@@ -345,10 +283,8 @@ public function setHashAlgorithm($hash)
/**
* Get the hash algorithm for HMAC authentication
- *
- * @return string
*/
- public function getHashAlgorithm()
+ public function getHashAlgorithm(): string
{
return $this->hash;
}
@@ -356,11 +292,9 @@ public function getHashAlgorithm()
/**
* Set the hash algorithm for the Pbkdf2
*
- * @param string $hash
- * @return BlockCipher Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setPbkdf2HashAlgorithm($hash)
+ public function setPbkdf2HashAlgorithm(string $hash): static
{
if (! Hash::isSupported($hash)) {
throw new Exception\InvalidArgumentException(
@@ -374,10 +308,8 @@ public function setPbkdf2HashAlgorithm($hash)
/**
* Get the Pbkdf2 hash algorithm
- *
- * @return string
*/
- public function getPbkdf2HashAlgorithm()
+ public function getPbkdf2HashAlgorithm(): string
{
return $this->pbkdf2Hash;
}
@@ -385,11 +317,9 @@ public function getPbkdf2HashAlgorithm()
/**
* Encrypt then authenticate using HMAC
*
- * @param string $data
- * @return string
* @throws Exception\InvalidArgumentException
*/
- public function encrypt($data)
+ public function encrypt(string $data): string
{
// 0 (as integer), 0.0 (as float) & '0' (as string) will return false, though these should be allowed
// Must be a string, integer, or float in order to encrypt
@@ -406,7 +336,7 @@ public function encrypt($data)
$data = (string) $data;
}
- if (empty($this->key)) {
+ if (! isset($this->key) || ($this->key === '' || $this->key === '0')) {
throw new Exception\InvalidArgumentException('No key specified for the encryption');
}
$keySize = $this->cipher->getKeySize();
@@ -442,11 +372,9 @@ public function encrypt($data)
/**
* Decrypt
*
- * @param string $data
- * @return string|bool
* @throws Exception\InvalidArgumentException
*/
- public function decrypt($data)
+ public function decrypt(string $data): string|false
{
if (! is_string($data)) {
throw new Exception\InvalidArgumentException('The data to decrypt must be a string');
@@ -454,7 +382,7 @@ public function decrypt($data)
if ('' === $data) {
throw new Exception\InvalidArgumentException('The data to decrypt cannot be empty');
}
- if (empty($this->key)) {
+ if (! isset($this->key) || ($this->key === '' || $this->key === '0')) {
throw new Exception\InvalidArgumentException('No key specified for the decryption');
}
@@ -494,12 +422,9 @@ public function decrypt($data)
/**
* Note: CCM and GCM modes do not need HMAC
*
- * @param string $data
- * @param int $keySize
- * @return string
* @throws Exception\InvalidArgumentException
*/
- private function encryptViaCcmOrGcm($data, $keySize)
+ private function encryptViaCcmOrGcm(string $data, int $keySize): string
{
$this->cipher->setKey(Pbkdf2::calc(
$this->getPbkdf2HashAlgorithm(),
@@ -517,12 +442,9 @@ private function encryptViaCcmOrGcm($data, $keySize)
/**
* Note: CCM and GCM modes do not need HMAC
*
- * @param string $data
- * @param int $keySize
- * @return string
* @throws Exception\InvalidArgumentException
*/
- private function decryptViaCcmOrGcm($data, $keySize)
+ private function decryptViaCcmOrGcm(string $data, int $keySize): string
{
$cipherText = $this->binaryOutput ? $data : base64_decode($data);
$iv = mb_substr($cipherText, $this->cipher->getTagSize(), $this->cipher->getSaltSize(), '8bit');
diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php
index c2ce6b3b..e32dffb1 100644
--- a/src/Exception/ExceptionInterface.php
+++ b/src/Exception/ExceptionInterface.php
@@ -1,5 +1,7 @@
cipher = $cipher;
@@ -76,40 +66,32 @@ public function __construct(?Symmetric\SymmetricInterface $cipher = null)
/**
* Set the cipher object
- *
- * @param SymmetricInterface $cipher
*/
- public function setCipher(Symmetric\SymmetricInterface $cipher)
+ public function setCipher(SymmetricInterface $cipher): void
{
$this->cipher = $cipher;
}
/**
* Get the cipher object
- *
- * @return SymmetricInterface
*/
- public function getCipher()
+ public function getCipher(): ?SymmetricInterface
{
return $this->cipher;
}
/**
* Set the number of iterations for Pbkdf2
- *
- * @param int $num
*/
- public function setKeyIteration($num)
+ public function setKeyIteration(int $num): void
{
- $this->keyIteration = (int) $num;
+ $this->keyIteration = $num;
}
/**
* Get the number of iterations for Pbkdf2
- *
- * @return int
*/
- public function getKeyIteration()
+ public function getKeyIteration(): int
{
return $this->keyIteration;
}
@@ -117,53 +99,44 @@ public function getKeyIteration()
/**
* Set the encryption/decryption key
*
- * @param string $key
* @throws Exception\InvalidArgumentException
*/
- public function setKey($key)
+ public function setKey(string $key): void
{
- if (empty($key)) {
+ if ($key === '' || $key === '0') {
throw new Exception\InvalidArgumentException('The key cannot be empty');
}
- $this->key = (string) $key;
+ $this->key = $key;
}
/**
* Get the key
- *
- * @return string|null
*/
- public function getKey()
+ public function getKey(): string|null
{
return $this->key;
}
/**
* Set algorithm of the symmetric cipher
- *
- * @param string $algo
*/
- public function setCipherAlgorithm($algo)
+ public function setCipherAlgorithm(string $algo): void
{
$this->cipher->setAlgorithm($algo);
}
/**
* Get the cipher algorithm
- *
- * @return string|bool
*/
- public function getCipherAlgorithm()
+ public function getCipherAlgorithm(): string
{
return $this->cipher->getAlgorithm();
}
/**
* Get the supported algorithms of the symmetric cipher
- *
- * @return array
*/
- public function getCipherSupportedAlgorithms()
+ public function getCipherSupportedAlgorithms(): array
{
return $this->cipher->getSupportedAlgorithms();
}
@@ -171,25 +144,22 @@ public function getCipherSupportedAlgorithms()
/**
* Set the hash algorithm for HMAC authentication
*
- * @param string $hash
* @throws Exception\InvalidArgumentException
*/
- public function setHashAlgorithm($hash)
+ public function setHashAlgorithm(string $hash): void
{
if (! Hash::isSupported($hash)) {
throw new Exception\InvalidArgumentException(
"The specified hash algorithm '{$hash}' is not supported by Laminas\Crypt\Hash"
);
}
- $this->hash = (string) $hash;
+ $this->hash = $hash;
}
/**
* Get the hash algorithm for HMAC authentication
- *
- * @return string
*/
- public function getHashAlgorithm()
+ public function getHashAlgorithm(): string
{
return $this->hash;
}
@@ -197,25 +167,22 @@ public function getHashAlgorithm()
/**
* Set the hash algorithm for the Pbkdf2
*
- * @param string $hash
* @throws Exception\InvalidArgumentException
*/
- public function setPbkdf2HashAlgorithm($hash)
+ public function setPbkdf2HashAlgorithm(string $hash): void
{
if (! Hash::isSupported($hash)) {
throw new Exception\InvalidArgumentException(
"The specified hash algorithm '{$hash}' is not supported by Laminas\Crypt\Hash"
);
}
- $this->pbkdf2Hash = (string) $hash;
+ $this->pbkdf2Hash = $hash;
}
/**
* Get the Pbkdf2 hash algorithm
- *
- * @return string
*/
- public function getPbkdf2HashAlgorithm()
+ public function getPbkdf2HashAlgorithm(): string
{
return $this->pbkdf2Hash;
}
@@ -223,15 +190,12 @@ public function getPbkdf2HashAlgorithm()
/**
* Encrypt then authenticate a file using HMAC
*
- * @param string $fileIn
- * @param string $fileOut
- * @return bool
* @throws Exception\InvalidArgumentException
*/
- public function encrypt($fileIn, $fileOut)
+ public function encrypt(string $fileIn, string $fileOut): bool
{
$this->checkFileInOut($fileIn, $fileOut);
- if (empty($this->key)) {
+ if (! isset($this->key) || ($this->key === '' || $this->key === '0')) {
throw new Exception\InvalidArgumentException('No key specified for encryption');
}
@@ -269,7 +233,7 @@ public function encrypt($fileIn, $fileOut)
$result = $this->cipher->encrypt($data);
if ($size <= self::BUFFER_SIZE) {
// Write a placeholder for the HMAC and write the IV
- fwrite($write, str_repeat(0, Hmac::getOutputSize($hashAlgo)));
+ fwrite($write, str_repeat('0', Hmac::getOutputSize($hashAlgo)));
} else {
$result = mb_substr($result, $saltSize, null, '8bit');
}
@@ -298,15 +262,12 @@ public function encrypt($fileIn, $fileOut)
/**
* Decrypt a file
*
- * @param string $fileIn
- * @param string $fileOut
- * @return bool
* @throws Exception\InvalidArgumentException
*/
- public function decrypt($fileIn, $fileOut)
+ public function decrypt(string $fileIn, string $fileOut): bool
{
$this->checkFileInOut($fileIn, $fileOut);
- if (empty($this->key)) {
+ if (! isset($this->key) || ($this->key === '' || $this->key === '0')) {
throw new Exception\InvalidArgumentException('No key specified for decryption');
}
@@ -368,11 +329,9 @@ public function decrypt($fileIn, $fileOut)
/**
* Check that input file exists and output file don't
*
- * @param string $fileIn
- * @param string $fileOut
* @throws Exception\InvalidArgumentException
*/
- protected function checkFileInOut($fileIn, $fileOut)
+ protected function checkFileInOut(string $fileIn, string $fileOut): void
{
if (! file_exists($fileIn)) {
throw new Exception\InvalidArgumentException(sprintf(
diff --git a/src/Hash.php b/src/Hash.php
index 93591fe0..74a7a9bc 100644
--- a/src/Hash.php
+++ b/src/Hash.php
@@ -1,11 +1,12 @@
bCipher = $bCipher ?? BlockCipher::factory('openssl');
- $this->rsa = $rsa ?? new PublicKey\Rsa();
}
/**
* Encrypt using a keyrings
*
- * @param string $plaintext
- * @param array|string $keys
- * @return string
* @throws RuntimeException
*/
- public function encrypt($plaintext, $keys = null)
+ public function encrypt(string $plaintext, array|string|Stringable|null $keys = null): string
{
// generate a random session key
$sessionKey = Rand::getBytes($this->bCipher->getCipher()->getKeySize());
@@ -72,7 +69,7 @@ public function encrypt($plaintext, $keys = null)
$pubkey = is_string($pubkey) ? new PubKey($pubkey) : $pubkey;
$encKeys .= sprintf(
"%s:%s:",
- base64_encode($id),
+ base64_encode((string) $id),
base64_encode($this->rsa->encrypt($sessionKey, $pubkey))
);
}
@@ -82,15 +79,14 @@ public function encrypt($plaintext, $keys = null)
/**
* Decrypt using a private key
*
- * @param string $msg
- * @param string $privateKey
- * @param string $passPhrase
- * @param string $id
- * @return string
* @throws RuntimeException
*/
- public function decrypt($msg, $privateKey = null, $passPhrase = null, $id = "")
- {
+ public function decrypt(
+ string $msg,
+ string|PrivateKey|null $privateKey = null,
+ ?string $passPhrase = null,
+ string $id = ""
+ ): string|false {
// get the session key
[$encKeys, $ciphertext] = explode(';', $msg, 2);
@@ -115,25 +111,21 @@ public function decrypt($msg, $privateKey = null, $passPhrase = null, $id = "")
// decrypt the plaintext with the blockcipher algorithm
$this->bCipher->setKey($sessionKey);
- return $this->bCipher->decrypt($ciphertext, $sessionKey);
+ return $this->bCipher->decrypt($ciphertext);
}
/**
* Get the BlockCipher adapter
- *
- * @return BlockCipher
*/
- public function getBlockCipherInstance()
+ public function getBlockCipherInstance(): BlockCipher
{
return $this->bCipher;
}
/**
* Get the Rsa instance
- *
- * @return Rsa
*/
- public function getRsaInstance()
+ public function getRsaInstance(): Rsa
{
return $this->rsa;
}
diff --git a/src/Key/Derivation/Exception/ExceptionInterface.php b/src/Key/Derivation/Exception/ExceptionInterface.php
index 35486013..388f3138 100644
--- a/src/Key/Derivation/Exception/ExceptionInterface.php
+++ b/src/Key/Derivation/Exception/ExceptionInterface.php
@@ -1,5 +1,7 @@
0 and a power of 2");
@@ -65,13 +64,8 @@ public static function calc($password, $salt, $n, $r, $p, $length)
* scryptROMix
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-4
- *
- * @param string $b
- * @param int $n
- * @param int $r
- * @return string
*/
- protected static function scryptROMix($b, $n, $r)
+ protected static function scryptROMix(string $b, int $n, int $r): string
{
$x = $b;
$v = [];
@@ -91,12 +85,8 @@ protected static function scryptROMix($b, $n, $r)
* scryptBlockMix
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-3
- *
- * @param string $b
- * @param int $r
- * @return string
*/
- protected static function scryptBlockMix($b, $r)
+ protected static function scryptBlockMix(string $b, int $r): string
{
$x = mb_substr($b, -64, null, '8bit');
$even = '';
@@ -123,11 +113,8 @@ protected static function scryptBlockMix($b, $r)
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-2
* @see http://cr.yp.to/salsa20.html
- *
- * @param string $b
- * @return string
*/
- protected static function salsa208Core32($b)
+ protected static function salsa208Core32(string $b): string
{
$b32 = [];
for ($i = 0; $i < 16; $i++) {
@@ -217,11 +204,8 @@ protected static function salsa208Core32($b)
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-2
* @see http://cr.yp.to/salsa20.html
- *
- * @param string $b
- * @return string
*/
- protected static function salsa208Core64($b)
+ protected static function salsa208Core64(string $b): string
{
$b32 = [];
for ($i = 0; $i < 16; $i++) {
@@ -314,11 +298,8 @@ protected static function salsa208Core64($b)
* Each block B is a string of 64 bytes.
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-4
- *
- * @param string $b
- * @return int
*/
- protected static function integerify($b)
+ protected static function integerify(string $b): int
{
$v = 'v';
if (PHP_INT_SIZE === 8) {
diff --git a/src/Password/Apache.php b/src/Password/Apache.php
index a1a34190..cab769f7 100644
--- a/src/Password/Apache.php
+++ b/src/Password/Apache.php
@@ -1,5 +1,7 @@
$value) {
- switch (strtolower($key)) {
+ switch (strtolower((string) $key)) {
case 'format':
$this->setFormat($value);
break;
@@ -88,13 +87,11 @@ public function __construct($options = [])
/**
* Generate the hash of a password
*
- * @param string $password
* @throws Exception\RuntimeException
- * @return string
*/
- public function create($password)
+ public function create(string $password): string
{
- if (empty($this->format)) {
+ if (! isset($this->format) || ($this->format === '' || $this->format === '0')) {
throw new Exception\RuntimeException(
'You must specify a password format'
);
@@ -110,7 +107,11 @@ public function create($password)
$hash = $this->apr1Md5($password);
break;
case 'digest':
- if (empty($this->userName) || empty($this->authName)) {
+ if (
+ ! isset($this->userName)
+ || ($this->userName === '' || $this->userName === '0')
+ || (! isset($this->authName) || ($this->authName === '' || $this->authName === '0'))
+ ) {
throw new Exception\RuntimeException(
'You must specify UserName and AuthName (realm) to generate the digest'
);
@@ -124,12 +125,8 @@ public function create($password)
/**
* Verify if a password is correct against a hash value
- *
- * @param string $password
- * @param string $hash
- * @return bool
*/
- public function verify($password, $hash)
+ public function verify(string $password, string $hash): bool
{
if (mb_substr($hash, 0, 5, '8bit') === '{SHA}') {
$hash2 = '{SHA}' . base64_encode(sha1($password, true));
@@ -147,10 +144,14 @@ public function verify($password, $hash)
return Utils::compareStrings($hash, $hash2);
}
- $bcryptPattern = '/\$2[ay]?\$[0-9]{2}\$[' . addcslashes(static::BASE64, '+/') . '\.]{53}/';
+ $bcryptPattern = '/\$2[ay]?\$[0-9]{2}\$[' . addcslashes((string) static::BASE64, '+/') . '\.]{53}/';
if (mb_strlen($hash, '8bit') > 13 && ! preg_match($bcryptPattern, $hash)) { // digest
- if (empty($this->userName) || empty($this->authName)) {
+ if (
+ ! isset($this->userName)
+ || ($this->userName === '' || $this->userName === '0')
+ || (! isset($this->authName) || ($this->authName === '' || $this->authName === '0'))
+ ) {
throw new Exception\RuntimeException(
'You must specify UserName and AuthName (realm) to verify the digest'
);
@@ -165,11 +166,10 @@ public function verify($password, $hash)
/**
* Set the format of the password
*
- * @param string $format
* @throws Exception\InvalidArgumentException
* @return Apache Provides a fluent interface
*/
- public function setFormat($format)
+ public function setFormat(string $format): Apache
{
$format = strtolower($format);
if (! in_array($format, $this->supportedFormat)) {
@@ -186,21 +186,16 @@ public function setFormat($format)
/**
* Get the format of the password
- *
- * @return string
*/
- public function getFormat()
+ public function getFormat(): string
{
return $this->format;
}
/**
* Set the AuthName (for digest authentication)
- *
- * @param string $name
- * @return Apache Provides a fluent interface
*/
- public function setAuthName($name)
+ public function setAuthName(string $name): static
{
$this->authName = $name;
@@ -209,21 +204,16 @@ public function setAuthName($name)
/**
* Get the AuthName (for digest authentication)
- *
- * @return string
*/
- public function getAuthName()
+ public function getAuthName(): string
{
return $this->authName;
}
/**
* Set the username
- *
- * @param string $name
- * @return Apache Provides a fluent interface
*/
- public function setUserName($name)
+ public function setUserName(string $name): static
{
$this->userName = $name;
@@ -232,33 +222,24 @@ public function setUserName($name)
/**
* Get the username
- *
- * @return string
*/
- public function getUserName()
+ public function getUserName(): string
{
return $this->userName;
}
/**
* Convert a binary string using the alphabet "./0-9A-Za-z"
- *
- * @param string $value
- * @return string
*/
- protected function toAlphabet64($value)
+ protected function toAlphabet64(string $value): string
{
return strtr(strrev(mb_substr(base64_encode($value), 2, null, '8bit')), self::BASE64, self::ALPHA64);
}
/**
* APR1 MD5 algorithm
- *
- * @param string $password
- * @param null|string $salt
- * @return string
*/
- protected function apr1Md5($password, $salt = null)
+ protected function apr1Md5(string $password, string|null $salt = null): string
{
if (null === $salt) {
$salt = Rand::getString(8, self::ALPHA64);
@@ -269,7 +250,7 @@ protected function apr1Md5($password, $salt = null)
);
}
for ($i = 0; $i < 8; $i++) {
- if (strpos(self::ALPHA64, $salt[$i]) === false) {
+ if (! str_contains(self::ALPHA64, $salt[$i])) {
throw new Exception\InvalidArgumentException(
'The salt value must be a string in the alphabet "./0-9A-Za-z"'
);
@@ -283,18 +264,18 @@ protected function apr1Md5($password, $salt = null)
$text .= mb_substr($bin, 0, min(16, $i), '8bit');
}
for ($i = $len; $i > 0; $i >>= 1) {
- $text .= $i & 1 ? chr(0) : $password[0];
+ $text .= ($i & 1) !== 0 ? chr(0) : $password[0];
}
$bin = pack("H32", md5($text));
for ($i = 0; $i < 1000; $i++) {
- $new = $i & 1 ? $password : $bin;
- if ($i % 3) {
+ $new = ($i & 1) !== 0 ? $password : $bin;
+ if ($i % 3 !== 0) {
$new .= $salt;
}
- if ($i % 7) {
+ if ($i % 7 !== 0) {
$new .= $password;
}
- $new .= $i & 1 ? $bin : $password;
+ $new .= ($i & 1) !== 0 ? $bin : $password;
$bin = pack("H32", md5($new));
}
$tmp = '';
diff --git a/src/Password/Bcrypt.php b/src/Password/Bcrypt.php
index 4a511d1f..b36fc4bd 100644
--- a/src/Password/Bcrypt.php
+++ b/src/Password/Bcrypt.php
@@ -1,23 +1,20 @@
(int) $this->cost];
- if (PHP_VERSION_ID < 70000) { // salt is deprecated from PHP 7.0
- $salt = $this->salt ?: Rand::getBytes(self::MIN_SALT_SIZE);
- $options['salt'] = $salt;
- }
return password_hash($password, PASSWORD_BCRYPT, $options);
}
/**
* Verify if a password is correct against a hash value
- *
- * @param string $password
- * @param string $hash
- * @return bool
*/
- public function verify($password, $hash)
+ public function verify(string $password, string $hash): bool
{
return password_verify($password, $hash);
}
@@ -96,13 +80,11 @@ public function verify($password, $hash)
/**
* Set the cost parameter
*
- * @param int|string $cost
* @throws Exception\InvalidArgumentException
- * @return Bcrypt Provides a fluent interface
*/
- public function setCost($cost)
+ public function setCost(int|string $cost): static
{
- if (! empty($cost)) {
+ if ($cost !== 0 && ($cost !== '' && $cost !== '0')) {
$cost = (int) $cost;
if ($cost < 4 || $cost > 31) {
throw new Exception\InvalidArgumentException(
@@ -116,51 +98,12 @@ public function setCost($cost)
/**
* Get the cost parameter
- *
- * @return string
*/
- public function getCost()
+ public function getCost(): string
{
return $this->cost;
}
- /**
- * Set the salt value
- *
- * @param string $salt
- * @throws Exception\InvalidArgumentException
- * @return Bcrypt Provides a fluent interface
- */
- public function setSalt($salt)
- {
- if (PHP_VERSION_ID >= 70000) {
- trigger_error('Salt support is deprecated starting with PHP 7.0.0', E_USER_DEPRECATED);
- }
-
- if (mb_strlen($salt, '8bit') < self::MIN_SALT_SIZE) {
- throw new Exception\InvalidArgumentException(
- 'The length of the salt must be at least ' . self::MIN_SALT_SIZE . ' bytes'
- );
- }
-
- $this->salt = $salt;
- return $this;
- }
-
- /**
- * Get the salt value
- *
- * @return string
- */
- public function getSalt()
- {
- if (PHP_VERSION_ID >= 70000) {
- trigger_error('Salt support is deprecated starting with PHP 7.0.0', E_USER_DEPRECATED);
- }
-
- return $this->salt;
- }
-
/**
* Benchmark the bcrypt hash generation to determine the cost parameter based on time to target.
*
@@ -174,7 +117,7 @@ public function getSalt()
* @param float $timeTarget Defaults to 50ms (0.05)
* @return int Maximum cost value that falls within the time to target.
*/
- public function benchmarkCost($timeTarget = 0.05)
+ public function benchmarkCost(float $timeTarget = 0.05): int
{
$cost = 8;
diff --git a/src/Password/BcryptSha.php b/src/Password/BcryptSha.php
index 3870e05b..4c6a1597 100644
--- a/src/Password/BcryptSha.php
+++ b/src/Password/BcryptSha.php
@@ -1,5 +1,7 @@
math = Math\BigInteger\BigInteger::factory();
@@ -117,21 +106,19 @@ public function __construct($prime, $generator, $privateKey = null, $privateKeyF
* Set whether to use openssl extension
*
* @static
- * @param bool $flag
*/
- public static function useOpensslExtension($flag = true)
+ public static function useOpensslExtension(bool $flag = true): void
{
- static::$useOpenssl = (bool) $flag;
+ static::$useOpenssl = $flag;
}
/**
* Generate own public key. If a private number has not already been set,
* one will be generated at this stage.
*
- * @return DiffieHellman Provides a fluent interface
* @throws RuntimeException
*/
- public function generateKeys()
+ public function generateKeys(): static
{
if (function_exists('openssl_dh_compute_key') && static::$useOpenssl !== false) {
$details = [
@@ -179,18 +166,15 @@ public function generateKeys()
/**
* Setter for the value of the public number
*
- * @param string $number
- * @param string $format
- * @return DiffieHellman Provides a fluent interface
* @throws InvalidArgumentException
*/
- public function setPublicKey($number, $format = self::FORMAT_NUMBER)
+ public function setPublicKey(string $number, string $format = self::FORMAT_NUMBER): static
{
$number = $this->convert($number, $format, self::FORMAT_NUMBER);
if (! preg_match('/^\d+$/', $number)) {
throw new Exception\InvalidArgumentException('Invalid parameter; not a positive natural number');
}
- $this->publicKey = (string) $number;
+ $this->publicKey = $number;
return $this;
}
@@ -198,11 +182,9 @@ public function setPublicKey($number, $format = self::FORMAT_NUMBER)
/**
* Returns own public key for communication to the second party to this transaction
*
- * @param string $format
- * @return string
* @throws InvalidArgumentException
*/
- public function getPublicKey($format = self::FORMAT_NUMBER)
+ public function getPublicKey(string $format = self::FORMAT_NUMBER): string
{
if ($this->publicKey === null) {
throw new Exception\InvalidArgumentException(
@@ -224,18 +206,14 @@ public function getPublicKey($format = self::FORMAT_NUMBER)
* If you need the binary form of the shared secret key, call
* getSharedSecretKey() with the optional parameter for Binary output.
*
- * @param string $publicKey
- * @param string $publicKeyFormat
- * @param string $secretKeyFormat
- * @return string
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function computeSecretKey(
- $publicKey,
- $publicKeyFormat = self::FORMAT_NUMBER,
- $secretKeyFormat = self::FORMAT_NUMBER
- ) {
+ string $publicKey,
+ string $publicKeyFormat = self::FORMAT_NUMBER,
+ string $secretKeyFormat = self::FORMAT_NUMBER
+ ): string {
if (function_exists('openssl_dh_compute_key') && static::$useOpenssl !== false) {
$publicKey = $this->convert($publicKey, $publicKeyFormat, self::FORMAT_BINARY);
$secretKey = openssl_dh_compute_key($publicKey, $this->opensslKeyResource);
@@ -261,13 +239,11 @@ public function computeSecretKey(
/**
* Return the computed shared secret key from the DiffieHellman transaction
*
- * @param string $format
- * @return string
* @throws InvalidArgumentException
*/
- public function getSharedSecretKey($format = self::FORMAT_NUMBER)
+ public function getSharedSecretKey(string $format = self::FORMAT_NUMBER): string
{
- if (! isset($this->secretKey)) {
+ if ($this->secretKey === null) {
throw new Exception\InvalidArgumentException(
'A secret key has not yet been computed; call computeSecretKey() first'
);
@@ -279,11 +255,9 @@ public function getSharedSecretKey($format = self::FORMAT_NUMBER)
/**
* Setter for the value of the prime number
*
- * @param string $number
- * @return DiffieHellman Provides a fluent interface
* @throws InvalidArgumentException
*/
- public function setPrime($number)
+ public function setPrime(string $number): static
{
if (! preg_match('/^\d+$/', $number) || $number < 11) {
throw new Exception\InvalidArgumentException(
@@ -291,7 +265,7 @@ public function setPrime($number)
. 'should be a large natural number prime'
);
}
- $this->prime = (string) $number;
+ $this->prime = $number;
return $this;
}
@@ -299,13 +273,11 @@ public function setPrime($number)
/**
* Getter for the value of the prime number
*
- * @param string $format
- * @return string
* @throws InvalidArgumentException
*/
- public function getPrime($format = self::FORMAT_NUMBER)
+ public function getPrime(string $format = self::FORMAT_NUMBER): string
{
- if (! isset($this->prime)) {
+ if ($this->prime === null) {
throw new Exception\InvalidArgumentException('No prime number has been set');
}
@@ -315,18 +287,16 @@ public function getPrime($format = self::FORMAT_NUMBER)
/**
* Setter for the value of the generator number
*
- * @param string $number
- * @return DiffieHellman Provides a fluent interface
* @throws InvalidArgumentException
*/
- public function setGenerator($number)
+ public function setGenerator(string $number): static
{
if (! preg_match('/^\d+$/', $number) || $number < 2) {
throw new Exception\InvalidArgumentException(
'Invalid parameter; not a positive natural number greater than 1'
);
}
- $this->generator = (string) $number;
+ $this->generator = $number;
return $this;
}
@@ -334,13 +304,11 @@ public function setGenerator($number)
/**
* Getter for the value of the generator number
*
- * @param string $format
- * @return string
* @throws InvalidArgumentException
*/
- public function getGenerator($format = self::FORMAT_NUMBER)
+ public function getGenerator(string $format = self::FORMAT_NUMBER): string
{
- if (! isset($this->generator)) {
+ if ($this->generator === null) {
throw new Exception\InvalidArgumentException('No generator number has been set');
}
@@ -350,29 +318,23 @@ public function getGenerator($format = self::FORMAT_NUMBER)
/**
* Setter for the value of the private number
*
- * @param string $number
- * @param string $format
- * @return DiffieHellman Provides a fluent interface
* @throws InvalidArgumentException
*/
- public function setPrivateKey($number, $format = self::FORMAT_NUMBER)
+ public function setPrivateKey(string $number, string $format = self::FORMAT_NUMBER): static
{
$number = $this->convert($number, $format, self::FORMAT_NUMBER);
if (! preg_match('/^\d+$/', $number)) {
throw new Exception\InvalidArgumentException('Invalid parameter; not a positive natural number');
}
- $this->privateKey = (string) $number;
+ $this->privateKey = $number;
return $this;
}
/**
* Getter for the value of the private number
- *
- * @param string $format
- * @return string
*/
- public function getPrivateKey($format = self::FORMAT_NUMBER)
+ public function getPrivateKey(string $format = self::FORMAT_NUMBER): string
{
if (! $this->hasPrivateKey()) {
$this->setPrivateKey($this->generatePrivateKey(), self::FORMAT_BINARY);
@@ -383,24 +345,20 @@ public function getPrivateKey($format = self::FORMAT_NUMBER)
/**
* Check whether a private key currently exists.
- *
- * @return bool
*/
- public function hasPrivateKey()
+ public function hasPrivateKey(): bool
{
- return isset($this->privateKey);
+ return $this->privateKey !== null;
}
/**
* Convert number between formats
- *
- * @param string $number
- * @param string $inputFormat
- * @param string $outputFormat
- * @return string
*/
- protected function convert($number, $inputFormat = self::FORMAT_NUMBER, $outputFormat = self::FORMAT_BINARY)
- {
+ protected function convert(
+ string $number,
+ string $inputFormat = self::FORMAT_NUMBER,
+ string $outputFormat = self::FORMAT_BINARY
+ ): string {
if ($inputFormat === $outputFormat) {
return $number;
}
@@ -418,15 +376,11 @@ protected function convert($number, $inputFormat = self::FORMAT_NUMBER, $outputF
}
// convert to output format
- switch ($outputFormat) {
- case self::FORMAT_BINARY:
- return $this->math->intToBin($number);
- case self::FORMAT_BTWOC:
- return $this->math->intToBin($number, true);
- case self::FORMAT_NUMBER:
- default:
- return $number;
- }
+ return match ($outputFormat) {
+ self::FORMAT_BINARY => $this->math->intToBin($number),
+ self::FORMAT_BTWOC => $this->math->intToBin($number, true),
+ default => $number,
+ };
}
/**
@@ -435,10 +389,8 @@ protected function convert($number, $inputFormat = self::FORMAT_NUMBER, $outputF
* generate a random key. Having a random number generator installed
* on linux/bsd is highly recommended! The alternative is not recommended
* for production unless without any other option.
- *
- * @return string
*/
- protected function generatePrivateKey()
+ protected function generatePrivateKey(): string
{
return Math\Rand::getBytes(mb_strlen($this->getPrime(), '8bit'));
}
diff --git a/src/PublicKey/Rsa.php b/src/PublicKey/Rsa.php
index abc4f890..3bb1632e 100644
--- a/src/PublicKey/Rsa.php
+++ b/src/PublicKey/Rsa.php
@@ -1,8 +1,14 @@
options = new RsaOptions();
- } else {
- $this->options = $options;
- }
}
/**
* Set options
- *
- * @return Rsa Provides a fluent interface
*/
- public function setOptions(RsaOptions $options)
+ public function setOptions(RsaOptions $options): static
{
$this->options = $options;
return $this;
@@ -124,20 +117,16 @@ public function setOptions(RsaOptions $options)
/**
* Get options
- *
- * @return RsaOptions
*/
- public function getOptions()
+ public function getOptions(): RsaOptions
{
return $this->options;
}
/**
* Return last openssl error(s)
- *
- * @return string
*/
- public function getOpensslErrorString()
+ public function getOpensslErrorString(): string
{
$message = '';
while (false !== ($error = openssl_error_string())) {
@@ -149,14 +138,12 @@ public function getOpensslErrorString()
/**
* Sign with private key
*
- * @param string $data
- * @return string
* @throws Rsa\Exception\RuntimeException
*/
- public function sign($data, ?Rsa\PrivateKey $privateKey = null)
+ public function sign(string $data, ?Rsa\PrivateKey $privateKey = null): string
{
$signature = '';
- if (null === $privateKey) {
+ if (! $privateKey instanceof PrivateKey) {
$privateKey = $this->options->getPrivateKey();
}
@@ -176,7 +163,7 @@ public function sign($data, ?Rsa\PrivateKey $privateKey = null)
return $signature;
}
- return base64_encode($signature);
+ return base64_encode((string) $signature);
}
/**
@@ -191,19 +178,16 @@ public function sign($data, ?Rsa\PrivateKey $privateKey = null)
* @see Rsa::MODE_BASE64
* @see Rsa::MODE_RAW
*
- * @param string $data
- * @param string $signature
* @param int $mode Input encoding
- * @return bool
* @throws Rsa\Exception\RuntimeException
*/
public function verify(
- $data,
- $signature,
+ string $data,
+ string $signature,
?Rsa\PublicKey $publicKey = null,
- $mode = self::MODE_AUTO
- ) {
- if (null === $publicKey) {
+ int $mode = self::MODE_AUTO
+ ): bool {
+ if (! $publicKey instanceof PublicKey) {
$publicKey = $this->options->getPublicKey();
}
@@ -241,26 +225,20 @@ public function verify(
/**
* Encrypt with private/public key
*
- * @param string $data
- * @return string
* @throws Rsa\Exception\InvalidArgumentException
*/
- public function encrypt($data, ?Rsa\AbstractKey $key = null)
+ public function encrypt(string $data, ?Rsa\AbstractKey $key = null): string
{
- if (null === $key) {
+ if (! $key instanceof AbstractKey) {
$key = $this->options->getPublicKey();
}
- if (null === $key) {
+ if (! $key instanceof AbstractKey) {
throw new Exception\InvalidArgumentException('No key specified for the decryption');
}
- $padding = $this->getOptions()->getOpensslPadding();
- if (null === $padding) {
- $encrypted = $key->encrypt($data);
- } else {
- $encrypted = $key->encrypt($data, $padding);
- }
+ $padding = $this->getOptions()->getOpensslPadding();
+ $encrypted = null === $padding ? $key->encrypt($data) : $key->encrypt($data, $padding);
if ($this->options->getBinaryOutput()) {
return $encrypted;
@@ -281,21 +259,19 @@ public function encrypt($data, ?Rsa\AbstractKey $key = null)
* @see Rsa::MODE_BASE64
* @see Rsa::MODE_RAW
*
- * @param string $data
* @param int $mode Input encoding
- * @return string
* @throws Rsa\Exception\InvalidArgumentException
*/
public function decrypt(
- $data,
+ string $data,
?Rsa\AbstractKey $key = null,
- $mode = self::MODE_AUTO
- ) {
- if (null === $key) {
+ int $mode = self::MODE_AUTO
+ ): string {
+ if (! $key instanceof AbstractKey) {
$key = $this->options->getPrivateKey();
}
- if (null === $key) {
+ if (! $key instanceof AbstractKey) {
throw new Exception\InvalidArgumentException('No key specified for the decryption');
}
@@ -322,19 +298,4 @@ public function decrypt(
return $key->decrypt($data, $padding);
}
}
-
- /**
- * Generate new private/public key pair
- *
- * @see RsaOptions::generateKeys()
- *
- * @param array $opensslConfig
- * @return Rsa Provides a fluent interface
- * @throws Rsa\Exception\RuntimeException
- */
- public function generateKeys(array $opensslConfig = [])
- {
- $this->options->generateKeys($opensslConfig);
- return $this;
- }
}
diff --git a/src/PublicKey/Rsa/AbstractKey.php b/src/PublicKey/Rsa/AbstractKey.php
index f6015b9c..391864ea 100644
--- a/src/PublicKey/Rsa/AbstractKey.php
+++ b/src/PublicKey/Rsa/AbstractKey.php
@@ -1,17 +1,19 @@
details['bits'];
- }
+ protected array $details = [];
/**
* Retrieve openssl key resource
@@ -51,32 +41,24 @@ public function getOpensslKeyResource()
* Encrypt using this key
*
* @abstract
- * @param string $data
- * @return string
*/
- abstract public function encrypt($data);
+ abstract public function encrypt(string $data): string;
/**
* Decrypt using this key
*
* @abstract
- * @param string $data
- * @return string
*/
- abstract public function decrypt($data);
+ abstract public function decrypt(string $data): string;
/**
* Get string representation of this key
*
* @abstract
- * @return string
*/
- abstract public function toString();
+ abstract public function toString(): string;
- /**
- * @return string
- */
- public function __toString()
+ public function __toString(): string
{
return $this->toString();
}
diff --git a/src/PublicKey/Rsa/Exception/ExceptionInterface.php b/src/PublicKey/Rsa/Exception/ExceptionInterface.php
index acbf58ab..7e3ce627 100644
--- a/src/PublicKey/Rsa/Exception/ExceptionInterface.php
+++ b/src/PublicKey/Rsa/Exception/ExceptionInterface.php
@@ -1,5 +1,7 @@
publicKey === null) {
$this->publicKey = new PublicKey($this->details['key']);
@@ -83,15 +76,12 @@ public function getPublicKey()
/**
* Encrypt using this key
*
- * @param string $data
- * @param integer $padding
- * @return string
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*/
- public function encrypt($data, $padding = OPENSSL_PKCS1_PADDING)
+ public function encrypt(string $data, int $padding = OPENSSL_PKCS1_PADDING): string
{
- if (empty($data)) {
+ if ($data === '' || $data === '0') {
throw new Exception\InvalidArgumentException('The data to encrypt cannot be empty');
}
@@ -115,13 +105,10 @@ public function encrypt($data, $padding = OPENSSL_PKCS1_PADDING)
*
* @see http://archiv.infsec.ethz.ch/education/fs08/secsem/bleichenbacher98.pdf
*
- * @param string $data
- * @param integer $padding
- * @return string
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*/
- public function decrypt($data, $padding = OPENSSL_PKCS1_OAEP_PADDING)
+ public function decrypt(string $data, int $padding = OPENSSL_PKCS1_OAEP_PADDING): string
{
if (! is_string($data)) {
throw new Exception\InvalidArgumentException('The data to decrypt must be a string');
@@ -141,10 +128,7 @@ public function decrypt($data, $padding = OPENSSL_PKCS1_OAEP_PADDING)
return $decrypted;
}
- /**
- * @return string
- */
- public function toString()
+ public function toString(): string
{
return $this->pemString;
}
diff --git a/src/PublicKey/Rsa/PublicKey.php b/src/PublicKey/Rsa/PublicKey.php
index ec6d746b..e071a645 100644
--- a/src/PublicKey/Rsa/PublicKey.php
+++ b/src/PublicKey/Rsa/PublicKey.php
@@ -1,5 +1,7 @@
certificateString = $pemStringOrCertificate;
} else {
$this->pemString = $pemStringOrCertificate;
@@ -78,15 +76,12 @@ public function __construct($pemStringOrCertificate)
*
* @see http://archiv.infsec.ethz.ch/education/fs08/secsem/bleichenbacher98.pdf
*
- * @param string $data
- * @param string $padding
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
- * @return string
*/
- public function encrypt($data, $padding = OPENSSL_PKCS1_OAEP_PADDING)
+ public function encrypt(string $data, int $padding = OPENSSL_PKCS1_OAEP_PADDING): string
{
- if (empty($data)) {
+ if ($data === '' || $data === '0') {
throw new Exception\InvalidArgumentException('The data to encrypt cannot be empty');
}
@@ -104,13 +99,10 @@ public function encrypt($data, $padding = OPENSSL_PKCS1_OAEP_PADDING)
/**
* Decrypt using this key
*
- * @param string $data
- * @param string $padding
- * @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
- * @return string
+ * @throws Exception\InvalidArgumentException
*/
- public function decrypt($data, $padding = OPENSSL_PKCS1_PADDING)
+ public function decrypt(string $data, int $padding = OPENSSL_PKCS1_PADDING): string
{
if (! is_string($data)) {
throw new Exception\InvalidArgumentException('The data to decrypt must be a string');
@@ -130,27 +122,16 @@ public function decrypt($data, $padding = OPENSSL_PKCS1_PADDING)
return $decrypted;
}
- /**
- * Get certificate string
- *
- * @return string
- */
- public function getCertificate()
- {
- return $this->certificateString;
- }
-
/**
* To string
*
- * @return string
* @throws Exception\RuntimeException
*/
- public function toString()
+ public function toString(): string
{
- if (! empty($this->certificateString)) {
+ if (isset($this->certificateString) && ($this->certificateString !== '' && $this->certificateString !== '0')) {
return $this->certificateString;
- } elseif (! empty($this->pemString)) {
+ } elseif ($this->pemString !== '' && $this->pemString !== '0') {
return $this->pemString;
}
throw new Exception\RuntimeException('No public key string representation is available');
diff --git a/src/PublicKey/RsaOptions.php b/src/PublicKey/RsaOptions.php
index dbb3e516..028a1780 100644
--- a/src/PublicKey/RsaOptions.php
+++ b/src/PublicKey/RsaOptions.php
@@ -1,5 +1,7 @@
privateKey = $key;
$this->publicKey = $this->privateKey->getPublicKey();
@@ -69,20 +59,16 @@ public function setPrivateKey(Rsa\PrivateKey $key)
/**
* Get private key
- *
- * @return null|Rsa\PrivateKey
*/
- public function getPrivateKey()
+ public function getPrivateKey(): Rsa\PrivateKey|null
{
return $this->privateKey;
}
/**
* Set public key
- *
- * @return RsaOptions Provides a fluent interface
*/
- public function setPublicKey(Rsa\PublicKey $key)
+ public function setPublicKey(Rsa\PublicKey $key): static
{
$this->publicKey = $key;
return $this;
@@ -90,23 +76,18 @@ public function setPublicKey(Rsa\PublicKey $key)
/**
* Get public key
- *
- * @return null|Rsa\PublicKey
*/
- public function getPublicKey()
+ public function getPublicKey(): Rsa\PublicKey|null
{
return $this->publicKey;
}
/**
* Set pass phrase
- *
- * @param string $phrase
- * @return RsaOptions Provides a fluent interface
*/
- public function setPassPhrase($phrase)
+ public function setPassPhrase(string $phrase): static
{
- $this->passPhrase = (string) $phrase;
+ $this->passPhrase = $phrase;
return $this;
}
@@ -115,7 +96,7 @@ public function setPassPhrase($phrase)
*
* @return string
*/
- public function getPassPhrase()
+ public function getPassPhrase(): string|null
{
return $this->passPhrase;
}
@@ -123,12 +104,10 @@ public function getPassPhrase()
/**
* Set hash algorithm
*
- * @param string $hash
- * @return RsaOptions Provides a fluent interface
* @throws Rsa\Exception\RuntimeException
* @throws Rsa\Exception\InvalidArgumentException
*/
- public function setHashAlgorithm($hash)
+ public function setHashAlgorithm(string $hash): static
{
$hashUpper = strtoupper($hash);
if (! defined('OPENSSL_ALGO_' . $hashUpper)) {
@@ -144,18 +123,15 @@ public function setHashAlgorithm($hash)
/**
* Get hash algorithm
- *
- * @return string
*/
- public function getHashAlgorithm()
+ public function getHashAlgorithm(): string
{
return $this->hashAlgorithm;
}
- /** @return string */
- public function getOpensslSignatureAlgorithm()
+ public function getOpensslSignatureAlgorithm(): int
{
- if (! isset($this->opensslSignatureAlgorithm)) {
+ if ($this->opensslSignatureAlgorithm === null) {
$this->opensslSignatureAlgorithm = constant('OPENSSL_ALGO_' . strtoupper($this->hashAlgorithm));
}
return $this->opensslSignatureAlgorithm;
@@ -163,56 +139,44 @@ public function getOpensslSignatureAlgorithm()
/**
* Enable/disable the binary output
- *
- * @param bool $value
- * @return RsaOptions Provides a fluent interface
*/
- public function setBinaryOutput($value)
+ public function setBinaryOutput(bool $value): static
{
- $this->binaryOutput = (bool) $value;
+ $this->binaryOutput = $value;
return $this;
}
/**
* Get the value of binary output
- *
- * @return bool
*/
- public function getBinaryOutput()
+ public function getBinaryOutput(): bool
{
return $this->binaryOutput;
}
/**
* Get the OPENSSL padding
- *
- * @return int|null
*/
- public function getOpensslPadding()
+ public function getOpensslPadding(): int|null
{
return $this->opensslPadding;
}
/**
* Set the OPENSSL padding
- *
- * @param int|null $opensslPadding
- * @return RsaOptions Provides a fluent interface
*/
- public function setOpensslPadding($opensslPadding)
+ public function setOpensslPadding(int $opensslPadding): static
{
- $this->opensslPadding = (int) $opensslPadding;
+ $this->opensslPadding = $opensslPadding;
return $this;
}
/**
* Generate new private/public key pair
*
- * @param array $opensslConfig
- * @return RsaOptions Provides a fluent interface
* @throws Rsa\Exception\RuntimeException
*/
- public function generateKeys(array $opensslConfig = [])
+ public function generateKeys(array $opensslConfig = []): static
{
$opensslConfig = array_replace(
[
diff --git a/src/Symmetric/Exception/ExceptionInterface.php b/src/Symmetric/Exception/ExceptionInterface.php
index e78af23a..78e9f2f4 100644
--- a/src/Symmetric/Exception/ExceptionInterface.php
+++ b/src/Symmetric/Exception/ExceptionInterface.php
@@ -1,5 +1,7 @@
'rijndael-128',
- 'blowfish' => 'blowfish',
- 'des' => 'des',
- '3des' => 'tripledes',
- 'tripledes' => 'tripledes',
- 'cast-128' => 'cast-128',
- 'cast-256' => 'cast-256',
- 'rijndael-128' => 'rijndael-128',
- 'rijndael-192' => 'rijndael-192',
- 'rijndael-256' => 'rijndael-256',
- 'saferplus' => 'saferplus',
- 'serpent' => 'serpent',
- 'twofish' => 'twofish',
- ];
-
- /**
- * Supported encryption modes
- *
- * @var array
- */
- protected $supportedModes = [
- 'cbc' => 'cbc',
- 'cfb' => 'cfb',
- 'ctr' => 'ctr',
- 'ofb' => 'ofb',
- 'nofb' => 'nofb',
- 'ncfb' => 'ncfb',
- ];
-
- /**
- * Constructor
- *
- * @param array|Traversable $options
- * @throws Exception\RuntimeException
- * @throws Exception\InvalidArgumentException
- */
- public function __construct($options = [])
- {
- if (PHP_VERSION_ID >= 70100) {
- trigger_error(
- 'The Mcrypt extension is deprecated from PHP 7.1+. '
- . 'We suggest to use Laminas\Crypt\Symmetric\Openssl.',
- E_USER_DEPRECATED
- );
- }
- if (! extension_loaded('mcrypt')) {
- throw new Exception\RuntimeException(sprintf(
- 'You cannot use %s without the Mcrypt extension',
- self::class
- ));
- }
- $this->setOptions($options);
- $this->setDefaultOptions($options);
- }
-
- /**
- * Set default options
- *
- * @param array $options
- * @return void
- */
- public function setOptions($options)
- {
- if (! empty($options)) {
- if ($options instanceof Traversable) {
- $options = ArrayUtils::iteratorToArray($options);
- } elseif (! is_array($options)) {
- throw new Exception\InvalidArgumentException(
- 'The options parameter must be an array or a Traversable'
- );
- }
- foreach ($options as $key => $value) {
- switch (strtolower($key)) {
- case 'algo':
- case 'algorithm':
- $this->setAlgorithm($value);
- break;
- case 'mode':
- $this->setMode($value);
- break;
- case 'key':
- $this->setKey($value);
- break;
- case 'iv':
- case 'salt':
- $this->setSalt($value);
- break;
- case 'padding':
- $plugins = static::getPaddingPluginManager();
- $padding = $plugins->get($value);
- $this->padding = $padding;
- break;
- }
- }
- }
- }
-
- /**
- * Set default options
- *
- * @param array $options
- * @return void
- */
- protected function setDefaultOptions($options = [])
- {
- if (! isset($options['padding'])) {
- $plugins = static::getPaddingPluginManager();
- $padding = $plugins->get(self::DEFAULT_PADDING);
- $this->padding = $padding;
- }
- }
-
- /**
- * Returns the padding plugin manager. If it doesn't exist it's created.
- *
- * @return ContainerInterface
- */
- public static function getPaddingPluginManager()
- {
- if (static::$paddingPlugins === null) {
- self::setPaddingPluginManager(new PaddingPluginManager());
- }
-
- return static::$paddingPlugins;
- }
-
- /**
- * Set the padding plugin manager
- *
- * @param string|ContainerInterface $plugins
- * @throws Exception\InvalidArgumentException
- * @return void
- */
- public static function setPaddingPluginManager($plugins)
- {
- if (is_string($plugins)) {
- if (! class_exists($plugins) || ! is_subclass_of($plugins, ContainerInterface::class)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Unable to locate padding plugin manager via class "%s"; '
- . 'class does not exist or does not implement ContainerInterface',
- $plugins
- ));
- }
- $plugins = new $plugins();
- }
- if (! $plugins instanceof ContainerInterface) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Padding plugins must implements Psr\Container\ContainerInterface; received "%s"',
- is_object($plugins) ? get_class($plugins) : gettype($plugins)
- ));
- }
- static::$paddingPlugins = $plugins;
- }
-
- /**
- * Get the maximum key size for the selected cipher and mode of operation
- *
- * @return int
- */
- public function getKeySize()
- {
- return mcrypt_get_key_size($this->supportedAlgos[$this->algo], $this->supportedModes[$this->mode]);
- }
-
- /**
- * Set the encryption key
- * If the key is longer than maximum supported, it will be truncated by getKey().
- *
- * @param string $key
- * @return Mcrypt Provides a fluent interface
- * @throws Exception\InvalidArgumentException
- */
- public function setKey($key)
- {
- $keyLen = mb_strlen($key, '8bit');
-
- if (! $keyLen) {
- throw new Exception\InvalidArgumentException('The key cannot be empty');
- }
- $keySizes = mcrypt_module_get_supported_key_sizes($this->supportedAlgos[$this->algo]);
- $maxKey = $this->getKeySize();
-
- /*
- * blowfish has $keySizes empty, meaning it can have arbitrary key length.
- * the others are more picky.
- */
- if (! empty($keySizes) && $keyLen < $maxKey) {
- if (! in_array($keyLen, $keySizes)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'The size of the key must be %s bytes or longer',
- implode(', ', $keySizes)
- ));
- }
- }
- $this->key = $key;
-
- return $this;
- }
-
- /**
- * Get the encryption key
- *
- * @return string
- */
- public function getKey()
- {
- if (empty($this->key)) {
- return;
- }
- return mb_substr($this->key, 0, $this->getKeySize(), '8bit');
- }
-
- /**
- * Set the encryption algorithm (cipher)
- *
- * @param string $algo
- * @return Mcrypt Provides a fluent interface
- * @throws Exception\InvalidArgumentException
- */
- public function setAlgorithm($algo)
- {
- if (! array_key_exists($algo, $this->supportedAlgos)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'The algorithm %s is not supported by %s',
- $algo,
- self::class
- ));
- }
- $this->algo = $algo;
-
- return $this;
- }
-
- /**
- * Get the encryption algorithm
- *
- * @return string
- */
- public function getAlgorithm()
- {
- return $this->algo;
- }
-
- /**
- * Set the padding object
- *
- * @return Mcrypt Provides a fluent interface
- */
- public function setPadding(Padding\PaddingInterface $padding)
- {
- $this->padding = $padding;
-
- return $this;
- }
-
- /**
- * Get the padding object
- *
- * @return Padding\PaddingInterface
- */
- public function getPadding()
- {
- return $this->padding;
- }
-
- /**
- * Encrypt
- *
- * @param string $data
- * @throws Exception\InvalidArgumentException
- * @return string
- */
- public function encrypt($data)
- {
- // Cannot encrypt empty string
- if (! is_string($data) || $data === '') {
- throw new Exception\InvalidArgumentException('The data to encrypt cannot be empty');
- }
- if (null === $this->getKey()) {
- throw new Exception\InvalidArgumentException('No key specified for the encryption');
- }
- if (null === $this->getSalt()) {
- throw new Exception\InvalidArgumentException('The salt (IV) cannot be empty');
- }
- if (null === $this->getPadding()) {
- throw new Exception\InvalidArgumentException('You have to specify a padding method');
- }
- // padding
- $data = $this->padding->pad($data, $this->getBlockSize());
- $iv = $this->getSalt();
- // encryption
- $result = mcrypt_encrypt(
- $this->supportedAlgos[$this->algo],
- $this->getKey(),
- $data,
- $this->supportedModes[$this->mode],
- $iv
- );
-
- return $iv . $result;
- }
-
- /**
- * Decrypt
- *
- * @param string $data
- * @throws Exception\InvalidArgumentException
- * @return string
- */
- public function decrypt($data)
- {
- if (empty($data)) {
- throw new Exception\InvalidArgumentException('The data to decrypt cannot be empty');
- }
- if (null === $this->getKey()) {
- throw new Exception\InvalidArgumentException('No key specified for the decryption');
- }
- if (null === $this->getPadding()) {
- throw new Exception\InvalidArgumentException('You have to specify a padding method');
- }
- $iv = mb_substr($data, 0, $this->getSaltSize(), '8bit');
- $ciphertext = mb_substr($data, $this->getSaltSize(), null, '8bit');
- $result = mcrypt_decrypt(
- $this->supportedAlgos[$this->algo],
- $this->getKey(),
- $ciphertext,
- $this->supportedModes[$this->mode],
- $iv
- );
- // unpadding
- return $this->padding->strip($result);
- }
-
- /**
- * Get the salt (IV) size
- *
- * @return int
- */
- public function getSaltSize()
- {
- return mcrypt_get_iv_size($this->supportedAlgos[$this->algo], $this->supportedModes[$this->mode]);
- }
-
- /**
- * Get the supported algorithms
- *
- * @return array
- */
- public function getSupportedAlgorithms()
- {
- return array_keys($this->supportedAlgos);
- }
-
- /**
- * Set the salt (IV)
- *
- * @param string $salt
- * @return Mcrypt Provides a fluent interface
- * @throws Exception\InvalidArgumentException
- */
- public function setSalt($salt)
- {
- if (empty($salt)) {
- throw new Exception\InvalidArgumentException('The salt (IV) cannot be empty');
- }
- if (mb_strlen($salt, '8bit') < $this->getSaltSize()) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'The size of the salt (IV) must be at least %d bytes',
- $this->getSaltSize()
- ));
- }
- $this->iv = $salt;
-
- return $this;
- }
-
- /**
- * Get the salt (IV) according to the size requested by the algorithm
- *
- * @return string
- */
- public function getSalt()
- {
- if (empty($this->iv)) {
- return;
- }
- if (mb_strlen($this->iv, '8bit') < $this->getSaltSize()) {
- throw new Exception\RuntimeException(sprintf(
- 'The size of the salt (IV) must be at least %d bytes',
- $this->getSaltSize()
- ));
- }
-
- return mb_substr($this->iv, 0, $this->getSaltSize(), '8bit');
- }
-
- /**
- * Get the original salt value
- *
- * @return string
- */
- public function getOriginalSalt()
- {
- return $this->iv;
- }
-
- /**
- * Set the cipher mode
- *
- * @param string $mode
- * @return Mcrypt Provides a fluent interface
- * @throws Exception\InvalidArgumentException
- */
- public function setMode($mode)
- {
- if (! empty($mode)) {
- $mode = strtolower($mode);
- if (! array_key_exists($mode, $this->supportedModes)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'The mode %s is not supported by %s',
- $mode,
- $this->algo
- ));
- }
- $this->mode = $mode;
- }
-
- return $this;
- }
-
- /**
- * Get the cipher mode
- *
- * @return string
- */
- public function getMode()
- {
- return $this->mode;
- }
-
- /**
- * Get all supported encryption modes
- *
- * @return array
- */
- public function getSupportedModes()
- {
- return array_keys($this->supportedModes);
- }
-
- /**
- * Get the block size
- *
- * @return int
- */
- public function getBlockSize()
- {
- return mcrypt_get_block_size($this->supportedAlgos[$this->algo], $this->supportedModes[$this->mode]);
- }
-}
diff --git a/src/Symmetric/Openssl.php b/src/Symmetric/Openssl.php
index 3514e5fd..04a9f321 100644
--- a/src/Symmetric/Openssl.php
+++ b/src/Symmetric/Openssl.php
@@ -1,20 +1,19 @@
*/
- public $supportedAlgos;
+ public array $supportedAlgos = [];
/**
* Constructor
*
- * @param array|Traversable $options
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*/
- public function __construct($options = [])
+ public function __construct(Traversable|array $options = [])
{
if (! extension_loaded('openssl')) {
throw new Exception\RuntimeException(sprintf(
@@ -192,10 +170,8 @@ public function __construct($options = [])
self::class
));
}
- // Add the GCM and CCM modes for PHP 7.1+
- if (PHP_VERSION_ID >= 70100) {
- array_push($this->encryptionModes, 'gcm', 'ccm');
- }
+ $this->encryptionModes[] = 'gcm';
+ $this->encryptionModes[] = 'ccm';
$this->setOptions($options);
$this->setDefaultOptions($options);
}
@@ -203,12 +179,10 @@ public function __construct($options = [])
/**
* Set default options
*
- * @param array $options
- * @return void
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*/
- public function setOptions($options)
+ public function setOptions(Traversable|array $options): void
{
if (empty($options)) {
return;
@@ -261,11 +235,8 @@ public function setOptions($options)
/**
* Set default options
- *
- * @param array $options
- * @return void
*/
- protected function setDefaultOptions($options = [])
+ protected function setDefaultOptions(array|ArrayAccess $options = []): void
{
if (isset($options['padding'])) {
return;
@@ -280,12 +251,10 @@ protected function setDefaultOptions($options = [])
* Returns the padding plugin manager.
*
* Creates one if none is present.
- *
- * @return ContainerInterface
*/
- public static function getPaddingPluginManager()
+ public static function getPaddingPluginManager(): ContainerInterface
{
- if (static::$paddingPlugins === null) {
+ if (! static::$paddingPlugins instanceof ContainerInterface) {
self::setPaddingPluginManager(new PaddingPluginManager());
}
@@ -295,11 +264,9 @@ public static function getPaddingPluginManager()
/**
* Set the padding plugin manager
*
- * @param string|ContainerInterface $plugins
* @throws Exception\InvalidArgumentException
- * @return void
*/
- public static function setPaddingPluginManager($plugins)
+ public static function setPaddingPluginManager(string|ContainerInterface $plugins): void
{
if (is_string($plugins)) {
if (! class_exists($plugins) || ! is_subclass_of($plugins, ContainerInterface::class)) {
@@ -313,23 +280,13 @@ public static function setPaddingPluginManager($plugins)
$plugins = new $plugins();
}
- if (! $plugins instanceof ContainerInterface) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Padding plugins must implements %s; received "%s"',
- ContainerInterface::class,
- is_object($plugins) ? get_class($plugins) : gettype($plugins)
- ));
- }
-
static::$paddingPlugins = $plugins;
}
/**
* Get the key size for the selected cipher
- *
- * @return int
*/
- public function getKeySize()
+ public function getKeySize(): int
{
return $this->keySizes[$this->algo];
}
@@ -338,15 +295,13 @@ public function getKeySize()
* Set the encryption key
* If the key is longer than maximum supported, it will be truncated by getKey().
*
- * @param string $key
- * @return Openssl Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setKey($key)
+ public function setKey(string $key): static
{
$keyLen = mb_strlen($key, '8bit');
- if (! $keyLen) {
+ if ($keyLen === 0) {
throw new Exception\InvalidArgumentException('The key cannot be empty');
}
@@ -363,13 +318,11 @@ public function setKey($key)
/**
* Get the encryption key
- *
- * @return string
*/
- public function getKey()
+ public function getKey(): ?string
{
- if (empty($this->key)) {
- return;
+ if (! isset($this->key) || ($this->key === '' || $this->key === '0')) {
+ return null;
}
return mb_substr($this->key, 0, $this->getKeySize(), '8bit');
}
@@ -377,11 +330,9 @@ public function getKey()
/**
* Set the encryption algorithm (cipher)
*
- * @param string $algo
- * @return Openssl Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setAlgorithm($algo)
+ public function setAlgorithm(string $algo): static
{
if (! in_array($algo, $this->getSupportedAlgorithms())) {
throw new Exception\InvalidArgumentException(sprintf(
@@ -396,20 +347,16 @@ public function setAlgorithm($algo)
/**
* Get the encryption algorithm
- *
- * @return string
*/
- public function getAlgorithm()
+ public function getAlgorithm(): string
{
return $this->algo;
}
/**
* Set the padding object
- *
- * @return Openssl Provides a fluent interface
*/
- public function setPadding(Padding\PaddingInterface $padding)
+ public function setPadding(PaddingInterface $padding): static
{
$this->padding = $padding;
return $this;
@@ -417,10 +364,8 @@ public function setPadding(Padding\PaddingInterface $padding)
/**
* Get the padding object
- *
- * @return Padding\PaddingInterface
*/
- public function getPadding()
+ public function getPadding(): PaddingInterface
{
return $this->padding;
}
@@ -428,12 +373,10 @@ public function getPadding()
/**
* Set Additional Authentication Data
*
- * @param string $aad
- * @return self
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
- public function setAad($aad)
+ public function setAad(string $aad): static
{
if (! $this->isAuthEncAvailable()) {
throw new Exception\RuntimeException(
@@ -447,13 +390,6 @@ public function setAad($aad)
);
}
- if (! is_string($aad)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'The provided $aad must be a string, %s given',
- gettype($aad)
- ));
- }
-
$this->aad = $aad;
return $this;
@@ -461,20 +397,16 @@ public function setAad($aad)
/**
* Get the Additional Authentication Data
- *
- * @return string
*/
- public function getAad()
+ public function getAad(): string
{
return $this->aad;
}
/**
* Get the authentication tag
- *
- * @return string
*/
- public function getTag()
+ public function getTag(): string|null
{
return $this->tag;
}
@@ -482,20 +414,11 @@ public function getTag()
/**
* Set the tag size for CCM and GCM mode
*
- * @param int $size
- * @return self
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
- public function setTagSize($size)
+ public function setTagSize(int $size): static
{
- if (! is_int($size)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'The provided $size must be an integer, %s given',
- gettype($size)
- ));
- }
-
if (! $this->isAuthEncAvailable()) {
throw new Exception\RuntimeException(
'You need PHP 7.1+ and OpenSSL with CCM or GCM mode to set the Tag Size'
@@ -521,10 +444,8 @@ public function setTagSize($size)
/**
* Get the tag size for CCM and GCM mode
- *
- * @return int
*/
- public function getTagSize()
+ public function getTagSize(): int
{
return $this->tagSize;
}
@@ -532,14 +453,12 @@ public function getTagSize()
/**
* Encrypt
*
- * @param string $data
* @throws Exception\InvalidArgumentException
- * @return string
*/
- public function encrypt($data)
+ public function encrypt(string $data): string
{
// Cannot encrypt empty string
- if (! is_string($data) || $data === '') {
+ if ($data === '') {
throw new Exception\InvalidArgumentException('The data to encrypt cannot be empty');
}
@@ -551,7 +470,7 @@ public function encrypt($data)
throw new Exception\InvalidArgumentException('The salt (IV) cannot be empty');
}
- if (null === $this->getPadding()) {
+ if (! $this->getPadding() instanceof PaddingInterface) {
throw new Exception\InvalidArgumentException('You must specify a padding method');
}
@@ -603,20 +522,18 @@ public function encrypt($data)
/**
* Decrypt
*
- * @param string $data
* @throws Exception\InvalidArgumentException
- * @return string
*/
- public function decrypt($data)
+ public function decrypt(string $data): string
{
- if (empty($data)) {
+ if ($data === '' || $data === '0') {
throw new Exception\InvalidArgumentException('The data to decrypt cannot be empty');
}
if (null === $this->getKey()) {
throw new Exception\InvalidArgumentException('No decryption key specified');
}
- if (null === $this->getPadding()) {
+ if (! $this->getPadding() instanceof PaddingInterface) {
throw new Exception\InvalidArgumentException('You must specify a padding method');
}
@@ -649,10 +566,8 @@ public function decrypt($data)
/**
* Get the salt (IV) size
- *
- * @return int
*/
- public function getSaltSize()
+ public function getSaltSize(): int|false
{
return openssl_cipher_iv_length(
$this->encryptionAlgos[$this->algo] . '-' . $this->mode
@@ -661,12 +576,10 @@ public function getSaltSize()
/**
* Get the supported algorithms
- *
- * @return array
*/
- public function getSupportedAlgorithms()
+ public function getSupportedAlgorithms(): array
{
- if (empty($this->supportedAlgos)) {
+ if ($this->supportedAlgos === []) {
foreach ($this->encryptionAlgos as $name => $algo) {
// CBC mode is supported by all the algorithms
if (in_array($algo . '-cbc', $this->getOpensslAlgos())) {
@@ -680,11 +593,9 @@ public function getSupportedAlgorithms()
/**
* Set the salt (IV)
*
- * @param string $salt
- * @return Openssl Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setSalt($salt)
+ public function setSalt(string $salt): static
{
if ($this->getSaltSize() <= 0) {
throw new Exception\InvalidArgumentException(sprintf(
@@ -694,7 +605,7 @@ public function setSalt($salt)
));
}
- if (empty($salt)) {
+ if ($salt === '' || $salt === '0') {
throw new Exception\InvalidArgumentException('The salt (IV) cannot be empty');
}
@@ -711,13 +622,11 @@ public function setSalt($salt)
/**
* Get the salt (IV) according to the size requested by the algorithm
- *
- * @return string
*/
- public function getSalt()
+ public function getSalt(): ?string
{
- if (empty($this->iv)) {
- return;
+ if (! isset($this->iv) || ($this->iv === '' || $this->iv === '0')) {
+ return null;
}
if (mb_strlen($this->iv, '8bit') < $this->getSaltSize()) {
@@ -732,10 +641,8 @@ public function getSalt()
/**
* Get the original salt value
- *
- * @return string
*/
- public function getOriginalSalt()
+ public function getOriginalSalt(): string
{
return $this->iv;
}
@@ -743,13 +650,11 @@ public function getOriginalSalt()
/**
* Set the cipher mode
*
- * @param string $mode
- * @return Openssl Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
- public function setMode($mode)
+ public function setMode(string $mode): static
{
- if (empty($mode)) {
+ if ($mode === '' || $mode === '0') {
return $this;
}
if (! in_array($mode, $this->getSupportedModes())) {
@@ -765,22 +670,18 @@ public function setMode($mode)
/**
* Get the cipher mode
- *
- * @return string
*/
- public function getMode()
+ public function getMode(): string
{
return $this->mode;
}
/**
* Return the OpenSSL supported encryption algorithms
- *
- * @return array
*/
- protected function getOpensslAlgos()
+ protected function getOpensslAlgos(): array
{
- if (empty($this->opensslAlgos)) {
+ if ($this->opensslAlgos === []) {
$this->opensslAlgos = openssl_get_cipher_methods(true);
}
return $this->opensslAlgos;
@@ -788,10 +689,8 @@ protected function getOpensslAlgos()
/**
* Get all supported encryption modes for the selected algorithm
- *
- * @return array
*/
- public function getSupportedModes()
+ public function getSupportedModes(): array
{
$modes = [];
foreach ($this->encryptionModes as $mode) {
@@ -805,20 +704,16 @@ public function getSupportedModes()
/**
* Get the block size
- *
- * @return int
*/
- public function getBlockSize()
+ public function getBlockSize(): int
{
return $this->blockSizes[$this->algo];
}
/**
* Return true if authenticated encryption is available
- *
- * @return bool
*/
- public function isAuthEncAvailable()
+ public function isAuthEncAvailable(): bool
{
// Counter with CBC-MAC
$ccm = in_array('aes-256-ccm', $this->getOpensslAlgos());
@@ -828,21 +723,12 @@ public function isAuthEncAvailable()
return PHP_VERSION_ID >= 70100 && ($ccm || $gcm);
}
- /**
- * @return bool
- */
- private function isCcmOrGcm()
+ private function isCcmOrGcm(): bool
{
return in_array(strtolower($this->mode), ['gcm', 'ccm'], true);
}
- /**
- * @param string $cipherText
- * @param string $iv
- * @param string $tag
- * @return string|bool false on failure
- */
- private function attemptOpensslDecrypt($cipherText, $iv, $tag)
+ private function attemptOpensslDecrypt(string $cipherText, string $iv, string|null $tag): string|false
{
if ($this->isCcmOrGcm()) {
return openssl_decrypt(
diff --git a/src/Symmetric/Padding/NoPadding.php b/src/Symmetric/Padding/NoPadding.php
index 2ac194e4..a6ecce5a 100644
--- a/src/Symmetric/Padding/NoPadding.php
+++ b/src/Symmetric/Padding/NoPadding.php
@@ -1,5 +1,7 @@
*/
- private $paddings = [
+ private array $paddings = [
'pkcs7' => Padding\Pkcs7::class,
'nopadding' => Padding\NoPadding::class,
'null' => Padding\NoPadding::class,
diff --git a/src/Symmetric/SymmetricInterface.php b/src/Symmetric/SymmetricInterface.php
index 07d894f2..a4461b17 100644
--- a/src/Symmetric/SymmetricInterface.php
+++ b/src/Symmetric/SymmetricInterface.php
@@ -1,86 +1,48 @@
plaintext = file_get_contents(__DIR__ . '/../_files/plaintext');
}
- public function testSetKey()
+ public function testSetKey(): void
{
$result = $this->blockCipher->setKey('test');
$this->assertEquals($result, $this->blockCipher);
$this->assertEquals('test', $this->blockCipher->getKey());
}
- public function testSetEmptyKey()
+ public function testSetEmptyKey(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->setKey('');
}
- public function testSetSalt()
+ public function testSetSalt(): void
{
$salt = str_repeat('a', $this->blockCipher->getCipher()->getSaltSize() + 2);
$result = $this->blockCipher->setSalt($salt);
@@ -75,63 +76,63 @@ public function testSetSalt()
$this->assertEquals($salt, $this->blockCipher->getOriginalSalt());
}
- public function testSetWrongSalt()
+ public function testSetWrongSalt(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->setSalt('x');
}
- public function testSetAlgorithm()
+ public function testSetAlgorithm(): void
{
$result = $this->blockCipher->setCipherAlgorithm('aes');
$this->assertEquals($result, $this->blockCipher);
$this->assertEquals('aes', $this->blockCipher->getCipherAlgorithm());
}
- public function testSetAlgorithmFail()
+ public function testSetAlgorithmFail(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
'The algorithm unknown is not supported by %s',
- get_class($this->cipher)
+ $this->cipher::class
));
- $result = $this->blockCipher->setCipherAlgorithm('unknown');
+ $this->blockCipher->setCipherAlgorithm('unknown');
}
- public function testSetHashAlgorithm()
+ public function testSetHashAlgorithm(): void
{
$result = $this->blockCipher->setHashAlgorithm('sha1');
$this->assertEquals($result, $this->blockCipher);
$this->assertEquals('sha1', $this->blockCipher->getHashAlgorithm());
}
- public function testSetUnsupportedHashAlgorithm()
+ public function testSetUnsupportedHashAlgorithm(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->setHashAlgorithm('foo');
}
- public function testSetPbkdf2HashAlgorithm()
+ public function testSetPbkdf2HashAlgorithm(): void
{
$result = $this->blockCipher->setPbkdf2HashAlgorithm('sha1');
$this->assertEquals($result, $this->blockCipher);
$this->assertEquals('sha1', $this->blockCipher->getPbkdf2HashAlgorithm());
}
- public function testSetUnsupportedPbkdf2HashAlgorithm()
+ public function testSetUnsupportedPbkdf2HashAlgorithm(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->setPbkdf2HashAlgorithm('foo');
}
- public function testSetKeyIteration()
+ public function testSetKeyIteration(): void
{
$result = $this->blockCipher->setKeyIteration(1000);
$this->assertEquals($result, $this->blockCipher);
$this->assertEquals(1000, $this->blockCipher->getKeyIteration());
}
- public function testEncryptWithoutData()
+ public function testEncryptWithoutData(): void
{
$plaintext = '';
$this->expectException(Exception\InvalidArgumentException::class);
@@ -139,7 +140,7 @@ public function testEncryptWithoutData()
$this->blockCipher->encrypt($plaintext);
}
- public function testEncryptErrorKey()
+ public function testEncryptErrorKey(): void
{
$plaintext = 'test';
$this->expectException(Exception\InvalidArgumentException::class);
@@ -147,7 +148,7 @@ public function testEncryptErrorKey()
$this->blockCipher->encrypt($plaintext);
}
- public function testEncryptDecrypt()
+ public function testEncryptDecrypt(): void
{
$this->blockCipher->setKey('test');
$this->blockCipher->setKeyIteration(1000);
@@ -176,7 +177,7 @@ public function testEncryptDecrypt()
}
}
- public function testEncryptDecryptUsingBinary()
+ public function testEncryptDecryptUsingBinary(): void
{
$this->blockCipher->setKey('test');
$this->blockCipher->setKeyIteration(1000);
@@ -209,10 +210,9 @@ public function testEncryptDecryptUsingBinary()
}
/** @psalm-return array */
- public function zeroValuesProvider(): array
+ public static function zeroValuesProvider(): array
{
return [
- '"0"' => [0],
'"0.0"' => [0.0],
'"0"' => ['0'],
];
@@ -220,9 +220,8 @@ public function zeroValuesProvider(): array
/**
* @dataProvider zeroValuesProvider
- * @param int|float|string $value
*/
- public function testEncryptDecryptUsingZero($value)
+ public function testEncryptDecryptUsingZero(int|float|string $value): void
{
$this->blockCipher->setKey('test');
$this->blockCipher->setKeyIteration(1000);
@@ -238,7 +237,7 @@ public function testEncryptDecryptUsingZero($value)
$this->blockCipher->setCipherAlgorithm($algo);
try {
- $encrypted = $this->blockCipher->encrypt($value);
+ $encrypted = $this->blockCipher->encrypt((string) $value);
} catch (GlobalException $e) {
$this->fail(sprintf('Failed encryption using %s: %s', $algo, $e->getMessage()));
}
@@ -252,25 +251,19 @@ public function testEncryptDecryptUsingZero($value)
}
}
- public function testDecryptNotString()
- {
- $this->expectException(Exception\InvalidArgumentException::class);
- $this->blockCipher->decrypt(['foo']);
- }
-
- public function testDecryptEmptyString()
+ public function testDecryptEmptyString(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->decrypt('');
}
- public function testDecyptWihoutKey()
+ public function testDecyptWihoutKey(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->decrypt('encrypted data');
}
- public function testDecryptAuthFail()
+ public function testDecryptAuthFail(): void
{
$this->blockCipher->setKey('test');
$this->blockCipher->setKeyIteration(1000);
@@ -282,7 +275,7 @@ public function testDecryptAuthFail()
$this->assertFalse($decrypted);
}
- public function testSetSymmetricPluginManager()
+ public function testSetSymmetricPluginManager(): void
{
$old = $this->blockCipher->getSymmetricPluginManager();
@@ -294,19 +287,19 @@ public function testSetSymmetricPluginManager()
$this->blockCipher->setSymmetricPluginManager($old);
}
- public function testFactoryWithWrongAdapter()
+ public function testFactoryWithWrongAdapter(): void
{
$this->expectException(Exception\RuntimeException::class);
$this->blockCipher = BlockCipher::factory('foo');
}
- public function testSetWrongSymmetricPluginManager()
+ public function testSetWrongSymmetricPluginManager(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->setSymmetricPluginManager(stdClass::class);
}
- public function testSetNotExistingSymmetricPluginManager()
+ public function testSetNotExistingSymmetricPluginManager(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->blockCipher->setSymmetricPluginManager('Foo');
diff --git a/test/BlockCipher/OpensslAeadTest.php b/test/BlockCipher/OpensslAeadTest.php
index 5f0e7ae0..aa1fa570 100644
--- a/test/BlockCipher/OpensslAeadTest.php
+++ b/test/BlockCipher/OpensslAeadTest.php
@@ -1,5 +1,7 @@
*/
- public function getAuthEncryptionMode(): array
+ public static function getAuthEncryptionMode(): array
{
return [
['gcm'],
@@ -33,7 +35,7 @@ public function getAuthEncryptionMode(): array
/**
* @dataProvider getAuthEncryptionMode
*/
- public function testEncryptDecrypt(string $mode)
+ public function testEncryptDecrypt(string $mode): void
{
$this->blockCipher->getCipher()->setMode($mode);
$this->blockCipher->setKey('test');
diff --git a/test/BlockCipher/OpensslTest.php b/test/BlockCipher/OpensslTestcase.php
similarity index 82%
rename from test/BlockCipher/OpensslTest.php
rename to test/BlockCipher/OpensslTestcase.php
index 9b25d00a..0b75d4fc 100644
--- a/test/BlockCipher/OpensslTest.php
+++ b/test/BlockCipher/OpensslTestcase.php
@@ -1,11 +1,13 @@
blockCipher->setCipher($this->cipher);
$this->assertEquals($result, $this->blockCipher);
$this->assertEquals($this->cipher, $this->blockCipher->getCipher());
}
- public function testFactory()
+ public function testFactory(): void
{
$this->blockCipher = BlockCipher::factory('openssl', ['algo' => 'aes']);
$this->assertInstanceOf(Symmetric\Openssl::class, $this->blockCipher->getCipher());
$this->assertEquals('aes', $this->blockCipher->getCipher()->getAlgorithm());
}
- public function testFactoryEmptyOptions()
+ public function testFactoryEmptyOptions(): void
{
$this->blockCipher = BlockCipher::factory('openssl');
$this->assertInstanceOf(Symmetric\Openssl::class, $this->blockCipher->getCipher());
diff --git a/test/FileCipher/AbstractFileCipherTest.php b/test/FileCipher/AbstractFileCipherTestcase.php
similarity index 86%
rename from test/FileCipher/AbstractFileCipherTest.php
rename to test/FileCipher/AbstractFileCipherTestcase.php
index 5db61f4d..fcb80dab 100644
--- a/test/FileCipher/AbstractFileCipherTest.php
+++ b/test/FileCipher/AbstractFileCipherTestcase.php
@@ -1,5 +1,7 @@
assertEquals(1048576, FileCipher::BUFFER_SIZE);
}
- public function testSetKeyIteration()
+ public function testSetKeyIteration(): void
{
$this->fileCipher->setKeyIteration(5000);
$this->assertEquals(5000, $this->fileCipher->getKeyIteration());
}
- public function testSetKey()
+ public function testSetKey(): void
{
$this->fileCipher->setKey('test');
$this->assertEquals('test', $this->fileCipher->getKey());
}
- public function testSetEmptyKey()
+ public function testSetEmptyKey(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The key cannot be empty');
$this->fileCipher->setKey('');
}
- public function testSetCipherAlgorithm()
+ public function testSetCipherAlgorithm(): void
{
$this->fileCipher->setCipherAlgorithm('aes');
$this->assertEquals('aes', $this->fileCipher->getCipherAlgorithm());
}
- public function testSetCipherAlgorithmFail()
+ public function testSetCipherAlgorithmFail(): void
{
$this->expectException(SymmetricException\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
'The algorithm unknown is not supported by %s',
- get_class($this->fileCipher->getCipher())
+ $this->fileCipher->getCipher()::class
));
$this->fileCipher->setCipherAlgorithm('unknown');
}
- public function testGetCipherSupportedAlgorithms()
+ public function testGetCipherSupportedAlgorithms(): void
{
$this->assertIsArray($this->fileCipher->getCipherSupportedAlgorithms());
}
- public function testSetHashAlgorithm()
+ public function testSetHashAlgorithm(): void
{
$this->fileCipher->setHashAlgorithm('sha1');
$this->assertEquals('sha1', $this->fileCipher->getHashAlgorithm());
}
- public function testSetWrongHashAlgorithm()
+ public function testSetWrongHashAlgorithm(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(
@@ -114,13 +115,13 @@ public function testSetWrongHashAlgorithm()
$this->fileCipher->setHashAlgorithm('unknown');
}
- public function testSetPbkdf2HashAlgorithm()
+ public function testSetPbkdf2HashAlgorithm(): void
{
$this->fileCipher->setPbkdf2HashAlgorithm('sha1');
$this->assertEquals('sha1', $this->fileCipher->getPbkdf2HashAlgorithm());
}
- public function testSetWrongPbkdf2HashAlgorithm()
+ public function testSetWrongPbkdf2HashAlgorithm(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(
@@ -129,7 +130,7 @@ public function testSetWrongPbkdf2HashAlgorithm()
$this->fileCipher->setPbkdf2HashAlgorithm('unknown');
}
- public function testEncryptDecryptFile()
+ public function testEncryptDecryptFile(): void
{
$this->fileCipher->setKey('test');
@@ -139,7 +140,7 @@ public function testEncryptDecryptFile()
$fileOut = $fileIn . '.enc';
// encrypt without compression
- $this->assertTrue($this->fileCipher->encrypt($fileIn, $fileOut, false));
+ $this->assertTrue($this->fileCipher->encrypt($fileIn, $fileOut));
$paddingSize = $this->fileCipher->getCipher()->getBlockSize();
$this->assertEquals(
@@ -162,16 +163,16 @@ public function testEncryptDecryptFile()
}
}
- public function testDecryptFileNoValidAuthenticate()
+ public function testDecryptFileNoValidAuthenticate(): void
{
$this->fileIn = $this->generateTmpFile(1048576, Rand::getBytes(1));
$this->fileOut = $this->fileIn . '.enc';
$this->fileCipher->setKey('test');
- $this->assertTrue($this->fileCipher->encrypt($this->fileIn, $this->fileOut, false));
+ $this->assertTrue($this->fileCipher->encrypt($this->fileIn, $this->fileOut));
$fileOut2 = $this->fileIn . '.dec';
- $this->assertTrue($this->fileCipher->decrypt($this->fileOut, $fileOut2, false));
+ $this->assertTrue($this->fileCipher->decrypt($this->fileOut, $fileOut2));
unlink($fileOut2);
// Tampering of the encrypted file
@@ -179,11 +180,11 @@ public function testDecryptFileNoValidAuthenticate()
$ciphertext[0] = chr((ord($ciphertext[0]) + 1) % 256);
file_put_contents($this->fileOut, $ciphertext);
- $this->assertFalse($this->fileCipher->decrypt($this->fileOut, $fileOut2, false));
+ $this->assertFalse($this->fileCipher->decrypt($this->fileOut, $fileOut2));
$this->assertFileDoesNotExist($fileOut2);
}
- public function testEncryptFileWithNoKey()
+ public function testEncryptFileWithNoKey(): void
{
$this->fileIn = $this->generateTmpFile(1048576, Rand::getBytes(1));
$this->fileOut = $this->fileIn . '.enc';
@@ -193,7 +194,7 @@ public function testEncryptFileWithNoKey()
$this->fileCipher->encrypt($this->fileIn, $this->fileOut);
}
- public function testDecryptFileWithNoKey()
+ public function testDecryptFileWithNoKey(): void
{
$this->fileIn = $this->generateTmpFile(1048576, Rand::getBytes(1));
$this->fileOut = $this->fileIn . '.enc';
@@ -203,7 +204,7 @@ public function testDecryptFileWithNoKey()
$this->fileCipher->decrypt($this->fileIn, $this->fileOut);
}
- public function testEncryptFileInvalidInputFile()
+ public function testEncryptFileInvalidInputFile(): void
{
$randomFile = uniqid('Invalid_File', true);
$this->expectException(Exception\InvalidArgumentException::class);
@@ -212,7 +213,7 @@ public function testEncryptFileInvalidInputFile()
$this->fileCipher->encrypt($randomFile, '');
}
- public function testDecryptFileInvalidInputFile()
+ public function testDecryptFileInvalidInputFile(): void
{
$randomFile = uniqid('Invalid_File', true);
$this->expectException(Exception\InvalidArgumentException::class);
@@ -221,7 +222,7 @@ public function testDecryptFileInvalidInputFile()
$this->fileCipher->decrypt($randomFile, '');
}
- public function testEncryptFileInvalidOutputFile()
+ public function testEncryptFileInvalidOutputFile(): void
{
$this->fileIn = $this->generateTmpFile(1024);
$this->fileOut = $this->generateTmpFile(1024);
@@ -232,7 +233,7 @@ public function testEncryptFileInvalidOutputFile()
$this->fileCipher->encrypt($this->fileIn, $this->fileOut);
}
- public function testDecryptFileInvalidOutputFile()
+ public function testDecryptFileInvalidOutputFile(): void
{
$this->fileIn = $this->generateTmpFile(1024);
$this->fileOut = $this->generateTmpFile(1024);
diff --git a/test/FileCipher/OpensslTest.php b/test/FileCipher/OpensslTestcase.php
similarity index 83%
rename from test/FileCipher/OpensslTest.php
rename to test/FileCipher/OpensslTestcase.php
index d80f7403..b2528a36 100644
--- a/test/FileCipher/OpensslTest.php
+++ b/test/FileCipher/OpensslTestcase.php
@@ -1,5 +1,7 @@
assertInstanceOf(Openssl::class, $fileCipher->getCipher());
}
- public function testSetCipher()
+ public function testSetCipher(): void
{
$cipher = new Openssl([
'algo' => 'aes',
diff --git a/test/HashTest.php b/test/HashTest.php
index ba69ed86..1413d0ac 100644
--- a/test/HashTest.php
+++ b/test/HashTest.php
@@ -1,5 +1,7 @@
getProperty('lastAlgorithmSupported');
@@ -56,7 +58,7 @@ public function testIsSupportedAndCache()
// SHA1 tests taken from RFC 3174
/** @psalm-return array */
- public function provideSha1Data(): array
+ public static function provideSha1Data(): array
{
return [
[
@@ -81,7 +83,7 @@ public function provideSha1Data(): array
/**
* @dataProvider provideSha1Data
*/
- public function testSha1(string $data, string $output)
+ public function testSha1(string $data, string $output): void
{
$hash = Hash::compute('sha1', $data);
$this->assertEquals($output, $hash);
@@ -90,7 +92,7 @@ public function testSha1(string $data, string $output)
// SHA-224 tests taken from RFC 3874
/** @psalm-return array */
- public function provideSha224Data(): array
+ public static function provideSha224Data(): array
{
return [
['abc', '23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7'],
@@ -108,7 +110,7 @@ public function provideSha224Data(): array
/**
* @dataProvider provideSha224Data
*/
- public function testSha224(string $data, string $output)
+ public function testSha224(string $data, string $output): void
{
$hash = Hash::compute('sha224', $data);
$this->assertEquals($output, $hash);
@@ -117,7 +119,7 @@ public function testSha224(string $data, string $output)
// MD5 test suite taken from RFC 1321
/** @psalm-return array */
- public function provideMd5Data(): array
+ public static function provideMd5Data(): array
{
return [
['', 'd41d8cd98f00b204e9800998ecf8427e'],
@@ -136,28 +138,20 @@ public function provideMd5Data(): array
/**
* @dataProvider provideMd5Data
*/
- public function testMd5(string $data, string $output)
+ public function testMd5(string $data, string $output): void
{
$hash = Hash::compute('md5', $data);
$this->assertEquals($output, $hash);
}
- public function testNullHashAlgorithm()
- {
- Hash::clearLastAlgorithmCache();
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage('Hash algorithm provided is not supported on this PHP installation');
- Hash::compute(null, 'test');
- }
-
- public function testWrongHashAlgorithm()
+ public function testWrongHashAlgorithm(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Hash algorithm provided is not supported on this PHP installation');
Hash::compute('wrong', 'test');
}
- public function testBinaryOutput()
+ public function testBinaryOutput(): void
{
$hash = Hash::compute('sha1', 'test', Hash::OUTPUT_BINARY);
$this->assertEquals('qUqP5cyxm6YcTAhz05Hph5gvu9M=', base64_encode($hash));
diff --git a/test/HmacTest.php b/test/HmacTest.php
index 532a5c86..099eead4 100644
--- a/test/HmacTest.php
+++ b/test/HmacTest.php
@@ -1,5 +1,7 @@
getProperty('lastAlgorithmSupported');
@@ -61,7 +63,7 @@ public function testIsSupportedAndCache()
* 2: string,
* }>
*/
- public function provideMd5Data()
+ public static function provideMd5Data(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
return [
@@ -91,7 +93,7 @@ public function provideMd5Data()
/**
* @dataProvider provideMd5Data
*/
- public function testMd5(string $data, string $key, string $output)
+ public function testMd5(string $data, string $key, string $output): void
{
$hash = Hmac::compute($key, 'MD5', $data);
$this->assertEquals($output, $hash);
@@ -106,7 +108,7 @@ public function testMd5(string $data, string $key, string $output)
* 2: string,
* }>
*/
- public function provideSha1Data(): array
+ public static function provideSha1Data(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
return [
@@ -136,7 +138,7 @@ public function provideSha1Data(): array
/**
* @dataProvider provideSha1Data
*/
- public function testSha1(string $data, string $key, string $output)
+ public function testSha1(string $data, string $key, string $output): void
{
$hash = Hmac::compute($key, 'SHA1', $data);
$this->assertEquals($output, $hash);
@@ -151,7 +153,7 @@ public function testSha1(string $data, string $key, string $output)
* 2: string,
* }>
*/
- public function provideRipemd160Data(): array
+ public static function provideRipemd160Data(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
return [
@@ -181,35 +183,28 @@ public function provideRipemd160Data(): array
/**
* @dataProvider provideRipemd160Data
*/
- public function testRipemd160(string $data, string $key, string $output)
+ public function testRipemd160(string $data, string $key, string $output): void
{
$hash = Hmac::compute($key, 'RIPEMD160', $data);
$this->assertEquals($output, $hash);
}
- public function testEmptyKey()
+ public function testEmptyKey(): void
{
Hmac::clearLastAlgorithmCache();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Provided key is null or empty');
- Hmac::compute(null, 'md5', 'test');
- }
-
- public function testNullHashAlgorithm()
- {
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage('Hash algorithm is not supported on this PHP installation');
- Hmac::compute('key', null, 'test');
+ Hmac::compute('', 'md5', 'test');
}
- public function testWrongHashAlgorithm()
+ public function testWrongHashAlgorithm(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Hash algorithm is not supported on this PHP installation');
Hmac::compute('key', 'wrong', 'test');
}
- public function testBinaryOutput()
+ public function testBinaryOutput(): void
{
$data = Hmac::compute('key', 'sha256', 'test', Hmac::OUTPUT_BINARY);
$this->assertEquals('Aq+1YwSQLGVvy3N83QPeYgW7bUAdooEu/ZstNqCK8Vk=', base64_encode($data));
diff --git a/test/HybridTest.php b/test/HybridTest.php
index d88f8904..1a337852 100644
--- a/test/HybridTest.php
+++ b/test/HybridTest.php
@@ -1,5 +1,7 @@
hybrid = new Hybrid();
}
- public function testConstructor()
+ public function testConstructor(): void
{
$hybrid = new Hybrid();
$this->assertInstanceOf(Hybrid::class, $hybrid);
}
- public function testConstructorWithParameters()
+ public function testConstructorWithParameters(): void
{
$hybrid = new Hybrid(
$this->createMock(BlockCipher::class),
@@ -38,19 +40,19 @@ public function testConstructorWithParameters()
$this->assertInstanceOf(Hybrid::class, $hybrid);
}
- public function testGetDefaultBlockCipherInstance()
+ public function testGetDefaultBlockCipherInstance(): void
{
$bCipher = $this->hybrid->getBlockCipherInstance();
$this->assertInstanceOf(BlockCipher::class, $bCipher);
}
- public function testGetDefaultRsaInstance()
+ public function testGetDefaultRsaInstance(): void
{
$rsa = $this->hybrid->getRsaInstance();
$this->assertInstanceOf(Rsa::class, $rsa);
}
- public function testEncryptDecryptWithOneStringKey()
+ public function testEncryptDecryptWithOneStringKey(): void
{
$rsaOptions = new RsaOptions();
$rsaOptions->generateKeys([
@@ -64,7 +66,7 @@ public function testEncryptDecryptWithOneStringKey()
$this->assertEquals('test', $plaintext);
}
- public function testEncryptDecryptWithOneStringKeyAndPassphrase()
+ public function testEncryptDecryptWithOneStringKeyAndPassphrase(): void
{
$passPhrase = 'test';
$rsaOptions = new RsaOptions([
@@ -81,7 +83,7 @@ public function testEncryptDecryptWithOneStringKeyAndPassphrase()
$this->assertEquals('test', $plaintext);
}
- public function testEncryptWithMultipleStringKeys()
+ public function testEncryptWithMultipleStringKeys(): void
{
$publicKeys = [];
$privateKeys = [];
@@ -97,12 +99,12 @@ public function testEncryptWithMultipleStringKeys()
$encrypted = $this->hybrid->encrypt('test', $publicKeys);
for ($id = 0; $id < 5; $id++) {
- $plaintext = $this->hybrid->decrypt($encrypted, $privateKeys[$id], null, $id);
+ $plaintext = $this->hybrid->decrypt($encrypted, $privateKeys[$id], null, (string) $id);
$this->assertEquals('test', $plaintext);
}
}
- public function testEncryptDecryptWithOneObjectKey()
+ public function testEncryptDecryptWithOneObjectKey(): void
{
$rsaOptions = new RsaOptions();
$rsaOptions->generateKeys([
@@ -116,7 +118,7 @@ public function testEncryptDecryptWithOneObjectKey()
$this->assertEquals('test', $plaintext);
}
- public function testEncryptWithMultipleObjectKeys()
+ public function testEncryptWithMultipleObjectKeys(): void
{
$publicKeys = [];
$privateKeys = [];
@@ -132,12 +134,12 @@ public function testEncryptWithMultipleObjectKeys()
$encrypted = $this->hybrid->encrypt('test', $publicKeys);
for ($id = 0; $id < 5; $id++) {
- $plaintext = $this->hybrid->decrypt($encrypted, $privateKeys[$id], null, $id);
+ $plaintext = $this->hybrid->decrypt($encrypted, $privateKeys[$id], null, (string) $id);
$this->assertEquals('test', $plaintext);
}
}
- public function testFailToDecryptWithOneKey()
+ public function testFailToDecryptWithOneKey(): void
{
$rsaOptions = new RsaOptions();
$rsaOptions->generateKeys([
@@ -158,7 +160,7 @@ public function testFailToDecryptWithOneKey()
$this->hybrid->decrypt($encrypted, $privateKey);
}
- public function testFailToEncryptUsingPrivateKey()
+ public function testFailToEncryptUsingPrivateKey(): void
{
$rsaOptions = new RsaOptions();
$rsaOptions->generateKeys([
diff --git a/test/Key/Derivation/Pbkdf2Test.php b/test/Key/Derivation/Pbkdf2Test.php
index 26875ca5..2a9ee793 100644
--- a/test/Key/Derivation/Pbkdf2Test.php
+++ b/test/Key/Derivation/Pbkdf2Test.php
@@ -1,5 +1,7 @@
salt = '12345678901234567890123456789012';
}
- public function testCalc()
+ public function testCalc(): void
{
$password = Pbkdf2::calc('sha256', 'test', $this->salt, 5000, 32);
$this->assertEquals(32, strlen($password));
$this->assertEquals('JVNgHc1AeBl/S9H6Jo2tUUi838snakDBMcsNJP0+0O0=', base64_encode($password));
}
- public function testCalcWithWrongHash()
+ public function testCalcWithWrongHash(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
@@ -68,8 +70,14 @@ public static function provideTestVectors(): array
/**
* @dataProvider provideTestVectors
*/
- public function testRFC670(string $hash, string $password, string $salt, int $cycles, int $length, string $expect)
- {
+ public function testRFC670(
+ string $hash,
+ string $password,
+ string $salt,
+ int $cycles,
+ int $length,
+ string $expect
+ ): void {
$result = Pbkdf2::calc($hash, $password, $salt, $cycles, $length);
$this->assertEquals($expect, bin2hex($result));
}
diff --git a/test/Key/Derivation/SaltedS2kTest.php b/test/Key/Derivation/SaltedS2kTest.php
index b816ceff..b25b51a7 100644
--- a/test/Key/Derivation/SaltedS2kTest.php
+++ b/test/Key/Derivation/SaltedS2kTest.php
@@ -1,5 +1,7 @@
salt = '12345678';
}
- public function testCalc()
+ public function testCalc(): void
{
if (! extension_loaded('hash')) {
$this->markTestSkipped('The hash extension is not available');
@@ -37,7 +39,7 @@ public function testCalc()
$this->assertEquals('qzQISUBUSP1iqYtwe/druhdOVqluc/Y2TetdSHSbaw8=', base64_encode($password));
}
- public function testCalcWithWrongHash()
+ public function testCalcWithWrongHash(): void
{
if (! extension_loaded('hash')) {
$this->markTestSkipped('The hash extension is not available');
@@ -52,7 +54,7 @@ public function testCalcWithWrongHash()
SaltedS2k::calc('wrong', 'test', $this->salt, 32);
}
- public function testCalcWithWrongSalt()
+ public function testCalcWithWrongSalt(): void
{
if (! extension_loaded('hash')) {
$this->markTestSkipped('The hash extension is not available');
diff --git a/test/Key/Derivation/ScryptTest.php b/test/Key/Derivation/ScryptTest.php
index ad92e4d7..2135f1dc 100644
--- a/test/Key/Derivation/ScryptTest.php
+++ b/test/Key/Derivation/ScryptTest.php
@@ -1,5 +1,7 @@
invokeArgs($obj, [$input]);
$this->assertEquals(64, strlen($input), 'Input must be a string of 64 bytes');
- $this->assertEquals(64, strlen($result), 'Output must be a string of 64 bytes');
- $this->assertEquals(str_replace([' ', "\n"], '', $hexOutput), bin2hex($result));
+ $this->assertEquals(64, strlen((string) $result), 'Output must be a string of 64 bytes');
+ $this->assertEquals(str_replace([' ', "\n"], '', $hexOutput), bin2hex((string) $result));
}
/**
@@ -67,7 +69,7 @@ public function testVectorSalsa208Core()
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-8
*/
- public function testVectorScryptBlockMix()
+ public function testVectorScryptBlockMix(): void
{
$hexInput = 'f7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd
77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad
@@ -94,7 +96,7 @@ public function testVectorScryptBlockMix()
$input = self::hex2bin(str_replace([' ', "\n"], '', $hexInput));
$result = $blockMix->invokeArgs($obj, [$input, 1]);
- $this->assertEquals(str_replace([' ', "\n"], '', $hexOutput), bin2hex($result));
+ $this->assertEquals(str_replace([' ', "\n"], '', $hexOutput), bin2hex((string) $result));
}
/**
@@ -102,7 +104,7 @@ public function testVectorScryptBlockMix()
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-9
*/
- public function testVectorScryptROMix()
+ public function testVectorScryptROMix(): void
{
$hexInput = 'f7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd
77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad
@@ -127,7 +129,7 @@ public function testVectorScryptROMix()
$input = self::hex2bin(str_replace([' ', "\n"], '', $hexInput));
$result = $roMix->invokeArgs($obj, [$input, 16, 1]);
- $this->assertEquals(str_replace([' ', "\n"], '', $hexOutput), bin2hex($result));
+ $this->assertEquals(str_replace([' ', "\n"], '', $hexOutput), bin2hex((string) $result));
}
/**
@@ -135,7 +137,7 @@ public function testVectorScryptROMix()
*
* @see https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01#section-11
*/
- public function testVectorScrypt()
+ public function testVectorScrypt(): void
{
$hexOutput = 'd3 3c 6e c1 81 8d aa f7 28 f5 5a fa df ea a5 58
b3 8e fa 81 30 5b 35 21 a7 f1 2f 4b e0 97 e8 4d
@@ -147,28 +149,28 @@ public function testVectorScrypt()
$this->assertEquals(str_replace([' ', "\n"], '', $hexOutput), bin2hex($result));
}
- public function testScryptWrongN1()
+ public function testScryptWrongN1(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
Scrypt::calc('test', 'salt', 17, 1, 1, 64);
}
- public function testScryptWronN2()
+ public function testScryptWronN2(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
Scrypt::calc('test', 'salt', PHP_INT_MAX, 1, 1, 64);
}
- public function testScryptWrongR()
+ public function testScryptWrongR(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
- Scrypt::calc('test', 'salt', PHP_INT_MAX / 128, 4, 1, 64);
+ Scrypt::calc('test', 'salt', (int) (PHP_INT_MAX / 128), 4, 1, 64);
}
/**
* Test scrypt correct size output
*/
- public function testScryptSize()
+ public function testScryptSize(): void
{
for ($size = 0; $size < 64; $size++) {
if (extension_loaded('Scrypt') && ($size < 16)) {
@@ -183,9 +185,8 @@ public function testScryptSize()
* Convert a string with hex values in binary string
*
* @param string $hex
- * @return string
*/
- protected static function hex2bin($hex)
+ protected static function hex2bin($hex): string
{
$len = strlen($hex);
$result = '';
diff --git a/test/Password/ApacheTest.php b/test/Password/ApacheTest.php
index 0615b378..4167d265 100644
--- a/test/Password/ApacheTest.php
+++ b/test/Password/ApacheTest.php
@@ -1,5 +1,7 @@
apache = new Apache();
}
- public function testConstruct()
+ public function testConstruct(): void
{
$apache = new Apache(['format' => 'crypt']);
$this->assertInstanceOf(Apache::class, $apache);
}
- public function testWrongConstruct()
- {
- $this->expectException(Exception\InvalidArgumentException::class);
- new Apache('crypt');
- }
-
- public function testWrongParamConstruct()
+ public function testWrongParamConstruct(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
new Apache(['format' => 'crypto']);
}
- public function testSetUserName()
+ public function testSetUserName(): void
{
$result = $this->apache->setUserName('test');
$this->assertInstanceOf(Apache::class, $result);
$this->assertEquals('test', $this->apache->getUserName());
}
- public function testSetFormat()
+ public function testSetFormat(): void
{
$result = $this->apache->setFormat('crypt');
$this->assertInstanceOf(Apache::class, $result);
$this->assertEquals('crypt', $this->apache->getFormat());
}
- public function testSetWrongFormat()
+ public function testSetWrongFormat(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->apache->setFormat('test');
}
- public function testSetAuthName()
+ public function testSetAuthName(): void
{
$result = $this->apache->setAuthName('test');
$this->assertInstanceOf(Apache::class, $result);
$this->assertEquals('test', $this->apache->getAuthName());
}
- public function testCrypt()
+ public function testCrypt(): void
{
$this->apache->setFormat('crypt');
$hash = $this->apache->create('myPassword');
@@ -76,14 +72,14 @@ public function testCrypt()
$this->assertTrue($this->apache->verify('myPassword', $hash));
}
- public function testSha1()
+ public function testSha1(): void
{
$this->apache->setFormat('sha1');
$hash = $this->apache->create('myPassword');
$this->assertTrue($this->apache->verify('myPassword', $hash));
}
- public function testMd5()
+ public function testMd5(): void
{
$this->apache->setFormat('md5');
$hash = $this->apache->create('myPassword');
@@ -92,7 +88,7 @@ public function testMd5()
$this->assertTrue($this->apache->verify('myPassword', $hash));
}
- public function testDigest()
+ public function testDigest(): void
{
$this->apache->setFormat('digest');
$this->apache->setUserName('Enrico');
@@ -101,7 +97,7 @@ public function testDigest()
$this->assertEquals(32, strlen($hash));
}
- public function testDigestWithoutPreset()
+ public function testDigestWithoutPreset(): void
{
$this->apache->setFormat('digest');
@@ -109,7 +105,7 @@ public function testDigestWithoutPreset()
$this->apache->create('myPassword');
}
- public function testDigestWithoutAuthName()
+ public function testDigestWithoutAuthName(): void
{
$this->apache->setFormat('digest');
$this->apache->setUserName('Enrico');
@@ -118,7 +114,7 @@ public function testDigestWithoutAuthName()
$this->apache->create('myPassword');
}
- public function testDigestWithoutUserName()
+ public function testDigestWithoutUserName(): void
{
$this->apache->setFormat('digest');
$this->apache->setAuthName('Auth');
@@ -149,24 +145,24 @@ public static function provideTestVectors(): array
/**
* @dataProvider provideTestVectors
*/
- public function testVerify(string $password, string $hash)
+ public function testVerify(string $password, string $hash): void
{
$this->assertTrue($this->apache->verify($password, $hash));
}
- public function testApr1Md5WrongSaltFormat1()
+ public function testApr1Md5WrongSaltFormat1(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->apache->verify('myPassword', '$apr1$z0Hhe5Lq3$6YdJKbkrJg77Dvw2gpuSA1');
}
- public function testApr1Md5WrongSaltFormat2()
+ public function testApr1Md5WrongSaltFormat2(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->apache->verify('myPassword', '$apr1$z0Hhe5L&$6YdJKbkrJg77Dvw2gpuSA1');
}
- public function testCanVerifyBcryptHashes()
+ public function testCanVerifyBcryptHashes(): void
{
$bcrypt = new Bcrypt();
$hash = $bcrypt->create('myPassword');
diff --git a/test/Password/BcryptBCTest.php b/test/Password/BcryptBCTest.php
index 5a6b25f9..719264a7 100644
--- a/test/Password/BcryptBCTest.php
+++ b/test/Password/BcryptBCTest.php
@@ -1,5 +1,7 @@
bcrypt = new Bcrypt();
}
- public function testBackwardCompatibilityV2()
+ public function testBackwardCompatibilityV2(): void
{
$hash = $this->bcryptV2Implementation('test', 10);
$this->assertTrue($this->bcrypt->verify('test', $hash));
@@ -36,7 +38,7 @@ public function testBackwardCompatibilityV2()
*/
protected function bcryptV2Implementation(string $password, int $cost = 10, ?string $salt = null): string
{
- if (empty($salt)) {
+ if ($salt === null || $salt === '' || $salt === '0') {
$salt = Rand::getBytes(16);
}
@@ -47,7 +49,7 @@ protected function bcryptV2Implementation(string $password, int $cost = 10, ?str
* @see http://php.net/security/crypt_blowfish.php
*/
$prefix = '$2y$';
- $hash = crypt($password, $prefix . (string) $cost . '$' . $salt64);
+ $hash = crypt($password, $prefix . $cost . '$' . $salt64);
if (mb_strlen($hash, '8bit') < 13) {
throw new RuntimeException('Error during the bcrypt generation');
}
diff --git a/test/Password/BcryptShaTest.php b/test/Password/BcryptShaTest.php
index f81d86ba..545354c3 100644
--- a/test/Password/BcryptShaTest.php
+++ b/test/Password/BcryptShaTest.php
@@ -1,5 +1,7 @@
bcryptPassword = $this->prefix . '10$123456789012345678901uhQoed..kXLQz0DxloSzgbQaEOW4N2Vm';
}
- public function testConstructByOptions()
+ public function testConstructByOptions(): void
{
$options = ['cost' => '15'];
$bcrypt = new BcryptSha($options);
@@ -49,7 +49,7 @@ public function testConstructByOptions()
* This test uses ArrayObject to simulate a Laminas\Config\Config instance;
* the class itself only tests for Traversable.
*/
- public function testConstructByConfig()
+ public function testConstructByConfig(): void
{
$options = ['cost' => '15'];
$config = new ArrayObject($options);
@@ -57,40 +57,33 @@ public function testConstructByConfig()
$this->assertEquals('15', $bcrypt->getCost());
}
- public function testWrongConstruct()
- {
- $this->expectException(Exception\InvalidArgumentException::class);
- $this->expectExceptionMessage('The options parameter must be an array or a Traversable');
- new BcryptSha('test');
- }
-
- public function testSetCost()
+ public function testSetCost(): void
{
$this->bcrypt->setCost('16');
$this->assertEquals('16', $this->bcrypt->getCost());
}
- public function testSetWrongCost()
+ public function testSetWrongCost(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The cost parameter of bcrypt must be in range 04-31');
$this->bcrypt->setCost('3');
}
- public function testCreateWithBuiltinSalt()
+ public function testCreateWithBuiltinSalt(): void
{
$password = $this->bcrypt->create('test');
$this->assertNotEmpty($password);
$this->assertEquals(60, strlen($password));
}
- public function testVerify()
+ public function testVerify(): void
{
$this->assertTrue($this->bcrypt->verify($this->password, $this->bcryptPassword));
$this->assertFalse($this->bcrypt->verify(substr($this->password, -1), $this->bcryptPassword));
}
- public function testPasswordWith8bitCharacter()
+ public function testPasswordWith8bitCharacter(): void
{
$password = 'test' . chr(128);
$hash = $this->bcrypt->create($password);
diff --git a/test/Password/BcryptTest.php b/test/Password/BcryptTest.php
index 27c4f493..1289789b 100644
--- a/test/Password/BcryptTest.php
+++ b/test/Password/BcryptTest.php
@@ -1,5 +1,7 @@
bcryptPassword = $this->prefix . '10$123456789012345678901uIcehzOq0s9RvVtyXJFIsuuxuE2XZRMq';
}
- public function testConstructByOptions()
+ public function testConstructByOptions(): void
{
$options = ['cost' => '15'];
$bcrypt = new Bcrypt($options);
@@ -48,7 +50,7 @@ public function testConstructByOptions()
* This test uses ArrayObject to simulate a Laminas\Config\Config instance;
* the class itself only tests for Traversable.
*/
- public function testConstructByConfig()
+ public function testConstructByConfig(): void
{
$options = ['cost' => '15'];
$config = new ArrayObject($options);
@@ -56,40 +58,33 @@ public function testConstructByConfig()
$this->assertEquals('15', $bcrypt->getCost());
}
- public function testWrongConstruct()
- {
- $this->expectException(Exception\InvalidArgumentException::class);
- $this->expectExceptionMessage('The options parameter must be an array or a Traversable');
- new Bcrypt('test');
- }
-
- public function testSetCost()
+ public function testSetCost(): void
{
$this->bcrypt->setCost('16');
$this->assertEquals('16', $this->bcrypt->getCost());
}
- public function testSetWrongCost()
+ public function testSetWrongCost(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The cost parameter of bcrypt must be in range 04-31');
$this->bcrypt->setCost('3');
}
- public function testCreateWithBuiltinSalt()
+ public function testCreateWithBuiltinSalt(): void
{
$password = $this->bcrypt->create('test');
$this->assertNotEmpty($password);
$this->assertEquals(60, strlen($password));
}
- public function testVerify()
+ public function testVerify(): void
{
$this->assertTrue($this->bcrypt->verify($this->password, $this->bcryptPassword));
$this->assertFalse($this->bcrypt->verify(substr($this->password, -1), $this->bcryptPassword));
}
- public function testPasswordWith8bitCharacter()
+ public function testPasswordWith8bitCharacter(): void
{
$password = 'test' . chr(128);
$hash = $this->bcrypt->create($password);
@@ -99,25 +94,7 @@ public function testPasswordWith8bitCharacter()
$this->assertTrue($this->bcrypt->verify($password, $hash));
}
- /**
- * @requires PHP 7.0
- */
- public function testSetSaltError()
- {
- $this->expectError();
- $this->bcrypt->setSalt('test');
- }
-
- /**
- * @requires PHP 7.0
- */
- public function testGetSaltError()
- {
- $this->expectError();
- $this->bcrypt->getSalt();
- }
-
- public function testBenchmarkCost()
+ public function testBenchmarkCost(): void
{
$cost = $this->bcrypt->benchmarkCost();
$this->assertIsInt($cost);
diff --git a/test/PublicKey/DiffieHellmanTest.php b/test/PublicKey/DiffieHellmanTest.php
index 7daa9a86..2b51e60f 100644
--- a/test/PublicKey/DiffieHellmanTest.php
+++ b/test/PublicKey/DiffieHellmanTest.php
@@ -1,5 +1,7 @@
getMessage(), 'math support is not detected') !== false) {
+ if (str_contains($e->getMessage(), 'math support is not detected')) {
$this->markTestSkipped($e->getMessage());
} else {
throw $e;
@@ -29,7 +31,7 @@ public function setUp(): void
}
}
- public function testWithSpec()
+ public function testWithSpec(): void
{
$aliceOptions = [
'prime' => '563',
@@ -60,7 +62,7 @@ public function testWithSpec()
$this->assertEquals('117', $bobSecretKey);
}
- public function testWithBinaryFormsAndLargeIntegers()
+ public function testWithBinaryFormsAndLargeIntegers(): void
{
// @codingStandardsIgnoreStart
$aliceOptions = [
@@ -114,7 +116,7 @@ public function testWithBinaryFormsAndLargeIntegers()
// @codingStandardsIgnoreEnd
}
- public function testWithBinaryFormsAndLargeIntegersAndOpensslWithoutPrivateKey()
+ public function testWithBinaryFormsAndLargeIntegersAndOpensslWithoutPrivateKey(): void
{
// @codingStandardsIgnoreStart
// skip this test if openssl DH support is not available
@@ -161,20 +163,20 @@ public function testWithBinaryFormsAndLargeIntegersAndOpensslWithoutPrivateKey()
// @codingStandardsIgnoreEnd
}
- public function testGenerateKeysWithUnsetPrivateKey()
+ public function testGenerateKeysWithUnsetPrivateKey(): void
{
$dh = new DiffieHellman(
// This number was derived from a prime found in the PHP manual
// phpcs:ignore Generic.Files.LineLength.TooLong
'20595147743956561473635506785364689242608156641683669610631810376381034689091062076699156642251004392108952858143484774920291169240754614150220808705672513182725720799259477027420213618077724812926858890986423862521124832721602613093351849581066146191024215917126835618245457407314890365423196085851324526812966877725950802151696434289308856332532106388538037192731883124146318902069590087059811604115285813365981576703499840166093799061116445367741724816239106013192273120668831654534518856490326103748487603609919471960894332833324295672569077878683980560262697833730582706235817119832357244970862344795976907973227',
- 2
+ '2'
);
$dh->generateKeys();
$privateKey = $dh->getPrivateKey();
$this->assertNotNull($privateKey);
}
- public function testInitMathBeforeAnyConversion()
+ public function testInitMathBeforeAnyConversion(): void
{
$this->expectNotToPerformAssertions();
@@ -183,51 +185,51 @@ public function testInitMathBeforeAnyConversion()
new DiffieHellman('563', '5', hex2bin('09'), DiffieHellman::FORMAT_BINARY);
}
- public function testGetPublicKeyWithoutGenerated()
+ public function testGetPublicKeyWithoutGenerated(): void
{
- $dh = new DiffieHellman(563, 5);
+ $dh = new DiffieHellman('563', '5');
$this->expectException(Exception\InvalidArgumentException::class);
$dh->getPublicKey();
}
- public function testSetWrongPublicKey()
+ public function testSetWrongPublicKey(): void
{
- $dh = new DiffieHellman(563, 5);
+ $dh = new DiffieHellman('563', '5');
$this->expectException(Exception\InvalidArgumentException::class);
- $dh->setPublicKey(-2);
+ $dh->setPublicKey('-2');
}
- public function testGetSharedSecretKeyWihoutCompute()
+ public function testGetSharedSecretKeyWihoutCompute(): void
{
- $dh = new DiffieHellman(563, 5);
+ $dh = new DiffieHellman('563', '5');
$this->expectException(Exception\InvalidArgumentException::class);
$dh->getSharedSecretKey();
}
- public function testSetWrongPrime()
+ public function testSetWrongPrime(): void
{
- $dh = new DiffieHellman(563, 5);
+ $dh = new DiffieHellman('563', '5');
$this->expectException(Exception\InvalidArgumentException::class);
- $dh->setPrime(-2);
+ $dh->setPrime('-2');
}
- public function testSetWrongGenerator()
+ public function testSetWrongGenerator(): void
{
- $dh = new DiffieHellman(563, 5);
+ $dh = new DiffieHellman('563', '5');
$this->expectException(Exception\InvalidArgumentException::class);
- $dh->setGenerator(-2);
+ $dh->setGenerator('-2');
}
- public function testSetWrongPrivateKey()
+ public function testSetWrongPrivateKey(): void
{
- $dh = new DiffieHellman(563, 5);
+ $dh = new DiffieHellman('563', '5');
$this->expectException(Exception\InvalidArgumentException::class);
- $dh->setPrivateKey(-2);
+ $dh->setPrivateKey('-2');
}
}
diff --git a/test/PublicKey/RsaTest.php b/test/PublicKey/RsaTest.php
index 2013a46e..039b5529 100644
--- a/test/PublicKey/RsaTest.php
+++ b/test/PublicKey/RsaTest.php
@@ -1,5 +1,7 @@
openSslConf = $openSslConf;
try {
- $rsa = new Rsa();
+ new Rsa();
} catch (Rsa\Exception\RuntimeException $e) {
- if (strpos($e->getMessage(), 'requires openssl extension') !== false) {
+ if (str_contains($e->getMessage(), 'requires openssl extension')) {
$this->markTestSkipped($e->getMessage());
} else {
throw $e;
@@ -96,7 +88,7 @@ public function setUp(): void
-----END PUBLIC KEY-----
RSAKEY;
- $this->testCertificateString = <<testCertificateString = <<testPemFile = realpath(__DIR__ . '/../_files/test.pem');
@@ -138,7 +130,7 @@ public function setUp(): void
$this->rsaBase64Out = new Rsa($rsaOptions);
}
- public function testFactoryCreatesInstance()
+ public function testFactoryCreatesInstance(): void
{
$rsa = Rsa::factory([
'hash_algorithm' => 'sha1',
@@ -150,7 +142,7 @@ public function testFactoryCreatesInstance()
$this->assertInstanceOf(RsaOptions::class, $rsa->getOptions());
}
- public function testFactoryCreatesKeys()
+ public function testFactoryCreatesKeys(): void
{
$rsa = Rsa::factory([
'private_key' => $this->testPemString,
@@ -160,7 +152,7 @@ public function testFactoryCreatesKeys()
$this->assertInstanceOf(PublicKey::class, $rsa->getOptions()->getPublicKey());
}
- public function testFactoryCreatesKeysFromFiles()
+ public function testFactoryCreatesKeysFromFiles(): void
{
$rsa = Rsa::factory([
'private_key' => $this->testPemFile,
@@ -169,7 +161,7 @@ public function testFactoryCreatesKeysFromFiles()
$this->assertInstanceOf(PublicKey::class, $rsa->getOptions()->getPublicKey());
}
- public function testFactoryCreatesJustPublicKey()
+ public function testFactoryCreatesJustPublicKey(): void
{
$rsa = Rsa::factory([
'public_key' => $this->testCertificateString,
@@ -178,7 +170,7 @@ public function testFactoryCreatesJustPublicKey()
$this->assertNull($rsa->getOptions()->getPrivateKey());
}
- public function testConstructorCreatesInstanceWithDefaultOptions()
+ public function testConstructorCreatesInstanceWithDefaultOptions(): void
{
$rsa = new Rsa();
$this->assertInstanceOf(Rsa::class, $rsa);
@@ -187,7 +179,7 @@ public function testConstructorCreatesInstanceWithDefaultOptions()
$this->assertTrue($rsa->getOptions()->getBinaryOutput());
}
- public function testPrivateKeyInstanceCreation()
+ public function testPrivateKeyInstanceCreation(): void
{
$privateKey = Rsa\PrivateKey::fromFile($this->testPemFile);
$this->assertInstanceOf(PrivateKey::class, $privateKey);
@@ -196,7 +188,7 @@ public function testPrivateKeyInstanceCreation()
$this->assertInstanceOf(PrivateKey::class, $privateKey);
}
- public function testPublicKeyInstanceCreation()
+ public function testPublicKeyInstanceCreation(): void
{
$publicKey = new Rsa\PublicKey($this->testPemStringPublic);
$this->assertInstanceOf(PublicKey::class, $publicKey);
@@ -208,7 +200,7 @@ public function testPublicKeyInstanceCreation()
$this->assertInstanceOf(PublicKey::class, $publicKey);
}
- public function testSignGeneratesExpectedBinarySignature()
+ public function testSignGeneratesExpectedBinarySignature(): void
{
$signature = $this->rsa->sign('1234567890');
$this->assertEquals(
@@ -217,7 +209,7 @@ public function testSignGeneratesExpectedBinarySignature()
);
}
- public function testSignGeneratesExpectedBinarySignatureUsingExternalKey()
+ public function testSignGeneratesExpectedBinarySignatureUsingExternalKey(): void
{
$rsaOptions = new RsaOptions([
'public_key' => new Rsa\PublicKey($this->testCertificateString),
@@ -233,7 +225,7 @@ public function testSignGeneratesExpectedBinarySignatureUsingExternalKey()
);
}
- public function testSignGeneratesExpectedBase64Signature()
+ public function testSignGeneratesExpectedBase64Signature(): void
{
$signature = $this->rsaBase64Out->sign('1234567890');
$this->assertEquals(
@@ -242,7 +234,7 @@ public function testSignGeneratesExpectedBase64Signature()
);
}
- public function testVerifyVerifiesBinarySignatures()
+ public function testVerifyVerifiesBinarySignatures(): void
{
$signature = $this->rsa->sign('1234567890');
$result = $this->rsa->verify('1234567890', $signature);
@@ -250,7 +242,7 @@ public function testVerifyVerifiesBinarySignatures()
$this->assertTrue($result);
}
- public function testVerifyVerifiesBinarySignaturesUsingCertificate()
+ public function testVerifyVerifiesBinarySignaturesUsingCertificate(): void
{
$rsaOptions = new RsaOptions([
'public_key' => new Rsa\PublicKey($this->testCertificateString),
@@ -265,7 +257,7 @@ public function testVerifyVerifiesBinarySignaturesUsingCertificate()
$this->assertTrue($result);
}
- public function testVerifyVerifiesBase64Signatures()
+ public function testVerifyVerifiesBase64Signatures(): void
{
$signature = $this->rsaBase64Out->sign('1234567890');
$result = $this->rsaBase64Out->verify('1234567890', $signature);
@@ -273,7 +265,7 @@ public function testVerifyVerifiesBase64Signatures()
$this->assertTrue($result);
}
- public function testEncryptionWithPublicKey()
+ public function testEncryptionWithPublicKey(): void
{
$publicKey = new Rsa\PublicKey($this->testCertificateString);
$privateKey = new Rsa\PrivateKey($this->testPemString);
@@ -282,7 +274,7 @@ public function testEncryptionWithPublicKey()
$this->assertEquals('1234567890', $privateKey->decrypt($encrypted));
}
- public function testEncryptionWithPrivateKey()
+ public function testEncryptionWithPrivateKey(): void
{
$publicKey = new Rsa\PublicKey($this->testCertificateString);
$privateKey = new Rsa\PrivateKey($this->testPemString);
@@ -291,14 +283,14 @@ public function testEncryptionWithPrivateKey()
$this->assertEquals('1234567890', $publicKey->decrypt($encrypted));
}
- public function testEncryptionWithOwnKeys()
+ public function testEncryptionWithOwnKeys(): void
{
$encrypted = $this->rsa->encrypt('1234567890');
$this->assertEquals('1234567890', $this->rsa->decrypt($encrypted));
}
- public function testEncryptionUsingPublicKeyEncryption()
+ public function testEncryptionUsingPublicKeyEncryption(): void
{
$encrypted = $this->rsa->encrypt('1234567890', $this->rsa->getOptions()->getPublicKey());
@@ -308,7 +300,7 @@ public function testEncryptionUsingPublicKeyEncryption()
);
}
- public function testEncryptionUsingPublicKeyBase64Encryption()
+ public function testEncryptionUsingPublicKeyBase64Encryption(): void
{
$encrypted = $this->rsaBase64Out->encrypt('1234567890', $this->rsaBase64Out->getOptions()->getPublicKey());
@@ -321,7 +313,7 @@ public function testEncryptionUsingPublicKeyBase64Encryption()
);
}
- public function testBase64EncryptionUsingCertificatePublicKeyEncryption()
+ public function testBase64EncryptionUsingCertificatePublicKeyEncryption(): void
{
$rsa1 = new Rsa(new RsaOptions([
'public_key' => new Rsa\PublicKey($this->testCertificateString),
@@ -341,7 +333,7 @@ public function testBase64EncryptionUsingCertificatePublicKeyEncryption()
);
}
- public function testEncryptionUsingPrivateKeyEncryption()
+ public function testEncryptionUsingPrivateKeyEncryption(): void
{
$encrypted = $this->rsa->encrypt('1234567890', $this->rsa->getOptions()->getPrivateKey());
$decrypted = $this->rsa->decrypt($encrypted, $this->rsa->getOptions()->getPublicKey());
@@ -349,7 +341,7 @@ public function testEncryptionUsingPrivateKeyEncryption()
$this->assertEquals('1234567890', $decrypted);
}
- public function testEncryptionUsingPrivateKeyBase64Encryption()
+ public function testEncryptionUsingPrivateKeyBase64Encryption(): void
{
$encrypted = $this->rsaBase64Out->encrypt('1234567890', $this->rsaBase64Out->getOptions()->getPrivateKey());
$decrypted = $this->rsaBase64Out->decrypt(
@@ -360,7 +352,7 @@ public function testEncryptionUsingPrivateKeyBase64Encryption()
$this->assertEquals('1234567890', $decrypted);
}
- public function testKeyGenerationWithDefaults()
+ public function testKeyGenerationWithDefaults(): void
{
if (! $this->openSslConf) {
$this->markTestSkipped('No openssl.cnf found or defined; cannot generate keys');
@@ -373,7 +365,7 @@ public function testKeyGenerationWithDefaults()
$this->assertInstanceOf(PublicKey::class, $rsa->getOptions()->getPublicKey());
}
- public function testKeyGenerationWithUserOpensslConfig()
+ public function testKeyGenerationWithUserOpensslConfig(): void
{
$rsaOptions = new RsaOptions();
$rsaOptions->generateKeys([
@@ -385,7 +377,7 @@ public function testKeyGenerationWithUserOpensslConfig()
$this->assertInstanceOf(PublicKey::class, $rsaOptions->getPublicKey());
}
- public function testKeyGenerationCreatesPassphrasedPrivateKey()
+ public function testKeyGenerationCreatesPassphrasedPrivateKey(): void
{
$this->expectException(Exception\RuntimeException::class);
@@ -397,13 +389,13 @@ public function testKeyGenerationCreatesPassphrasedPrivateKey()
'private_key_bits' => 512,
]);
- $rsa = Rsa::factory([
+ Rsa::factory([
'pass_phrase' => '1234567890',
'private_key' => $rsaOptions->getPrivateKey()->toString(),
]);
}
- public function testRsaLoadsPassphrasedKeys()
+ public function testRsaLoadsPassphrasedKeys(): void
{
$this->expectNotToPerformAssertions();
@@ -421,66 +413,66 @@ public function testRsaLoadsPassphrasedKeys()
]);
}
- public function testLaminas3492Base64DetectDecrypt()
+ public function testLaminas3492Base64DetectDecrypt(): void
{
$data = 'vNKINbWV6qUKGsmawN8ii0mak7PPNoVQPC7fwXJOgMNfCgdT+9W4PUte4fic6U4A6fMra4gv7NCTESxap2qpBQ==';
$this->rsa->getOptions()->setOpensslPadding(OPENSSL_PKCS1_PADDING);
$this->assertEquals('1234567890', $this->rsa->decrypt($data));
}
- public function testLaminas3492Base64DetectVerify()
+ public function testLaminas3492Base64DetectVerify(): void
{
$data = 'sMHpp3u6DNecIm5RIkDD3xyKaH6qqP8roUWDs215iOGHehfK1ypqwoETKNP7NaksGS2C1Up813ixlGXkipPVbQ==';
$this->assertTrue($this->rsa->verify('1234567890', $data));
}
- public function testDecryptBase64()
+ public function testDecryptBase64(): void
{
$data = 'vNKINbWV6qUKGsmawN8ii0mak7PPNoVQPC7fwXJOgMNfCgdT+9W4PUte4fic6U4A6fMra4gv7NCTESxap2qpBQ==';
$this->rsa->getOptions()->setOpensslPadding(OPENSSL_PKCS1_PADDING);
$this->assertEquals('1234567890', $this->rsa->decrypt($data, null, Rsa::MODE_BASE64));
}
- public function testDecryptCorruptBase64()
+ public function testDecryptCorruptBase64(): void
{
$data = 'vNKINbWV6qUKGsmawN8ii0mak7PPNoVQPC7fwXJOgMNfCgdT+9W4PUte4fic6U4A6fMra4gv7NCTESxap2qpBQ==';
$this->expectException(Exception\RuntimeException::class);
$this->rsa->decrypt(base64_decode($data), null, Rsa::MODE_BASE64);
}
- public function testDecryptRaw()
+ public function testDecryptRaw(): void
{
$data = 'vNKINbWV6qUKGsmawN8ii0mak7PPNoVQPC7fwXJOgMNfCgdT+9W4PUte4fic6U4A6fMra4gv7NCTESxap2qpBQ==';
$this->rsa->getOptions()->setOpensslPadding(OPENSSL_PKCS1_PADDING);
$this->assertEquals('1234567890', $this->rsa->decrypt(base64_decode($data), null, Rsa::MODE_RAW));
}
- public function testDecryptCorruptRaw()
+ public function testDecryptCorruptRaw(): void
{
$data = 'vNKINbWV6qUKGsmawN8ii0mak7PPNoVQPC7fwXJOgMNfCgdT+9W4PUte4fic6U4A6fMra4gv7NCTESxap2qpBQ==';
$this->expectException(Exception\RuntimeException::class);
$this->rsa->decrypt($data, null, Rsa::MODE_RAW);
}
- public function testVerifyBase64()
+ public function testVerifyBase64(): void
{
$data = 'sMHpp3u6DNecIm5RIkDD3xyKaH6qqP8roUWDs215iOGHehfK1ypqwoETKNP7NaksGS2C1Up813ixlGXkipPVbQ==';
$this->assertTrue($this->rsa->verify('1234567890', $data, null, Rsa::MODE_BASE64));
}
- public function testVerifyCorruptBase64()
+ public function testVerifyCorruptBase64(): void
{
$data = 'sMHpp3u6DNecIm5RIkDD3xyKaH6qqP8roUWDs215iOGHehfK1ypqwoETKNP7NaksGS2C1Up813ixlGXkipPVbQ==';
$this->assertFalse($this->rsa->verify('1234567890', base64_decode($data), null, Rsa::MODE_BASE64));
}
- public function testVerifyRaw()
+ public function testVerifyRaw(): void
{
$data = 'sMHpp3u6DNecIm5RIkDD3xyKaH6qqP8roUWDs215iOGHehfK1ypqwoETKNP7NaksGS2C1Up813ixlGXkipPVbQ==';
$this->assertTrue($this->rsa->verify('1234567890', base64_decode($data), null, Rsa::MODE_RAW));
}
- public function testVerifyCorruptRaw()
+ public function testVerifyCorruptRaw(): void
{
$data = 'sMHpp3u6DNecIm5RIkDD3xyKaH6qqP8roUWDs215iOGHehfK1ypqwoETKNP7NaksGS2C1Up813ixlGXkipPVbQ==';
$this->assertFalse($this->rsa->verify('1234567890', $data, null, Rsa::MODE_RAW));
diff --git a/test/Symmetric/AbstractTest.php b/test/Symmetric/AbstractTestcase.php
similarity index 84%
rename from test/Symmetric/AbstractTest.php
rename to test/Symmetric/AbstractTestcase.php
index 75e5c6a0..dfdd5cd7 100644
--- a/test/Symmetric/AbstractTest.php
+++ b/test/Symmetric/AbstractTestcase.php
@@ -1,5 +1,7 @@
crypt = new $this->adapterClass();
- } catch (Exception\RuntimeException $e) {
+ } catch (Exception\RuntimeException) {
$this->markTestSkipped(
sprintf("%s is not installed, I cannot execute %s", $this->adapterClass, static::class)
);
@@ -60,7 +63,7 @@ public function setUp(): void
$this->plaintext = file_get_contents(__DIR__ . '/../_files/plaintext');
}
- public function testConstructByParams()
+ public function testConstructByParams(): void
{
$key = $this->generateKey();
$iv = $this->generateSalt();
@@ -75,7 +78,7 @@ public function testConstructByParams()
$this->assertEquals($crypt->getAlgorithm(), $options['algorithm']);
$this->assertEquals($crypt->getMode(), $options['mode']);
$this->assertEquals($crypt->getKey(), mb_substr($key, 0, $crypt->getKeySize(), '8bit'));
- $this->assertEquals($crypt->getSalt(), mb_substr($iv, 0, $crypt->getSaltSize(), '8bit'));
+ $this->assertEquals($crypt->getSalt(), mb_substr((string) $iv, 0, $crypt->getSaltSize(), '8bit'));
$this->assertInstanceOf(PKCS7::class, $crypt->getPadding());
}
@@ -83,7 +86,7 @@ public function testConstructByParams()
* This test uses ArrayObject to simulate a Laminas\Config\Config instance;
* the class itself only tests for Traversable.
*/
- public function testConstructByConfig()
+ public function testConstructByConfig(): void
{
$key = $this->generateKey();
$iv = $this->generateSalt();
@@ -99,25 +102,25 @@ public function testConstructByConfig()
$this->assertEquals($crypt->getAlgorithm(), $options['algorithm']);
$this->assertEquals($crypt->getMode(), $options['mode']);
$this->assertEquals($crypt->getKey(), mb_substr($key, 0, $crypt->getKeySize(), '8bit'));
- $this->assertEquals($crypt->getSalt(), mb_substr($iv, 0, $crypt->getSaltSize(), '8bit'));
+ $this->assertEquals($crypt->getSalt(), mb_substr((string) $iv, 0, $crypt->getSaltSize(), '8bit'));
$this->assertInstanceOf(PKCS7::class, $crypt->getPadding());
}
- public function testConstructWrongParam()
+ public function testConstructWrongParam(): void
{
$options = 'test';
- $this->expectException(Exception\InvalidArgumentException::class);
- $this->expectExceptionMessage('The options parameter must be an array or a Traversable');
+ $this->expectException(TypeError::class);
+ $this->expectExceptionMessage('($options) must be of type Traversable|array, string given');
new $this->adapterClass($options);
}
- public function testSetAlgorithm()
+ public function testSetAlgorithm(): void
{
$this->crypt->setAlgorithm($this->defaultAlgo);
$this->assertEquals($this->crypt->getAlgorithm(), $this->defaultAlgo);
}
- public function testSetWrongAlgorithm()
+ public function testSetWrongAlgorithm(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
@@ -127,7 +130,7 @@ public function testSetWrongAlgorithm()
$this->crypt->setAlgorithm('test');
}
- public function testSetKey()
+ public function testSetKey(): void
{
$key = $this->generateKey();
$result = $this->crypt->setKey($key);
@@ -136,19 +139,19 @@ public function testSetKey()
$this->assertEquals($key, $this->crypt->getKey());
}
- public function testSetEmptyKey()
+ public function testSetEmptyKey(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The key cannot be empty');
$this->crypt->setKey('');
}
- public function testSetShortKey()
+ public function testSetShortKey(): void
{
foreach ($this->crypt->getSupportedAlgorithms() as $algo) {
$this->crypt->setAlgorithm($algo);
try {
- $result = $this->crypt->setKey('four');
+ $this->crypt->setKey('four');
} catch (\Exception $ex) {
$this->assertInstanceOf(
Exception\InvalidArgumentException::class,
@@ -158,7 +161,7 @@ public function testSetShortKey()
}
}
- public function testSetSalt()
+ public function testSetSalt(): void
{
$iv = $this->generateSalt() . $this->generateSalt();
$this->crypt->setSalt($iv);
@@ -169,19 +172,19 @@ public function testSetSalt()
$this->assertEquals($iv, $this->crypt->getOriginalSalt());
}
- public function testShortSalt()
+ public function testShortSalt(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->crypt->setSalt('short');
}
- public function testSetMode()
+ public function testSetMode(): void
{
$this->crypt->setMode($this->defaultMode);
$this->assertEquals($this->defaultMode, $this->crypt->getMode());
}
- public function testSetWrongMode()
+ public function testSetWrongMode(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
@@ -191,7 +194,7 @@ public function testSetWrongMode()
$this->crypt->setMode('xxx');
}
- public function testEncryptDecrypt()
+ public function testEncryptDecrypt(): void
{
$this->crypt->setPadding(new PKCS7());
foreach ($this->crypt->getSupportedAlgorithms() as $algo) {
@@ -207,7 +210,7 @@ public function testEncryptDecrypt()
$this->crypt->setAlgorithm($algo);
try {
$this->crypt->setMode($mode);
- } catch (\Exception $e) {
+ } catch (\Exception) {
// Continue if the encryption mode is not supported for the algorithm
continue;
}
@@ -226,20 +229,20 @@ public function testEncryptDecrypt()
}
}
- public function testEncryptWithoutKey()
+ public function testEncryptWithoutKey(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->crypt->encrypt('test');
}
- public function testEncryptEmptyData()
+ public function testEncryptEmptyData(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The data to encrypt cannot be empty');
$this->crypt->encrypt('');
}
- public function testEncryptWithoutSalt()
+ public function testEncryptWithoutSalt(): void
{
$this->crypt->setKey($this->generateKey());
$this->expectException(Exception\InvalidArgumentException::class);
@@ -247,20 +250,20 @@ public function testEncryptWithoutSalt()
$this->crypt->encrypt($this->plaintext);
}
- public function testDecryptEmptyData()
+ public function testDecryptEmptyData(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('The data to decrypt cannot be empty');
$this->crypt->decrypt('');
}
- public function testDecryptWithoutKey()
+ public function testDecryptWithoutKey(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->crypt->decrypt($this->plaintext);
}
- public function testSetOptions()
+ public function testSetOptions(): void
{
$options = [
'algo' => $this->defaultAlgo,
@@ -283,7 +286,7 @@ public function testSetOptions()
$this->assertInstanceOf(NoPadding::class, $this->crypt->getPadding());
}
- public function testSetPaddingPluginManager()
+ public function testSetPaddingPluginManager(): void
{
$this->crypt->setPaddingPluginManager(
$this->getMockBuilder(ContainerInterface::class)->getMock()
@@ -291,13 +294,13 @@ public function testSetPaddingPluginManager()
$this->assertInstanceOf(ContainerInterface::class, $this->crypt->getPaddingPluginManager());
}
- public function testSetWrongPaddingPluginManager()
+ public function testSetWrongPaddingPluginManager(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->crypt->setPaddingPluginManager(stdClass::class);
}
- public function testSetNotExistingPaddingPluginManager()
+ public function testSetNotExistingPaddingPluginManager(): void
{
$this->expectException(Exception\InvalidArgumentException::class);
$this->crypt->setPaddingPluginManager('Foo');
diff --git a/test/Symmetric/McryptDeprecatedTest.php b/test/Symmetric/McryptDeprecatedTest.php
deleted file mode 100644
index 5752397e..00000000
--- a/test/Symmetric/McryptDeprecatedTest.php
+++ /dev/null
@@ -1,24 +0,0 @@
-markTestSkipped('The Mcrypt deprecated test is for PHP 7.1+');
- }
- }
-
- public function testDeprecated()
- {
- $this->expectDeprecation();
- new Mcrypt();
- }
-}
diff --git a/test/Symmetric/OpensslAeadTest.php b/test/Symmetric/OpensslAeadTest.php
index a9073f14..c9eb223e 100644
--- a/test/Symmetric/OpensslAeadTest.php
+++ b/test/Symmetric/OpensslAeadTest.php
@@ -1,5 +1,7 @@
'aes',
@@ -48,10 +52,10 @@ public function testConstructByParams()
$this->assertEquals($params['tag_size'], $crypt->getTagSize());
}
- public function testRejectsNonStringAadMode()
+ public function testRejectsNonStringAadMode(): void
{
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage('The provided $aad must be a string, integer given');
+ $this->expectException(TypeError::class);
+ $this->expectExceptionMessage('($aad) must be of type string, int given');
new Openssl([
'algo' => 'aes',
@@ -61,10 +65,10 @@ public function testRejectsNonStringAadMode()
]);
}
- public function testRejectsNonIntegerTagSize()
+ public function testRejectsNonIntegerTagSize(): void
{
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessage('The provided $size must be an integer, double given');
+ $this->expectException(TypeError::class);
+ $this->expectExceptionMessage('($size) must be of type int, float given');
new Openssl([
'algo' => 'aes',
@@ -74,14 +78,14 @@ public function testRejectsNonIntegerTagSize()
]);
}
- public function testSetGetAad()
+ public function testSetGetAad(): void
{
$this->crypt->setMode('gcm');
$this->crypt->setAad('foo@bar.com');
$this->assertEquals('foo@bar.com', $this->crypt->getAad());
}
- public function testSetAadException()
+ public function testSetAadException(): void
{
$this->crypt->setMode('cbc');
@@ -89,21 +93,21 @@ public function testSetAadException()
$this->crypt->setAad('foo@bar.com');
}
- public function testSetGetGcmTagSize()
+ public function testSetGetGcmTagSize(): void
{
$this->crypt->setMode('gcm');
$this->crypt->setTagSize(10);
$this->assertEquals(10, $this->crypt->getTagSize());
}
- public function testSetGetCcmTagSize()
+ public function testSetGetCcmTagSize(): void
{
$this->crypt->setMode('ccm');
$this->crypt->setTagSize(28);
$this->assertEquals(28, $this->crypt->getTagSize());
}
- public function testSetTagSizeException()
+ public function testSetTagSizeException(): void
{
$this->crypt->setMode('cbc');
@@ -111,7 +115,7 @@ public function testSetTagSizeException()
$this->crypt->setTagSize(10);
}
- public function testSetInvalidGcmTagSize()
+ public function testSetInvalidGcmTagSize(): void
{
$this->crypt->setMode('gcm');
@@ -120,7 +124,7 @@ public function testSetInvalidGcmTagSize()
}
/** @psalm-return array */
- public function getAuthEncryptionMode(): array
+ public static function getAuthEncryptionMode(): array
{
return [
['gcm'],
@@ -131,7 +135,7 @@ public function getAuthEncryptionMode(): array
/**
* @dataProvider getAuthEncryptionMode
*/
- public function testAuthenticatedEncryption(string $mode)
+ public function testAuthenticatedEncryption(string $mode): void
{
$this->crypt->setMode($mode);
$this->crypt->setKey(random_bytes($this->crypt->getKeySize()));
@@ -153,26 +157,29 @@ public function testAuthenticatedEncryption(string $mode)
/**
* @dataProvider getAuthEncryptionMode
*/
- public function testAuthenticationError(string $mode)
+ public function testAuthenticationError(string $mode): void
{
$this->crypt->setMode($mode);
$this->crypt->setKey(random_bytes($this->crypt->getKeySize()));
$this->crypt->setSalt(random_bytes($this->crypt->getSaltSize()));
- $plaintext = Rand::getBytes(1024);
- $encrypt = $this->crypt->encrypt($plaintext);
+ $plaintext = Rand::getBytes(1024);
+ $encrypt = $this->crypt->encrypt($plaintext);
+ $encryptArray = str_split($encrypt);
// Alter the encrypted message
// phpcs:disable SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator.RequiredCombinedAssigmentOperator
- $i = rand(0, mb_strlen($encrypt, '8bit') - 1);
- $encrypt[$i] = $encrypt[$i] ^ chr(1);
+ $i = random_int(0, mb_strlen($encrypt, '8bit') - 1);
+ $encryptArray[$i] ^= chr(1);
// phpcs:enable SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator.RequiredCombinedAssigmentOperator
+ $encrypt = implode('', $encryptArray);
+
$this->expectException(RuntimeException::class);
$this->crypt->decrypt($encrypt);
}
- public function testGcmEncryptWithTagSize()
+ public function testGcmEncryptWithTagSize(): void
{
$this->crypt->setMode('gcm');
$this->crypt->setKey(random_bytes($this->crypt->getKeySize()));
@@ -180,12 +187,12 @@ public function testGcmEncryptWithTagSize()
$this->crypt->setTagSize(14);
$plaintext = Rand::getBytes(1024);
- $encrypt = $this->crypt->encrypt($plaintext);
+ $this->crypt->encrypt($plaintext);
$this->assertEquals(14, $this->crypt->getTagSize());
$this->assertEquals($this->crypt->getTagSize(), mb_strlen($this->crypt->getTag(), '8bit'));
}
- public function testCcmEncryptWithTagSize()
+ public function testCcmEncryptWithTagSize(): void
{
$this->crypt->setMode('ccm');
$this->crypt->setKey(random_bytes($this->crypt->getKeySize()));
@@ -193,7 +200,7 @@ public function testCcmEncryptWithTagSize()
$this->crypt->setTagSize(14);
$plaintext = Rand::getBytes(1024);
- $encrypt = $this->crypt->encrypt($plaintext);
+ $this->crypt->encrypt($plaintext);
$this->assertEquals(14, $this->crypt->getTagSize());
$this->assertEquals($this->crypt->getTagSize(), mb_strlen($this->crypt->getTag(), '8bit'));
}
@@ -201,7 +208,7 @@ public function testCcmEncryptWithTagSize()
/**
* @dataProvider getAuthEncryptionMode
*/
- public function testAuthenticatedEncryptionWithAdditionalData(string $mode)
+ public function testAuthenticatedEncryptionWithAdditionalData(string $mode): void
{
$this->crypt->setMode($mode);
$this->crypt->setKey(random_bytes($this->crypt->getKeySize()));
@@ -224,7 +231,7 @@ public function testAuthenticatedEncryptionWithAdditionalData(string $mode)
/**
* @dataProvider getAuthEncryptionMode
*/
- public function testAuthenticationErrorOnAdditionalData(string $mode)
+ public function testAuthenticationErrorOnAdditionalData(string $mode): void
{
$this->crypt->setMode($mode);
$this->crypt->setKey(random_bytes($this->crypt->getKeySize()));
diff --git a/test/Symmetric/OpensslTest.php b/test/Symmetric/OpensslTestcase.php
similarity index 86%
rename from test/Symmetric/OpensslTest.php
rename to test/Symmetric/OpensslTestcase.php
index ad54ca1a..eadd937a 100644
--- a/test/Symmetric/OpensslTest.php
+++ b/test/Symmetric/OpensslTestcase.php
@@ -1,5 +1,7 @@
markTestSkipped('The CTR mode is not supported');
diff --git a/test/Symmetric/Padding/NoPaddingTest.php b/test/Symmetric/Padding/NoPaddingTest.php
index e5795385..ab7e9ea9 100644
--- a/test/Symmetric/Padding/NoPaddingTest.php
+++ b/test/Symmetric/Padding/NoPaddingTest.php
@@ -1,5 +1,7 @@
padding = new NoPadding();
}
- public function testPad()
+ public function testPad(): void
{
$string = 'test';
for ($size = 0; $size < 10; $size++) {
@@ -23,7 +25,7 @@ public function testPad()
}
}
- public function testStrip()
+ public function testStrip(): void
{
$string = 'test';
$this->assertEquals($string, $this->padding->strip($string));
diff --git a/test/Symmetric/Padding/PaddingPluginManagerTest.php b/test/Symmetric/Padding/PaddingPluginManagerTest.php
index a060b73c..24bb2d47 100644
--- a/test/Symmetric/Padding/PaddingPluginManagerTest.php
+++ b/test/Symmetric/Padding/PaddingPluginManagerTest.php
@@ -1,5 +1,7 @@
*/
- public function getPaddings(): array
+ public static function getPaddings(): array
{
return [
['pkcs7'],
@@ -20,7 +22,7 @@ public function getPaddings(): array
];
}
- public function testConstruct()
+ public function testConstruct(): void
{
$plugin = new PaddingPluginManager();
$this->assertInstanceOf(ContainerInterface::class, $plugin);
@@ -29,7 +31,7 @@ public function testConstruct()
/**
* @dataProvider getPaddings
*/
- public function testHas(string $padding)
+ public function testHas(string $padding): void
{
$plugin = new PaddingPluginManager();
$this->assertTrue($plugin->has($padding));
@@ -38,13 +40,13 @@ public function testHas(string $padding)
/**
* @dataProvider getPaddings
*/
- public function testGet(string $padding)
+ public function testGet(string $padding): void
{
$plugin = new PaddingPluginManager();
$this->assertInstanceOf(PaddingInterface::class, $plugin->get($padding));
}
- public function testGetError()
+ public function testGetError(): void
{
$plugin = new PaddingPluginManager();
diff --git a/test/Symmetric/Padding/Pkcs7Test.php b/test/Symmetric/Padding/Pkcs7Test.php
index 8376d749..fe82448c 100644
--- a/test/Symmetric/Padding/Pkcs7Test.php
+++ b/test/Symmetric/Padding/Pkcs7Test.php
@@ -1,12 +1,14 @@
end = 32;
}
- public function testPad()
+ public function testPad(): void
{
for ($blockSize = $this->start; $blockSize <= $this->end; $blockSize++) {
for ($i = 1; $i <= $blockSize; $i++) {
- $input = str_repeat(chr(rand(0, 255)), $i);
+ $input = str_repeat(chr(random_int(0, 255)), $i);
$output = $this->padding->pad($input, $blockSize);
$num = $blockSize - ($i % $blockSize);
$this->assertEquals($output, $input . str_repeat(chr($num), $num));
@@ -37,7 +39,7 @@ public function testPad()
}
}
- public function testStrip()
+ public function testStrip(): void
{
for ($blockSize = $this->start; $blockSize <= $this->end; $blockSize++) {
for ($i = 1; $i < $blockSize; $i++) {
diff --git a/test/SymmetricPluginManagerTest.php b/test/SymmetricPluginManagerTest.php
index fcc38510..6f01db73 100644
--- a/test/SymmetricPluginManagerTest.php
+++ b/test/SymmetricPluginManagerTest.php
@@ -1,5 +1,7 @@
*/
- public function getSymmetrics(): array
+ public static function getSymmetrics(): array
{
- if (PHP_VERSION_ID >= 70100) {
- return [
- ['openssl'],
- ];
- }
-
return [
- ['mcrypt'],
['openssl'],
];
}
- public function testConstruct()
+ public function testConstruct(): void
{
$plugin = new SymmetricPluginManager();
$this->assertInstanceOf(ContainerInterface::class, $plugin);
@@ -39,7 +32,7 @@ public function testConstruct()
/**
* @dataProvider getSymmetrics
*/
- public function testHas(string $symmetric)
+ public function testHas(string $symmetric): void
{
$plugin = new SymmetricPluginManager();
$this->assertTrue($plugin->has($symmetric));
@@ -48,7 +41,7 @@ public function testHas(string $symmetric)
/**
* @dataProvider getSymmetrics
*/
- public function testGet(string $symmetric)
+ public function testGet(string $symmetric): void
{
if (! extension_loaded($symmetric)) {
$this->expectException(Exception\RuntimeException::class);
@@ -57,7 +50,7 @@ public function testGet(string $symmetric)
$this->assertInstanceOf(SymmetricInterface::class, $plugin->get($symmetric));
}
- public function testGetError()
+ public function testGetError(): void
{
$plugin = new SymmetricPluginManager();
diff --git a/test/UtilsTest.php b/test/UtilsTest.php
index 27c2b874..6a6f9f3a 100644
--- a/test/UtilsTest.php
+++ b/test/UtilsTest.php
@@ -1,5 +1,7 @@
assertTrue(Utils::compareStrings('test', 'test'));
$this->assertFalse(Utils::compareStrings('test', 'Test'));
diff --git a/test/_autoload.php b/test/_autoload.php
index eb883d63..57fbee66 100644
--- a/test/_autoload.php
+++ b/test/_autoload.php
@@ -1,5 +1,7 @@