]> git.mxchange.org Git - friendica.git/blob - src/Security/OAuth1/Signature/OAuthSignatureMethod.php
Changed to null-coalscing style (??) as sugguested by @MrPetovan
[friendica.git] / src / Security / OAuth1 / Signature / OAuthSignatureMethod.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Security\OAuth1\Signature;
23
24 use Friendica\Security\OAuth1\OAuthRequest;
25
26 /**
27  * A class for implementing a Signature Method
28  * See section 9 ("Signing Requests") in the spec
29  */
30 abstract class OAuthSignatureMethod
31 {
32         /**
33          * Needs to return the name of the Signature Method (ie HMAC-SHA1)
34          *
35          * @return string
36          */
37         abstract public function get_name();
38
39         /**
40          * Build up the signature
41          * NOTE: The output of this function MUST NOT be urlencoded.
42          * the encoding is handled in OAuthRequest when the final
43          * request is serialized
44          *
45          * @param OAuthRequest                             $request
46          * @param \Friendica\Security\OAuth1\OAuthConsumer $consumer
47          * @param \Friendica\Security\OAuth1\OAuthToken    $token
48          *
49          * @return string
50          */
51         abstract public function build_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, \Friendica\Security\OAuth1\OAuthToken $token = null);
52
53         /**
54          * Verifies that a given signature is correct
55          *
56          * @param OAuthRequest                             $request
57          * @param \Friendica\Security\OAuth1\OAuthConsumer $consumer
58          * @param \Friendica\Security\OAuth1\OAuthToken    $token
59          * @param string                                   $signature
60          *
61          * @return bool
62          */
63         public function check_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, $signature, \Friendica\Security\OAuth1\OAuthToken $token = null)
64         {
65                 $built = $this->build_signature($request, $consumer, $token);
66                 return ($built == $signature);
67         }
68 }