Skip to content

Commit 4679f2b

Browse files
chore: keys
Signed-off-by: Dusan Malusev <[email protected]>
1 parent 3179ddb commit 4679f2b

17 files changed

+62
-89
lines changed

src/Console/GenerateCryptoKeysCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace CodeLieutenant\LaravelCrypto\Console;
66

77
use CodeLieutenant\LaravelCrypto\Keys\Generators\AppKeyGenerator;
8-
use CodeLieutenant\LaravelCrypto\Keys\Generators\Blake2bHashingKeyGenerator;
8+
use CodeLieutenant\LaravelCrypto\Keys\Generators\Blake2BHashingKeyGenerator;
99
use CodeLieutenant\LaravelCrypto\Keys\Generators\EdDSASignerKeyGenerator;
1010
use CodeLieutenant\LaravelCrypto\Keys\Generators\HmacKeyGenerator;
1111
use Exception;
@@ -31,7 +31,7 @@ class GenerateCryptoKeysCommand extends Command
3131
public function handle(
3232
EdDSASignerKeyGenerator $edDSAGenerator,
3333
AppKeyGenerator $appKeyGenerator,
34-
Blake2bHashingKeyGenerator $blake2bKeyGenerator,
34+
Blake2BHashingKeyGenerator $blake2bKeyGenerator,
3535
HmacKeyGenerator $hmacKeyGenerator,
3636
): int {
3737
$show = $this->option('show');

src/Contracts/KeyGeneration.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Keys/Generators/Generator.php renamed to src/Contracts/KeyGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
declare(strict_types=1);
44

5-
namespace CodeLieutenant\LaravelCrypto\Keys\Generators;
5+
namespace CodeLieutenant\LaravelCrypto\Contracts;
66

7-
interface Generator
7+
interface KeyGenerator
88
{
99
public function generate(?string $write): ?string;
1010
}

src/Encryption/AesGcm256Encrypter.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace CodeLieutenant\LaravelCrypto\Encryption;
66

77
use CodeLieutenant\LaravelCrypto\Contracts\Encoder;
8-
use CodeLieutenant\LaravelCrypto\Contracts\KeyGeneration;
98
use CodeLieutenant\LaravelCrypto\Contracts\KeyLoader;
109
use CodeLieutenant\LaravelCrypto\Encoder\JsonEncoder;
1110
use CodeLieutenant\LaravelCrypto\Support\Base64;
@@ -17,7 +16,7 @@
1716
use Illuminate\Contracts\Encryption\StringEncrypter;
1817
use Psr\Log\LoggerInterface;
1918

20-
final class AesGcm256Encrypter implements Encrypter, KeyGeneration, StringEncrypter
19+
final class AesGcm256Encrypter implements Encrypter, StringEncrypter
2120
{
2221
use Crypto;
2322

@@ -70,11 +69,6 @@ public function decrypt($payload, $unserialize = true)
7069
};
7170
}
7271

