Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AwsCredential
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/http-message.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/http-message
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Http\Message\Header\Authorization;
20
21use SensitiveParameter;
22
23/**
24 * Class AwsCredential.
25 *
26 * Represents the structured credential for AWS Signature Version 4
27 * authentication. This credential is extracted from an `Authorization`
28 * header beginning with the scheme `AWS4-HMAC-SHA256`.
29 *
30 * AWS Signature Version 4 requires an HMAC-based signing process in which the
31 * client computes a derived signing key using its AWS secret access key,
32 * the request date, region, service name, and a fixed terminator string
33 * (`aws4_request`). The client then signs a canonical representation of the
34 * HTTP request. The server reconstructs this process and validates the
35 * signature to authenticate the request.
36 *
37 * Implementations using this class MUST treat all contained values as
38 * immutable authentication parameters. These values MUST NOT be modified
39 * internally, and callers SHOULD validate them strictly according to AWS
40 * signing rules. The `signature` value MUST be treated as opaque binary
41 * content encoded in hexadecimal; possession of a valid signature MAY allow
42 * unauthorized access if mishandled.
43 *
44 * Each property corresponds directly to fields parsed from the
45 * `Authorization` header:
46 *
47 * - **algorithm**: The signing algorithm identifier. For SigV4 this MUST be
48 *   `"AWS4-HMAC-SHA256"`.
49 * - **credentialScope**: The hierarchical credential scope string in the form:
50 *   `AccessKeyId/Date/Region/Service/aws4_request`.
51 * - **signedHeaders**: A semicolon-delimited list of header names included
52 *   during canonicalization. The server MUST reconstruct these headers in
53 *   exactly the same order for signature verification.
54 * - **signature**: A 64-character hexadecimal string representing the
55 *   computed request signature.
56 */
57final readonly class AwsCredential implements AuthorizationCredential
58{
59    /**
60     * Creates a representation of the SigV4 credential parameters extracted
61     * from an Authorization header.
62     *
63     * All values passed to this constructor MUST come directly from the parsed
64     * header and MUST NOT be transformed semantically. Any additional
65     * normalization required for validation (e.g., canonical header
66     * reconstruction) MUST be performed by the caller or authentication
67     * subsystem.
68     *
69     * @param string $algorithm the SigV4 signing algorithm identifier
70     * @param string $credentialScope the credential scope string
71     *                                (`AccessKeyId/Date/Region/Service/aws4_request`)
72     * @param string $signedHeaders a semicolon-separated list of signed headers
73     * @param string $signature a 64-character hex-encoded signature
74     */
75    public function __construct(
76        public string $algorithm,
77        #[SensitiveParameter]
78        public string $credentialScope,
79        public string $signedHeaders,
80        #[SensitiveParameter]
81        public string $signature,
82    ) {}
83}