Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <nguyennv1981@gmail.com>
  • Loading branch information
nguyennv committed Nov 5, 2024
1 parent dbefd70 commit 18b6946
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/Enum/KeyAlgorithm.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,8 @@ public function forEncryption(): bool
public function keyVersion(): int
{
return match ($this) {
self::X25519,
self::X448,
self::Ed25519,
self::Ed448
=> KeyVersion::V6->value,
self::X25519, self::X448, self::Ed25519, self::Ed448 => KeyVersion
::V6->value,
default => Config::useV6Key()
? KeyVersion::V6->value
: KeyVersion::V4->value,
Expand Down
5 changes: 4 additions & 1 deletion src/Packet/PublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public function __construct(
? PacketTag::PublicSubkey
: PacketTag::PublicKey
);
if ($version !== KeyVersion::V4->value && $version !== KeyVersion::V6->value) {
if (
$version !== KeyVersion::V4->value &&
$version !== KeyVersion::V6->value
) {
throw new \InvalidArgumentException(
"Version {$version} of the key packet is unsupported."
);
Expand Down
14 changes: 11 additions & 3 deletions src/Packet/SecretSubkey.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public static function generate(
?DateTimeInterface $time = null
): self {
$keyMaterial = self::generateKeyMaterial(
$keyAlgorithm, $rsaKeySize, $curve
$keyAlgorithm,
$rsaKeySize,
$curve
);
return new self(
new PublicSubkey(
Expand All @@ -132,12 +134,18 @@ public function encrypt(
?AeadAlgorithm $aead = null
): self {
if ($this->isDecrypted()) {
[$encrypted, $iv, $s2k] = $this->encryptKeyMaterial($passphrase, $symmetric, $aead);
[$encrypted, $iv, $s2k] = $this->encryptKeyMaterial(
$passphrase,
$symmetric,
$aead
);
return new self(
$this->getPublicKey(),
$encrypted,
$this->getKeyMaterial(),
$aead instanceof AeadAlgorithm ? S2kUsage::AeadProtect : S2kUsage::Cfb,
$aead instanceof AeadAlgorithm
? S2kUsage::AeadProtect
: S2kUsage::Cfb,
$symmetric,
$s2k,
$aead,
Expand Down

0 comments on commit 18b6946

Please sign in to comment.