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

Support Laravel 6 and 7 #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"require": {
"php": ">=7.2.0",
"ext-sodium": "*",
"ext-json": "*",
"illuminate/support": "^5.6"
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
Expand Down
18 changes: 15 additions & 3 deletions src/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LaravelAEAD;

use Illuminate\Support\Arr;
use LaravelAEAD\Ciphers;
use LaravelAEAD\Contracts\Encrypter as EncrypterContract;
use LaravelAEAD\Exceptions\DecryptException;
Expand Down Expand Up @@ -36,6 +37,11 @@ class Encrypter implements EncrypterContract
*/
protected $cipher;

/**
* @var string $key
*/
protected $key;

/**
* Create a new encrypter instance.
*
Expand All @@ -50,6 +56,8 @@ public function __construct($key, $cipherName = 'XCHACHA20-POLY1305-IETF')
// force the key into string.
$key = (string)$key;

$this->key = $key;

// create the instance of the cipher.
$this->cipher = self::makeCipher($key, $cipherName);
}
Expand Down Expand Up @@ -134,7 +142,7 @@ protected function decodePayload(string $payload) : array
$payload = json_decode($this->decodeBase64($payload), true);

// the payload should at least contain the 3 main keys.
if (!array_has($payload, ['value', 'nonce', 'ad'])) {
if (!Arr::has($payload, ['value', 'nonce', 'ad'])) {
throw new DecryptException('Invalid Payload.');
}

Expand Down Expand Up @@ -258,7 +266,7 @@ public static function getCiphers(): array
public static function getCipherClass(string $cipherName): string
{
// retrieves the list of available ciphers
$cipherClass = array_get(self::getCiphers(), $cipherName, null);
$cipherClass = Arr::get(self::getCiphers(), $cipherName, null);

// check if the cipher exists.
if (!$cipherClass || !class_exists($cipherClass)) {
Expand All @@ -268,4 +276,8 @@ public static function getCipherClass(string $cipherName): string
// returns the cipher class.
return $cipherClass;
}
}

public function getKey(): string {
return $this->key;
}
}
5 changes: 3 additions & 2 deletions src/Providers/EncryptionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use LaravelAEAD\Encrypter;
use Illuminate\Encryption\Encrypter as LaravelEncrypter;
use Illuminate\Encryption\EncryptionServiceProvider as LaravelEncryptionServiceProvider;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Contracts\Config\Repository as Config;

Expand Down Expand Up @@ -52,7 +53,7 @@ public function register()
*/
protected function supported(string $cipher) : bool
{
return array_has(Encrypter::getCiphers(), $cipher);
return Arr::has(Encrypter::getCiphers(), $cipher);
}

/**
Expand Down Expand Up @@ -80,4 +81,4 @@ protected function getConfigValue(string $key, $default = null)
// retrieve the value for the key,
return $value;
}
}
}