@@ -57,15 +57,10 @@ func (rv *RequestValidator) ValidateBody(url string, body []byte, expectedSignat
5757 return false
5858 }
5959
60- if parsed .Query ().Has ("bodySHA256" ) {
61- bodySHA256 := parsed .Query ().Get ("bodySHA256" )
62- if len (bodySHA256 ) == 0 {
63- return false
64- }
65- return rv .Validate (url , map [string ]string {}, expectedSignature ) &&
66- rv .validateBody (body , bodySHA256 )
67- } else {
68- // For x-www-form-urlencoded Request body
60+ bodySHA256 := parsed .Query ().Get ("bodySHA256" )
61+
62+ // For x-www-form-urlencoded Request body
63+ if len (bodySHA256 ) == 0 {
6964 parsedBody , err := urllib .ParseQuery (string (body ))
7065 if err != nil {
7166 return false
@@ -77,17 +72,16 @@ func (rv *RequestValidator) ValidateBody(url string, body []byte, expectedSignat
7772 }
7873 return rv .Validate (url , params , expectedSignature )
7974 }
75+
76+ return rv .Validate (url , map [string ]string {}, expectedSignature ) &&
77+ rv .validateBody (body , bodySHA256 )
8078}
8179
8280func compare (x , y string ) bool {
8381 return subtle .ConstantTimeCompare ([]byte (x ), []byte (y )) == 1
8482}
8583
8684func (rv * RequestValidator ) validateBody (body []byte , expectedSHA string ) bool {
87- if len (expectedSHA ) == 0 {
88- return true
89- }
90-
9185 hasher := sha256 .New ()
9286 _ , err := hasher .Write (body )
9387 if err != nil {
0 commit comments