a1def56cdd92ca50a3f9fb1792fe246275997e70
[friendica-addons.git/.git] / s3_storage / vendor / akeeba / s3 / src / Signature.php
1 <?php
2 /**
3  * Akeeba Engine
4  *
5  * @package   akeebaengine
6  * @copyright Copyright (c)2006-2024 Nicholas K. Dionysopoulos / Akeeba Ltd
7  * @license   GNU General Public License version 3, or later
8  */
9
10 namespace Akeeba\S3;
11
12 // Protection against direct access
13 defined('AKEEBAENGINE') || die();
14
15 /**
16  * Base class for request signing objects.
17  */
18 abstract class Signature
19 {
20         /**
21          * The request we will be signing
22          *
23          * @var  Request
24          */
25         protected $request = null;
26
27         /**
28          * Signature constructor.
29          *
30          * @param   Request  $request  The request we will be signing
31          */
32         public function __construct(Request $request)
33         {
34                 $this->request = $request;
35         }
36
37         /**
38          * Get a signature object for the request
39          *
40          * @param   Request  $request  The request which needs signing
41          * @param   string   $method   The signature method, "v2" or "v4"
42          *
43          * @return  Signature
44          */
45         public static function getSignatureObject(Request $request, string $method = 'v2'): self
46         {
47                 $className = __NAMESPACE__ . '\\Signature\\' . ucfirst($method);
48
49                 return new $className($request);
50         }
51
52         /**
53          * Returns the authorization header for the request
54          *
55          * @return  string
56          */
57         abstract public function getAuthorizationHeader(): string;
58
59         /**
60          * Pre-process the request headers before we convert them to cURL-compatible format. Used by signature engines to
61          * add custom headers, e.g. x-amz-content-sha256
62          *
63          * @param   array  $headers     The associative array of headers to process
64          * @param   array  $amzHeaders  The associative array of amz-* headers to process
65          *
66          * @return  void
67          */
68         abstract public function preProcessHeaders(array &$headers, array &$amzHeaders): void;
69
70         /**
71          * Get a pre-signed URL for the request. Typically used to pre-sign GET requests to objects, i.e. give shareable
72          * pre-authorized URLs for downloading files from S3.
73          *
74          * @param   integer|null  $lifetime  Lifetime in seconds. NULL for default lifetime.
75          * @param   bool          $https     Use HTTPS ($hostBucket should be false for SSL verification)?
76          *
77          * @return  string  The authenticated URL, complete with signature
78          */
79         abstract public function getAuthenticatedURL(?int $lifetime = null, bool $https = false): string;
80 }