3
3
namespace YandexCloud \Ydb \Jwt \Signer ;
4
4
5
5
use Lcobucci \JWT \Signer \Key as SignerKey ;
6
- use Lcobucci \JWT \Signer \Rsa as SignerRsa ;
6
+ use Lcobucci \JWT \Signer \OpenSSL ;
7
7
8
8
use phpseclib \Crypt \RSA as LegacyRSA ;
9
9
use phpseclib3 \Crypt \RSA ;
10
10
use phpseclib3 \Crypt \PublicKeyLoader ;
11
11
12
- class Sha256 extends SignerRsa
12
+ class Sha256 extends OpenSSL
13
13
{
14
14
/**
15
15
* @param string $payload
16
16
* @param SignerKey $key
17
17
* @return string
18
18
*/
19
- public function createHash ( $ payload , SignerKey $ key )
19
+ final public function sign ( string $ payload , SignerKey $ key ): string
20
20
{
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 ();
22
51
23
52
if (class_exists (LegacyRSA::class))
24
53
{
@@ -42,15 +71,15 @@ public function createHash($payload, SignerKey $key)
42
71
/**
43
72
* @return string
44
73
*/
45
- public function getAlgorithmId ()
74
+ public function algorithmId (): string
46
75
{
47
76
return 'PS256 ' ;
48
77
}
49
78
50
79
/**
51
80
* @return int
52
81
*/
53
- public function getAlgorithm ()
82
+ public function algorithm (): int
54
83
{
55
84
return OPENSSL_ALGO_SHA256 ;
56
85
}
0 commit comments