Debian Codegraph @

lib/3rdParty/composer/web-auth/cose-lib/src/Key/SymmetricKey.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Cose\Key;
6
7 use InvalidArgumentException;
8
9 /**
10 * @final
11 */
12 class SymmetricKey extends Key
13 {
14 final public const DATA_K = -1;
15
16 /**
17 * @param array<int|string, mixed> $data
18 */
19 public function __construct(array $data)
20 {
21 parent::__construct($data);
22 if (! isset($data[self::TYPE]) || (int) $data[self::TYPE] !== self::TYPE_OCT) {
23 throw new InvalidArgumentException(
24 'Invalid symmetric key. The key type does not correspond to a symmetric key'
25 );
26 }
27 if (! isset($data[self::DATA_K])) {
28 throw new InvalidArgumentException('Invalid symmetric key. The parameter "k" is missing');
29 }
30 }
31
32 /**
33 * @param array<int|string, mixed> $data
34 */
35 public static function create(array $data): self
36 {
37 return new self($data);
38 }
39
40 public function k(): string
41 {
42 return $this->get(self::DATA_K);
43 }
44 }