Skip to content

Commit

Permalink
Fix ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Jan 7, 2024
1 parent 0eece81 commit 10727f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/Component/Encryption/JWEBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ private function determineCEK(array &$additionalHeader): string
}

switch ($this->keyManagementMode) {
case KeyEncryption::MODE_ENCRYPT :
case KeyEncryption::MODE_WRAP :
case KeyEncryption::MODE_ENCRYPT:
case KeyEncryption::MODE_WRAP:
return $this->createCEK($this->contentEncryptionAlgorithm->getCEKSize());

case KeyEncryption::MODE_AGREEMENT :
case KeyEncryption::MODE_AGREEMENT:
if (count($this->recipients) !== 1) {
throw new LogicException(
'Unable to encrypt for multiple recipients using key agreement algorithms.'
Expand All @@ -465,7 +465,7 @@ private function determineCEK(array &$additionalHeader): string
$additionalHeader
);

case KeyEncryption::MODE_DIRECT :
case KeyEncryption::MODE_DIRECT:
if (count($this->recipients) !== 1) {
throw new LogicException(
'Unable to encrypt for multiple recipients using key agreement algorithms.'
Expand All @@ -483,7 +483,7 @@ private function determineCEK(array &$additionalHeader): string

return Base64UrlSafe::decodeNoPadding($k);

default :
default:
throw new InvalidArgumentException(sprintf(
'Unsupported key management mode "%s".',
$this->keyManagementMode
Expand Down
36 changes: 18 additions & 18 deletions src/EncryptionAlgorithm/KeyEncryption/ECDHES/AbstractECDH.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
throw new InvalidArgumentException('Invalid key parameter "crv"');
}
switch ($crv) {
case 'P-256' :
case 'P-384' :
case 'P-521' :
case 'P-256':
case 'P-384':
case 'P-521':
$curve = $this->getCurve($crv);
if (function_exists('openssl_pkey_derive')) {
try {
Expand Down Expand Up @@ -120,7 +120,7 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str

return $this->convertDecToBin(EcDH::computeSharedKey($curve, $pub_key, $priv_key));

case 'X25519' :
case 'X25519':
$x = $public_key->get('x');
if (! is_string($x)) {
throw new InvalidArgumentException('Invalid key parameter "x"');
Expand All @@ -134,7 +134,7 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str

return sodium_crypto_scalarmult($sKey, $recipientPublickey);

default :
default:
throw new InvalidArgumentException(sprintf('The curve "%s" is not supported', $crv));
}
}
Expand All @@ -156,20 +156,20 @@ protected function getKeysFromPublicKey(
throw new InvalidArgumentException('Invalid key parameter "crv"');
}
switch ($crv) {
case 'P-256' :
case 'P-384' :
case 'P-521' :
case 'P-256':
case 'P-384':
case 'P-521':
$private_key = $senderKey ?? ECKey::createECKey($crv);

break;

case 'X25519' :
case 'X25519':
$this->checkSodiumExtensionIsAvailable();
$private_key = $senderKey ?? $this->createOKPKey('X25519');

break;

default :
default:
throw new InvalidArgumentException(sprintf('The curve "%s" is not supported', $crv));
}
$epk = $private_key->toPublic()
Expand Down Expand Up @@ -228,19 +228,19 @@ private function checkKey(JWK $key, bool $is_private): void
throw new InvalidArgumentException('Invalid key parameter "crv"');
}
switch ($crv) {
case 'P-256' :
case 'P-384' :
case 'P-521' :
case 'P-256':
case 'P-384':
case 'P-521':
if (! $key->has('y')) {
throw new InvalidArgumentException('The key parameter "y" is missing.');
}

break;

case 'X25519' :
case 'X25519':
break;

default :
default:
throw new InvalidArgumentException(sprintf('The curve "%s" is not supported', $crv));
}
if ($is_private === true && ! $key->has('d')) {
Expand Down Expand Up @@ -295,14 +295,14 @@ private function createOKPKey(string $curve): JWK
$this->checkSodiumExtensionIsAvailable();

switch ($curve) {
case 'X25519' :
case 'X25519':
$keyPair = sodium_crypto_box_keypair();
$d = sodium_crypto_box_secretkey($keyPair);
$x = sodium_crypto_box_publickey($keyPair);

break;

case 'Ed25519' :
case 'Ed25519':
$keyPair = sodium_crypto_sign_keypair();
$secret = sodium_crypto_sign_secretkey($keyPair);
$secretLength = mb_strlen($secret, '8bit');
Expand All @@ -311,7 +311,7 @@ private function createOKPKey(string $curve): JWK

break;

default :
default:
throw new InvalidArgumentException(sprintf('Unsupported "%s" curve', $curve));
}

Expand Down

0 comments on commit 10727f1

Please sign in to comment.