Skip to content
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
2 changes: 1 addition & 1 deletion packages/cryptography/src/Encryption/EncryptionKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(
}

if (strlen($value) !== $algorithm->getKeyLength()) {
throw EncryptionKeyWasInvalid::becauseLengthMismatched($algorithm);
throw EncryptionKeyWasInvalid::becauseLengthMismatched($algorithm, strlen($value));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ public function __construct(

public static function becauseItIsMissing(EncryptionAlgorithm $algorithm): self
{
return new self('The encryption key is missing or empty. Ensure you have a `SIGNING_KEY` environment variable.', $algorithm);
return new self(
message: 'The encryption key is missing or empty. Generate a valid `SIGNING_KEY` with `php tempest key:generate`.',
algorithm: $algorithm,
);
}

public static function becauseLengthMismatched(EncryptionAlgorithm $algorithm): self
public static function becauseLengthMismatched(EncryptionAlgorithm $algorithm, int $actualLength): self
{
return new self(
"The encryption key length does not match the expected length ({$algorithm->getKeyLength()}).",
$algorithm,
message: "The encryption key length ({$actualLength}) does not match the expected length ({$algorithm->getKeyLength()}). Generate a valid `SIGNING_KEY` with `php tempest key:generate`.",
algorithm: $algorithm,
);
}
}
6 changes: 5 additions & 1 deletion packages/cryptography/src/GenerateSigningKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public function __construct(
private Console $console,
) {}

#[ConsoleCommand('key:generate', description: 'Generates the signing key required to sign and verify data.')]
#[ConsoleCommand(
name: 'key:generate',
description: 'Generates the signing key required to sign and verify data.',
aliases: ['generate:key'],
)]
public function __invoke(bool $override = true): ExitCode
{
$key = EncryptionKey::generate($this->encryptionConfig->algorithm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ final class SigningKeyWasInvalid extends Exception implements SigningException
{
public static function becauseItIsMissing(): self
{
return new self('The signing key is missing or empty. Ensure you have a `SIGNING_KEY` environment variable.');
return new self('The signing key is missing or empty. Generate a valid `SIGNING_KEY` with `php tempest key:generate`.');
}
}