73-
public static function generateKey(string $cipher): string
74-
{
75-
return sodium_crypto_aead_aes256gcm_keygen();
76-
}
77-
7872
public static function nonceSize(): int
7973
{
8074
return SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES;

src/Encryption/XChaCha20Poly1305Encrypter.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace CodeLieutenant\LaravelCrypto\Encryption;
66

77
use CodeLieutenant\LaravelCrypto\Contracts\Encoder;
8-
use CodeLieutenant\LaravelCrypto\Contracts\KeyGeneration;
98
use CodeLieutenant\LaravelCrypto\Contracts\KeyLoader;
109
use CodeLieutenant\LaravelCrypto\Encoder\JsonEncoder;
1110
use CodeLieutenant\LaravelCrypto\Support\Base64;
@@ -17,7 +16,7 @@
1716
use Illuminate\Contracts\Encryption\StringEncrypter;
1817
use Psr\Log\LoggerInterface;
1918

20-
final class XChaCha20Poly1305Encrypter implements Encrypter, KeyGeneration, StringEncrypter
19+
final class XChaCha20Poly1305Encrypter implements Encrypter, StringEncrypter
2120
{
2221
use Crypto;
2322

@@ -81,11 +80,6 @@ public function decrypt($payload, $unserialize = true)
8180
return $decrypted;
8281
}
8382

84-
public static function generateKey(string $_): string
85-
{
86-
return sodium_crypto_aead_xchacha20poly1305_ietf_keygen();
87-
}
88-
8983
public static function nonceSize(): int
9084
{
9185
return SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES;

src/Keys/Blake2bHashingKey.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Keys/Generators/AppKeyGenerator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
namespace CodeLieutenant\LaravelCrypto\Keys\Generators;
66

7+
use CodeLieutenant\LaravelCrypto\Contracts\KeyGenerator;
78
use CodeLieutenant\LaravelCrypto\Encryption\AesGcm256Encrypter;
89
use CodeLieutenant\LaravelCrypto\Encryption\XChaCha20Poly1305Encrypter;
910
use CodeLieutenant\LaravelCrypto\Enums\Encryption;
1011
use CodeLieutenant\LaravelCrypto\Traits\EnvKeySaver;
1112
use Illuminate\Contracts\Config\Repository;
1213
use Illuminate\Encryption\Encrypter;
1314

14-
class AppKeyGenerator implements Generator
15+
class AppKeyGenerator implements KeyGenerator
1516
{
1617
use EnvKeySaver;
1718

@@ -31,8 +32,8 @@ public function generate(?string $write): ?string
3132

3233
$new = $this->formatKey(
3334
match (Encryption::tryFrom($cipher)) {
34-
Encryption::SodiumAES256GCM => AesGcm256Encrypter::generateKey($cipher),
35-
Encryption::SodiumXChaCha20Poly1305 => XChaCha20Poly1305Encrypter::generateKey($cipher),
35+
Encryption::SodiumAES256GCM => sodium_crypto_aead_aes256gcm_keygen(),
36+
Encryption::SodiumXChaCha20Poly1305 => sodium_crypto_aead_xchacha20poly1305_ietf_keygen(),
3637
default => Encrypter::generateKey($cipher),
3738
}
3839
);

src/Keys/Generators/Blake2bHashingKeyGenerator.php renamed to src/Keys/Generators/Blake2BHashingKeyGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
namespace CodeLieutenant\LaravelCrypto\Keys\Generators;
66

7+
use CodeLieutenant\LaravelCrypto\Contracts\KeyGenerator;
78
use CodeLieutenant\LaravelCrypto\Support\Random;
89
use CodeLieutenant\LaravelCrypto\Traits\EnvKeySaver;
910
use Illuminate\Contracts\Config\Repository;
1011

11-
class Blake2bHashingKeyGenerator implements Generator
12+
class Blake2BHashingKeyGenerator implements KeyGenerator
1213
{
1314
use EnvKeySaver;
1415

src/Keys/Generators/EdDSASignerKeyGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace CodeLieutenant\LaravelCrypto\Keys\Generators;
66

7+
use CodeLieutenant\LaravelCrypto\Contracts\KeyGenerator;
78
use Illuminate\Contracts\Config\Repository;
89
use Psr\Log\LoggerInterface;
910
use RuntimeException;
1011
use SplFileObject;
1112

12-
class EdDSASignerKeyGenerator implements Generator
13+
class EdDSASignerKeyGenerator implements KeyGenerator
1314
{
1415
private const CONFIG_KEY_PATH = 'crypto.signing.keys.eddsa';
1516

src/Keys/Generators/HmacKeyGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace CodeLieutenant\LaravelCrypto\Keys\Generators;
66

7-
class HmacKeyGenerator extends Blake2bHashingKeyGenerator
7+
class HmacKeyGenerator extends Blake2BHashingKeyGenerator
88
{
99
public const ENV = 'CRYPTO_HMAC_KEY';
1010
public const CONFIG_KEY_PATH = 'crypto.signing.keys.hmac';

0 commit comments

Comments
 (0)