Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use absolute path to age executable #7

Merged
merged 8 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2]
laravel: [10.*]
laravel: [11.*]
stability: [prefer-stable]
include:
- testbench: 8.*
- testbench: 9.*
carbon: ^2.63

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
],
"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"
},
"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",
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ parameters:
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
17 changes: 16 additions & 1 deletion src/PrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\TemporaryDirectory\TemporaryDirectory;
use Symfony\Component\Process\ExecutableFinder;

class PrivateKey
{
Expand Down Expand Up @@ -64,7 +65,21 @@ 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)}");
/**
* @var array<string>|string|null
*/
$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!');
Expand Down
15 changes: 14 additions & 1 deletion src/PublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Illuminate\Support\Facades\Process;
use Symfony\Component\Process\ExecutableFinder;

class PublicKey
{
Expand Down Expand Up @@ -31,7 +32,19 @@ public function encode(): string
*/
public function encrypt(string $message, bool $base64): string
{
$result = Process::input($message)->run("age -r {$this->encode()}");
/**
* @var array<string>|string|null
*/
$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!');
Expand Down