Skip to content

Commit 36bf60a

Browse files
authored
Revert "Remove extra \0 byte if present (#476)" (#477)
This reverts commit 4ab8741.
1 parent 4ab8741 commit 36bf60a

File tree

2 files changed

+2
-30
lines changed

2 files changed

+2
-30
lines changed

src/Component/Core/Util/ECKey.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,9 @@ private static function getKey(JWK $jwk): string
317317
if (! is_string($y)) {
318318
throw new InvalidArgumentException('Unable to get the public key');
319319
}
320-
$binX = ltrim(Base64UrlSafe::decode($x), "\0");
321-
$binY = ltrim(Base64UrlSafe::decode($y), "\0");
322320

323321
return "\04"
324-
. str_pad($binX, $length, "\0", STR_PAD_LEFT)
325-
. str_pad($binY, $length, "\0", STR_PAD_LEFT)
326-
;
322+
. str_pad(Base64UrlSafe::decode($x), $length, "\0", STR_PAD_LEFT)
323+
. str_pad(Base64UrlSafe::decode($y), $length, "\0", STR_PAD_LEFT);
327324
}
328325
}

tests/Component/Core/JWKTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use InvalidArgumentException;
88
use Jose\Component\Core\JWK;
9-
use Jose\Component\Core\Util\ECKey;
109
use const JSON_THROW_ON_ERROR;
1110
use PHPUnit\Framework\Attributes\Test;
1211
use PHPUnit\Framework\TestCase;
@@ -128,28 +127,4 @@ public function iCanConvertAPrivateKeyIntoPublicKey(): void
128127
'kid' => '9876543210',
129128
]), json_encode($public, JSON_THROW_ON_ERROR));
130129
}
131-
132-
/**
133-
* @test
134-
* @see https://github.com/web-token/jwt-framework/issues/475
135-
*/
136-
public static function convertToPEM(): void
137-
{
138-
// Given
139-
$key = '{"kty":"EC","crv":"P-256","x":"GDDdmNtwNvlXN04SEUp20BZJ9im6SQqkP8u4d8G6RAk","y":"AIAxkBwTTqbCcNbqbpk8l_Eh-4KtpgyyHkNJ6K4jnvOv","use":"sig","alg":"ES256","kid":"ayRrlw","key_ops":["verify"]}';
140-
$jwk = JWK::createFromJson($key);
141-
$expectedPEM = <<<'PEM'
142-
-----BEGIN PUBLIC KEY-----
143-
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGDDdmNtwNvlXN04SEUp20BZJ9im6
144-
SQqkP8u4d8G6RAmAMZAcE06mwnDW6m6ZPJfxIfuCraYMsh5DSeiuI57zrw==
145-
-----END PUBLIC KEY-----
146-
147-
PEM;
148-
149-
//When
150-
$pem = ECKey::convertToPEM($jwk);
151-
152-
//Then
153-
static::assertSame($expectedPEM, $pem);
154-
}
155130
}

0 commit comments

Comments
 (0)