| Conditions | 5 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | function jose_secret_key(string $secret, ?string $alg = null): JWK |
||
| 11 | { |
||
| 12 | 16 | if (null !== $alg && (bool) preg_match('/^A(\d{3})(?:GCM)?KW$/', $alg, $matches)) { |
|
| 13 | 6 | return derived_key($secret, (int) $matches[1]); |
|
| 14 | } |
||
| 15 | |||
| 16 | 10 | if (null !== $alg && (bool) preg_match('/^A(\d{3})(?:GCM|CBC-HS(\d{3}))$/', $alg, $matches)) { |
|
| 17 | 6 | return derived_key($secret, (int) ($matches[2] ?? $matches[1])); |
|
| 18 | } |
||
| 19 | |||
| 20 | 4 | $key = new JWK([ |
|
| 21 | 4 | 'k' => base64url_encode($secret), |
|
| 22 | 4 | 'kty' => 'oct', |
|
| 23 | ]); |
||
| 24 | |||
| 25 | 4 | return $key; |
|
| 26 | } |
||
| 27 |