33namespace YandexCloud \Ydb \Jwt \Signer ;
44
55use Lcobucci \JWT \Signer \Key as SignerKey ;
6- use Lcobucci \JWT \Signer \Rsa as SignerRsa ;
6+ use Lcobucci \JWT \Signer \OpenSSL ;
77
88use phpseclib \Crypt \RSA as LegacyRSA ;
99use phpseclib3 \Crypt \RSA ;
1010use phpseclib3 \Crypt \PublicKeyLoader ;
1111
12- class Sha256 extends SignerRsa
12+ class Sha256 extends OpenSSL
1313{
1414 /**
1515 * @param string $payload
1616 * @param SignerKey $key
1717 * @return string
1818 */
19- public function createHash ( $ payload , SignerKey $ key )
19+ final public function sign ( string $ payload , SignerKey $ key ): string
2020 {
21- $ keyContent = $ key ->getContent ();
21+ return $ this ->createHash ($ payload , $ key );
22+ }
23+
24+ /**
25+ * @param string $expected
26+ * @param string $payload
27+ * @param SignerKey $key
28+ * @return bool
29+ */
30+ final public function verify (string $ expected , string $ payload , SignerKey $ key ): bool
31+ {
32+ return $ this ->verifySignature ($ expected , $ payload , $ key ->contents ());
33+ }
34+
35+ /**
36+ * @return int
37+ */
38+ final public function keyType (): int
39+ {
40+ return OPENSSL_KEYTYPE_RSA ;
41+ }
42+
43+ /**
44+ * @param string $payload
45+ * @param SignerKey $key
46+ * @return string
47+ */
48+ public function createHash ($ payload , SignerKey $ key ): string
49+ {
50+ $ keyContent = $ key ->contents ();
2251
2352 if (class_exists (LegacyRSA::class))
2453 {
@@ -42,15 +71,15 @@ public function createHash($payload, SignerKey $key)
4271 /**
4372 * @return string
4473 */
45- public function getAlgorithmId ()
74+ public function algorithmId (): string
4675 {
4776 return 'PS256 ' ;
4877 }
4978
5079 /**
5180 * @return int
5281 */
53- public function getAlgorithm ()
82+ public function algorithm (): int
5483 {
5584 return OPENSSL_ALGO_SHA256 ;
5685 }
0 commit comments