1 | <?php |
||
18 | class JWS implements JWT |
||
19 | { |
||
20 | /** |
||
21 | * @var bool |
||
22 | */ |
||
23 | private $isPayloadDetached = false; |
||
24 | |||
25 | /** |
||
26 | * @var string|null |
||
27 | */ |
||
28 | private $encodedPayload = null; |
||
29 | |||
30 | /** |
||
31 | * @var Signature[] |
||
32 | */ |
||
33 | private $signatures = []; |
||
34 | |||
35 | /** |
||
36 | * @var string|null |
||
37 | */ |
||
38 | private $payload = null; |
||
39 | |||
40 | /** |
||
41 | * JWS constructor. |
||
42 | * |
||
43 | * @param string|null $payload |
||
44 | * @param string|null $encodedPayload |
||
45 | * @param bool $isPayloadDetached |
||
46 | */ |
||
47 | private function __construct(?string $payload, ?string $encodedPayload = null, bool $isPayloadDetached = false) |
||
53 | |||
54 | /** |
||
55 | * Creates a JWS object. |
||
56 | * |
||
57 | * @param string|null $payload |
||
58 | * @param string|null $encodedPayload |
||
59 | * @param bool $isPayloadDetached |
||
60 | * |
||
61 | * @return JWS |
||
62 | */ |
||
63 | public static function create(?string $payload, ?string $encodedPayload = null, bool $isPayloadDetached = false): self |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function getPayload(): ?string |
||
75 | |||
76 | /** |
||
77 | * Returns true if the payload is detached. |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function isPayloadDetached(): bool |
||
85 | |||
86 | /** |
||
87 | * Returns the Base64Url encoded payload. |
||
88 | * If the payload is detached, this method returns null. |
||
89 | * |
||
90 | * @return string|null |
||
91 | */ |
||
92 | public function getEncodedPayload(): ?string |
||
100 | |||
101 | /** |
||
102 | * Returns the signatures associated with the JWS. |
||
103 | * |
||
104 | * @return Signature[] |
||
105 | */ |
||
106 | public function getSignatures(): array |
||
110 | |||
111 | /** |
||
112 | * Returns the signature at the given index. |
||
113 | * |
||
114 | * @param int $id |
||
115 | * |
||
116 | * @return Signature |
||
117 | */ |
||
118 | public function getSignature(int $id): Signature |
||
126 | |||
127 | /** |
||
128 | * This method adds a signature to the JWS object. |
||
129 | * Its returns a new JWS object. |
||
130 | * |
||
131 | * @internal |
||
132 | * |
||
133 | * @param string $signature |
||
134 | * @param array $protectedHeader |
||
135 | * @param string|null $encodedProtectedHeader |
||
136 | * @param array $header |
||
137 | * |
||
138 | * @return JWS |
||
139 | */ |
||
140 | public function addSignature(string $signature, array $protectedHeader, ?string $encodedProtectedHeader, array $header = []): self |
||
147 | |||
148 | /** |
||
149 | * Returns the number of signature associated with the JWS. |
||
150 | * |
||
151 | * @return int |
||
152 | */ |
||
153 | public function countSignatures(): int |
||
157 | |||
158 | /** |
||
159 | * This method splits the JWS into a list of JWSs. |
||
160 | * It is only useful when the JWS contains more than one signature (JSON General Serialization). |
||
161 | * |
||
162 | * @return JWS[] |
||
163 | */ |
||
164 | public function split(): array |
||
185 | } |
||
186 |