S3SignatureV4
extends SignatureV4
in package
implements
S3SignatureInterface
Amazon S3 signature version 4 overrides.
Table of Contents
Interfaces
- S3SignatureInterface
- Interface used to provide interchangeable strategies for signing requests using the various AWS signature protocols.
Constants
- DEFAULT_PAYLOAD = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
Properties
- $cacheSize : int
- $hashCache : array<string|int, mixed>
- $maxCacheSize : int
- $regionName : string
- $serviceName : string
Methods
- __construct() : mixed
- convertPostToGet() : RequestInterface
- Converts a POST request to a GET request by moving POST fields into the query string.
- createPresignedUrl() : string
- Create a pre-signed URL
- setMaxCacheSize() : self
- Set the maximum number of computed hashes to cache
- setRegionName() : self
- Set the region name instead of inferring it from a request URL
- setServiceName() : self
- Set the service name instead of inferring it from a request URL
- signRequest() : mixed
- Always add a x-amz-content-sha-256 for data integrity.
- createCanonicalizedPath() : mixed
- Amazon S3 does not double-encode the path component in the canonical req
- getPayload() : string
- Get the payload part of a signature from a request.
- getPresignedPayload() : string
- Override used to allow pre-signed URLs to be created for an in-determinate request payload.
- getTimestamp() : int
- Provides the timestamp used for the class (used for mocking PHP's time() function)
- addQueryValues() : mixed
- convertExpires() : mixed
- createPresignedRequest() : mixed
- createScope() : mixed
- createSigningContext() : array<string|int, mixed>
- Create the canonical representation of a request
- createStringToSign() : mixed
- getCanonicalizedQueryString() : string
- Get the canonicalized query string for a request
- getSigningKey() : string
- Get a hash for a specific key and value. If the hash was previously cached, return it
- moveHeadersToQuery() : mixed
Constants
DEFAULT_PAYLOAD
public
string
DEFAULT_PAYLOAD
= 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
Cache of the default empty entity-body payload
Properties
$cacheSize
protected
int
$cacheSize
= 0
Size of the hash cache
$hashCache
protected
array<string|int, mixed>
$hashCache
= array()
Cache of previously signed values
$maxCacheSize
protected
int
$maxCacheSize
= 50
Maximum number of hashes to cache
$regionName
protected
string
$regionName
Explicitly set region name
$serviceName
protected
string
$serviceName
Explicitly set service name
Methods
__construct()
public
__construct([string $serviceName = null ][, string $regionName = null ]) : mixed
Parameters
- $serviceName : string = null
-
Bind the signing to a particular service name
- $regionName : string = null
-
Bind the signing to a particular region name
convertPostToGet()
Converts a POST request to a GET request by moving POST fields into the query string.
public
static convertPostToGet(EntityEnclosingRequestInterface $request) : RequestInterface
Useful for pre-signing query protocol requests.
Parameters
- $request : EntityEnclosingRequestInterface
-
Request to clone
Tags
Return values
RequestInterfacecreatePresignedUrl()
Create a pre-signed URL
public
createPresignedUrl(RequestInterface $request, CredentialsInterface $credentials, mixed $expires) : string
Parameters
- $request : RequestInterface
-
Request to sign
- $credentials : CredentialsInterface
-
Credentials used to sign
- $expires : mixed
-
The time at which the URL should expire. This can be a Unix timestamp, a PHP DateTime object, or a string that can be evaluated by strtotime
Return values
stringsetMaxCacheSize()
Set the maximum number of computed hashes to cache
public
setMaxCacheSize(int $maxCacheSize) : self
Parameters
- $maxCacheSize : int
-
Maximum number of hashes to cache
Return values
selfsetRegionName()
Set the region name instead of inferring it from a request URL
public
setRegionName(string $region) : self
Parameters
- $region : string
-
Name of the region used when signing
Return values
selfsetServiceName()
Set the service name instead of inferring it from a request URL
public
setServiceName(string $service) : self
Parameters
- $service : string
-
Name of the service used when signing
Return values
selfsignRequest()
Always add a x-amz-content-sha-256 for data integrity.
public
signRequest(RequestInterface $request, CredentialsInterface $credentials) : mixed
Parameters
- $request : RequestInterface
-
Request to add a signature to
- $credentials : CredentialsInterface
-
Signing credentials
createCanonicalizedPath()
Amazon S3 does not double-encode the path component in the canonical req
protected
createCanonicalizedPath(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface
getPayload()
Get the payload part of a signature from a request.
protected
getPayload(RequestInterface $request) : string
Parameters
- $request : RequestInterface
Return values
stringgetPresignedPayload()
Override used to allow pre-signed URLs to be created for an in-determinate request payload.
protected
getPresignedPayload(RequestInterface $request) : string
Parameters
- $request : RequestInterface
Return values
stringgetTimestamp()
Provides the timestamp used for the class (used for mocking PHP's time() function)
protected
getTimestamp() : int
Return values
intaddQueryValues()
private
addQueryValues(mixed $scope, RequestInterface $request, CredentialsInterface $credentials, mixed $expires) : mixed
Parameters
- $scope : mixed
- $request : RequestInterface
- $credentials : CredentialsInterface
- $expires : mixed
convertExpires()
private
convertExpires(mixed $expires) : mixed
Parameters
- $expires : mixed
createPresignedRequest()
private
createPresignedRequest(RequestInterface $request, CredentialsInterface $credentials) : mixed
Parameters
- $request : RequestInterface
- $credentials : CredentialsInterface
createScope()
private
createScope(mixed $shortDate, mixed $region, mixed $service) : mixed
Parameters
- $shortDate : mixed
- $region : mixed
- $service : mixed
createSigningContext()
Create the canonical representation of a request
private
createSigningContext(RequestInterface $request, string $payload) : array<string|int, mixed>
Parameters
- $request : RequestInterface
-
Request to canonicalize
- $payload : string
-
Request payload (typically the value of the x-amz-content-sha256 header.
Return values
array<string|int, mixed> —Returns an array of context information including:
- canonical_request
- signed_headers
createStringToSign()
private
createStringToSign(mixed $longDate, mixed $credentialScope, mixed $creq) : mixed
Parameters
- $longDate : mixed
- $credentialScope : mixed
- $creq : mixed
getCanonicalizedQueryString()
Get the canonicalized query string for a request
private
getCanonicalizedQueryString(RequestInterface $request) : string
Parameters
- $request : RequestInterface
Return values
stringgetSigningKey()
Get a hash for a specific key and value. If the hash was previously cached, return it
private
getSigningKey(string $shortDate, string $region, string $service, string $secretKey) : string
Parameters
- $shortDate : string
-
Short date
- $region : string
-
Region name
- $service : string
-
Service name
- $secretKey : string
-
Secret Access Key
Return values
stringmoveHeadersToQuery()
private
moveHeadersToQuery(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface