@@ -16,37 +16,24 @@ public function __construct(
1616 $ this ->setMethod (strtoupper ($ method ));
1717 }
1818
19- public function buildVerificationSignature (SignatureConfig $ signatureConfig ): string
19+ public function buildSignature (SignatureConfig $ signatureConfig, bool $ forVerification = false ): string
2020 {
2121 $ payload = [
2222 $ this ->method ,
2323 $ this ->host ,
2424 $ this ->pathInfo ,
25- $ this ->content ,
25+ rawurldecode ( $ this ->content ) ,
2626 ];
2727
28- if ($ signatureConfig ->isReplayProtectionEnabled ()) {
29- $ this ->guardValidSignatureTime ();
30- // use unshift to keep BC on signature generation
31- array_unshift ($ payload , $ this ->signatureTime );
28+ if ($ forVerification ) {
29+ $ payload = [
30+ $ this ->method ,
31+ $ this ->host ,
32+ $ this ->pathInfo ,
33+ $ this ->content ,
34+ ];
3235 }
3336
34- return hash_hmac (
35- $ signatureConfig ->getAlgorithm (),
36- implode ("\n" , $ payload ),
37- $ signatureConfig ->getSecret (),
38- );
39- }
40-
41- public function buildSignature (SignatureConfig $ signatureConfig ): string
42- {
43- $ payload = [
44- $ this ->method ,
45- $ this ->host ,
46- $ this ->pathInfo ,
47- rawurldecode ($ this ->content ),
48- ];
49-
5037 if ($ signatureConfig ->isReplayProtectionEnabled ()) {
5138 $ this ->guardValidSignatureTime ();
5239 // use unshift to keep BC on signature generation
@@ -62,7 +49,7 @@ public function buildSignature(SignatureConfig $signatureConfig): string
6249
6350 public function authenticateSignature (string $ signature , SignatureConfig $ signatureConfig , ReplayProtection $ replayProtection ): bool
6451 {
65- if ($ signature !== $ this ->buildVerificationSignature ($ signatureConfig )) {
52+ if ($ signature !== $ this ->buildSignature ($ signatureConfig, true )) {
6653 throw new InvalidSignatureException ();
6754 }
6855
0 commit comments