From abe7b24b21ce6fc6de71a3169cd799dbdcbea79b Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Tue, 14 May 2024 18:21:51 +0200 Subject: [PATCH 1/8] Update PrivateKey and PublicKey classes to use absolute paths for age command --- src/PrivateKey.php | 14 +++++++++++++- src/PublicKey.php | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/PrivateKey.php b/src/PrivateKey.php index e94a6e2..5523927 100644 --- a/src/PrivateKey.php +++ b/src/PrivateKey.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Spatie\TemporaryDirectory\TemporaryDirectory; +use Symfony\Component\Process\ExecutableFinder; class PrivateKey { @@ -64,7 +65,18 @@ public function decrypt(string $message, bool $base64): string $data = $base64 ? base64_decode(str_replace(['-', '_'], ['+', '/'], $message)) : $message; Storage::build(['driver' => 'local', 'root' => $dir->path()])->put($ulid, $data); - $result = Process::input($this->encode())->run("age -d -i - {$dir->path($ulid)}"); + $command = [ + (new ExecutableFinder())->find('age', 'age', [ + '/usr/local/bin', + '/opt/homebrew/bin', + ]), + '-d', + '-i', + '-', + $dir->path($ulid), + ]; + + $result = Process::input($this->encode())->run($command); if ($result->failed()) { throw new Exception('Failed to decrypt message!'); diff --git a/src/PublicKey.php b/src/PublicKey.php index 5283e70..87bc7e1 100644 --- a/src/PublicKey.php +++ b/src/PublicKey.php @@ -4,6 +4,7 @@ use Exception; use Illuminate\Support\Facades\Process; +use Symfony\Component\Process\ExecutableFinder; class PublicKey { @@ -31,7 +32,16 @@ public function encode(): string */ public function encrypt(string $message, bool $base64): string { - $result = Process::input($message)->run("age -r {$this->encode()}"); + $command = [ + (new ExecutableFinder())->find('age', 'age', [ + '/usr/local/bin', + '/opt/homebrew/bin', + ]), + '-r', + $this->encode(), + ]; + + $result = Process::input($message)->run($command); if ($result->failed()) { throw new Exception('Failed to encrypt message!'); From 382736e25d39aef9678b17468ef19f37458e7367 Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Tue, 14 May 2024 18:22:59 +0200 Subject: [PATCH 2/8] Also test laravel 11 --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 49ff729..e8417d5 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: matrix: os: [ubuntu-latest] php: [8.3, 8.2] - laravel: [10.*] + laravel: [10.*, 11.*] stability: [prefer-stable] include: - testbench: 8.* From 45575d87c9d069f124a12d747ada677e17ac8d0a Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Tue, 14 May 2024 18:26:27 +0200 Subject: [PATCH 3/8] Set var type for linter --- src/PrivateKey.php | 7 +++++-- src/PublicKey.php | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/PrivateKey.php b/src/PrivateKey.php index 5523927..24c190e 100644 --- a/src/PrivateKey.php +++ b/src/PrivateKey.php @@ -15,7 +15,7 @@ class PrivateKey public function __construct(string $privateKey = '') { - if (! $privateKey) { + if (!$privateKey) { $result = Process::pipe([ 'age-keygen', 'grep -E "^AGE-SECRET-KEY-[A-Za-z0-9]{59}$"', @@ -30,7 +30,7 @@ public function __construct(string $privateKey = '') $privateKey = str($privateKey)->trim(); - if (! $privateKey->startsWith('AGE-SECRET-KEY-') || $privateKey->length() !== 74) { + if (!$privateKey->startsWith('AGE-SECRET-KEY-') || $privateKey->length() !== 74) { throw new Exception('Invalid private key provided!'); } @@ -65,6 +65,9 @@ public function decrypt(string $message, bool $base64): string $data = $base64 ? base64_decode(str_replace(['-', '_'], ['+', '/'], $message)) : $message; Storage::build(['driver' => 'local', 'root' => $dir->path()])->put($ulid, $data); + /** + * @var array|string|null + */ $command = [ (new ExecutableFinder())->find('age', 'age', [ '/usr/local/bin', diff --git a/src/PublicKey.php b/src/PublicKey.php index 87bc7e1..e54f9b2 100644 --- a/src/PublicKey.php +++ b/src/PublicKey.php @@ -14,7 +14,7 @@ public function __construct(string $publicKey) { $publicKey = str($publicKey)->trim(); - if (! $publicKey->startsWith('age') || $publicKey->length() !== 62) { + if (!$publicKey->startsWith('age') || $publicKey->length() !== 62) { throw new Exception('Invalid public key provided!'); } @@ -32,6 +32,9 @@ public function encode(): string */ public function encrypt(string $message, bool $base64): string { + /** + * @var array|string|null + */ $command = [ (new ExecutableFinder())->find('age', 'age', [ '/usr/local/bin', From 0790272611844d6d32f1f82fa228183bfd5d1a02 Mon Sep 17 00:00:00 2001 From: lucacastelnuovo Date: Tue, 14 May 2024 16:26:47 +0000 Subject: [PATCH 4/8] Fix styling --- src/PrivateKey.php | 4 ++-- src/PublicKey.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PrivateKey.php b/src/PrivateKey.php index 24c190e..7c86d7f 100644 --- a/src/PrivateKey.php +++ b/src/PrivateKey.php @@ -15,7 +15,7 @@ class PrivateKey public function __construct(string $privateKey = '') { - if (!$privateKey) { + if (! $privateKey) { $result = Process::pipe([ 'age-keygen', 'grep -E "^AGE-SECRET-KEY-[A-Za-z0-9]{59}$"', @@ -30,7 +30,7 @@ public function __construct(string $privateKey = '') $privateKey = str($privateKey)->trim(); - if (!$privateKey->startsWith('AGE-SECRET-KEY-') || $privateKey->length() !== 74) { + if (! $privateKey->startsWith('AGE-SECRET-KEY-') || $privateKey->length() !== 74) { throw new Exception('Invalid private key provided!'); } diff --git a/src/PublicKey.php b/src/PublicKey.php index e54f9b2..661718b 100644 --- a/src/PublicKey.php +++ b/src/PublicKey.php @@ -14,7 +14,7 @@ public function __construct(string $publicKey) { $publicKey = str($publicKey)->trim(); - if (!$publicKey->startsWith('age') || $publicKey->length() !== 62) { + if (! $publicKey->startsWith('age') || $publicKey->length() !== 62) { throw new Exception('Invalid public key provided!'); } From b1099efb5253e0c1b6c0374adcdabe1f41db27a5 Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Tue, 14 May 2024 18:29:18 +0200 Subject: [PATCH 5/8] Upgrade testbench --- composer.json | 4 ++-- phpstan.neon.dist | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e34bf2b..37c92f4 100644 --- a/composer.json +++ b/composer.json @@ -23,9 +23,9 @@ }, "require-dev": { "laravel/pint": "^1.0", - "nunomaduro/collision": "^7.8", + "nunomaduro/collision": "^8.1", "larastan/larastan": "^2.0.1", - "orchestra/testbench": "^8.8", + "orchestra/testbench": "^9.0", "pestphp/pest": "^2.20", "pestphp/pest-plugin-arch": "^2.5", "pestphp/pest-plugin-laravel": "^2.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index cb247a2..f4a34f0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,4 +9,3 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true - checkMissingIterableValueType: false From d7511f9d89a7bd59bfab1368c79b994940eb1ec7 Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Tue, 14 May 2024 18:32:49 +0200 Subject: [PATCH 6/8] Drop laravel 10 support --- .github/workflows/run-tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e8417d5..40cf6c1 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: matrix: os: [ubuntu-latest] php: [8.3, 8.2] - laravel: [10.*, 11.*] + laravel: [11.*] stability: [prefer-stable] include: - testbench: 8.* diff --git a/composer.json b/composer.json index 37c92f4..96f779f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.2", - "illuminate/contracts": "^10.0|^11.0", + "illuminate/contracts": "^11.0", "spatie/laravel-package-tools": "^1.14.0", "spatie/temporary-directory": "^2.2" }, From 08ce1bbe0a37ff7c246f9ad61ff0757136e2363d Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Tue, 14 May 2024 18:43:29 +0200 Subject: [PATCH 7/8] Use testbench 9 in the tests; reintroduce laravel 10 support --- .github/workflows/run-tests.yml | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 40cf6c1..46ee6bd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,10 +19,10 @@ jobs: matrix: os: [ubuntu-latest] php: [8.3, 8.2] - laravel: [11.*] + laravel: [10.*, 11.*] stability: [prefer-stable] include: - - testbench: 8.* + - testbench: 9.* carbon: ^2.63 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 96f779f..37c92f4 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.2", - "illuminate/contracts": "^11.0", + "illuminate/contracts": "^10.0|^11.0", "spatie/laravel-package-tools": "^1.14.0", "spatie/temporary-directory": "^2.2" }, From dc187ddc5df4b84345fba8805a8dae10241f3243 Mon Sep 17 00:00:00 2001 From: Luca Castelnuovo Date: Tue, 14 May 2024 18:45:22 +0200 Subject: [PATCH 8/8] Re drop l10 --- .github/workflows/run-tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 46ee6bd..b063f9c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: matrix: os: [ubuntu-latest] php: [8.3, 8.2] - laravel: [10.*, 11.*] + laravel: [11.*] stability: [prefer-stable] include: - testbench: 9.* diff --git a/composer.json b/composer.json index 37c92f4..96f779f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.2", - "illuminate/contracts": "^10.0|^11.0", + "illuminate/contracts": "^11.0", "spatie/laravel-package-tools": "^1.14.0", "spatie/temporary-directory": "^2.2" },