Skip to content

Commit

Permalink
Merge pull request #23 from CodeLieutenant/chore/change-encryptor-to-…
Browse files Browse the repository at this point in the history
…encrypter

chore: rename *Encryptor to *Encrypter per Laravel convention **BREAKING**
  • Loading branch information
CodeLieutenant committed Mar 5, 2024
2 parents 2046457 + 9d8f925 commit 53d912c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions benchmarks/DecryptionBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace CodeLieutenant\LaravelCrypto\Benchmarks;

use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;
use Illuminate\Encryption\Encrypter;

class DecryptionBench
{
private Encrypter $laravelEncrypter;
private XChaCha20Poly1305Encryptor $xchacha;
private AesGcm256Encryptor $aes256gcm;
private XChaCha20Poly1305Encrypter $xchacha;
private AesGcm256Encrypter $aes256gcm;
private string $xChaChaData;
private string $aes256GcmData;
private string $laravelData;
Expand All @@ -21,8 +21,8 @@ public function __construct()
{
$key = base64_decode(file_get_contents(__DIR__.'/key'));
$this->laravelEncrypter = new Encrypter($key, 'AES-256-CBC');
$this->xchacha = new XChaCha20Poly1305Encryptor($key);
$this->aes256gcm = new AesGcm256Encryptor($key);
$this->xchacha = new XChaCha20Poly1305Encrypter($key);
$this->aes256gcm = new AesGcm256Encrypter($key);
$this->xChaChaData = file_get_contents(__DIR__.'/encrypted-xchacha');
$this->laravelData = file_get_contents(__DIR__.'/encrypted-laravel');
$this->aes256GcmData = file_get_contents(__DIR__.'/encrypted-aes256gcm');
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/EncryptionBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use CodeLieutenant\LaravelCrypto\Encoder\IgbinaryEncoder;
use CodeLieutenant\LaravelCrypto\Encoder\JsonEncoder;
use CodeLieutenant\LaravelCrypto\Encoder\PhpEncoder;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;
use CodeLieutenant\LaravelCrypto\Support\Random;
use Generator;
use Illuminate\Encryption\Encrypter;
Expand Down Expand Up @@ -62,7 +62,7 @@ public function providerChaCha20Crypto(): Generator
foreach ($encoders as $encoderName => $encoder) {
yield 'ChaCha20-' . $encoderName . '-' . $dataName => [
'data' => $dataValue,
'encrypter' => new XChaCha20Poly1305Encryptor(new KeyLoader(Random::bytes(32)), $logger, $encoder),
'encrypter' => new XChaCha20Poly1305Encrypter(new KeyLoader(Random::bytes(32)), $logger, $encoder),
];
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public function providerAESGCMCrypto(): Generator
foreach ($encoders as $encoderName => $encoder) {
yield 'ChaCha20-' . $encoderName . '-' . $dataName => [
'data' => $dataValue,
'encrypter' => new AesGcm256Encryptor(new KeyLoader(Random::bytes(32)), $logger, $encoder),
'encrypter' => new AesGcm256Encrypter(new KeyLoader(Random::bytes(32)), $logger, $encoder),
];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Illuminate\Contracts\Encryption\StringEncrypter;
use Psr\Log\LoggerInterface;

final class AesGcm256Encryptor implements Encrypter, KeyGeneration, StringEncrypter
final class AesGcm256Encrypter implements Encrypter, KeyGeneration, StringEncrypter
{
use Crypto;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Illuminate\Contracts\Encryption\StringEncrypter;
use Psr\Log\LoggerInterface;

final class XChaCha20Poly1305Encryptor implements Encrypter, KeyGeneration, StringEncrypter
final class XChaCha20Poly1305Encrypter implements Encrypter, KeyGeneration, StringEncrypter
{
use Crypto;

Expand Down
8 changes: 4 additions & 4 deletions src/Keys/Generators/AppKeyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace CodeLieutenant\LaravelCrypto\Keys\Generators;

use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;
use CodeLieutenant\LaravelCrypto\Enums\Encryption;
use CodeLieutenant\LaravelCrypto\Keys\EnvKeySaver;
use Illuminate\Contracts\Config\Repository;
Expand All @@ -31,8 +31,8 @@ public function generate(?string $write): ?string

$new = $this->formatKey(
match (Encryption::tryFrom($cipher)) {
Encryption::SodiumAES256GCM => AesGcm256Encryptor::generateKey($cipher),
Encryption::SodiumXChaCha20Poly1305 => XChaCha20Poly1305Encryptor::generateKey($cipher),
Encryption::SodiumAES256GCM => AesGcm256Encrypter::generateKey($cipher),
Encryption::SodiumXChaCha20Poly1305 => XChaCha20Poly1305Encrypter::generateKey($cipher),
default => Encrypter::generateKey($cipher),
}
);
Expand Down
10 changes: 5 additions & 5 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use CodeLieutenant\LaravelCrypto\Encoder\JsonEncoder;
use CodeLieutenant\LaravelCrypto\Encoder\MessagePackEncoder;
use CodeLieutenant\LaravelCrypto\Encoder\PhpEncoder;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;
use CodeLieutenant\LaravelCrypto\Enums\Encryption;
use CodeLieutenant\LaravelCrypto\Hashing\Blake2b;
use CodeLieutenant\LaravelCrypto\Hashing\HashingManager;
Expand Down Expand Up @@ -173,7 +173,7 @@ protected function getConfigPath(): string

protected function registerEncrypter(): void
{
foreach ([AesGcm256Encryptor::class, XChaCha20Poly1305Encryptor::class] as $encryptor) {
foreach ([AesGcm256Encrypter::class, XChaCha20Poly1305Encrypter::class] as $encryptor) {
$this->app->singleton($encryptor);
$this->app->when($encryptor)
->needs(Loader::class)
Expand All @@ -190,8 +190,8 @@ protected function registerEncrypter(): void
}

return match ($enc) {
Encryption::SodiumAES256GCM => $app->make(AesGcm256Encryptor::class),
Encryption::SodiumXChaCha20Poly1305 => $app->make(XChaCha20Poly1305Encryptor::class),
Encryption::SodiumAES256GCM => $app->make(AesGcm256Encrypter::class),
Encryption::SodiumXChaCha20Poly1305 => $app->make(XChaCha20Poly1305Encrypter::class),
};
};

Expand Down
6 changes: 3 additions & 3 deletions tests/Architecture/EncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
declare(strict_types=1);

use CodeLieutenant\LaravelCrypto\Contracts\KeyGeneration;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;
use CodeLieutenant\LaravelCrypto\Enums\Encryption;
use CodeLieutenant\LaravelCrypto\Traits\Crypto;
use Illuminate\Contracts\Encryption\Encrypter;
Expand All @@ -14,5 +14,5 @@
->expect('CodeLieutenant\LaravelCrypto\Encryption')
->toImplement([Encrypter::class, StringEncrypter::class])
->toBeClasses()
->toHaveSuffix('Encryptor')
->toHaveSuffix('Encrypter')
->toBeFinal();
6 changes: 3 additions & 3 deletions tests/Feature/Encryption/AesGcm256EncryptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;

it('should encrypt/decrypt data', function (bool $serialize) {
$encryptor = new AesGcm256Encryptor(inMemoryKeyLoader());
$encryptor = new AesGcm256Encrypter(inMemoryKeyLoader());
$data = $serialize ? ['data'] : 'hello world';
$encrypted = $encryptor->encrypt($data, $serialize);

Expand All @@ -16,7 +16,7 @@
})->with([true, false]);

it('should encrypt/decrypt string', function () {
$encryptor = new AesGcm256Encryptor(inMemoryKeyLoader());
$encryptor = new AesGcm256Encrypter(inMemoryKeyLoader());
$data = 'hello world';
$encrypted = $encryptor->encryptString($data);

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Encryption/XChaCha20Poly1305EncryptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;

it('should encrypt/decrypt data', function (bool $serialize) {
$encryptor = new XChaCha20Poly1305Encryptor(inMemoryKeyLoader());
$encryptor = new XChaCha20Poly1305Encrypter(inMemoryKeyLoader());
$data = $serialize ? ['data'] : 'hello world';
$encrypted = $encryptor->encrypt($data, $serialize);

Expand All @@ -16,7 +16,7 @@
})->with([true, false]);

it('should encrypt/decrypt string', function () {
$encryptor = new XChaCha20Poly1305Encryptor(inMemoryKeyLoader());
$encryptor = new XChaCha20Poly1305Encrypter(inMemoryKeyLoader());
$data = 'hello world';
$encrypted = $encryptor->encryptString($data);

Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/ServiceProviderLoadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encryptor;
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;
use CodeLieutenant\LaravelCrypto\Enums\Encryption;
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Facades\Config;
Expand All @@ -17,6 +17,6 @@
})->with([
['AES-256-GCM', Encrypter::class],
['AES-256-CBC', Encrypter::class],
[Encryption::SodiumAES256GCM->value, AesGcm256Encryptor::class],
[Encryption::SodiumXChaCha20Poly1305->value, XChaCha20Poly1305Encryptor::class],
[Encryption::SodiumAES256GCM->value, AesGcm256Encrypter::class],
[Encryption::SodiumXChaCha20Poly1305->value, XChaCha20Poly1305Encrypter::class],
]);

0 comments on commit 53d912c

Please sign in to comment.