|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is a part of the DiscordPHP-RFC9420 project. |
| 7 | + * |
| 8 | + * Copyright (c) 2026-present Valithor Obsidion <valithor@discordphp.org> |
| 9 | + * |
| 10 | + * This file is subject to the MIT license that is bundled |
| 11 | + * with this source code in the LICENSE.md file. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace MLS\Handshake; |
| 15 | + |
| 16 | +class KeyPackageBundle implements KeyPackageBundleInterface |
| 17 | +{ |
| 18 | + /** @var KeyPackageInterface[] */ |
| 19 | + protected array $keyPackages = []; |
| 20 | + /** @var array<string,mixed> */ |
| 21 | + protected array $associatedSecrets = []; |
| 22 | + /** @var array */ |
| 23 | + protected array $extensions = []; |
| 24 | + |
| 25 | + /** @param KeyPackageInterface[] $keyPackages */ |
| 26 | + public function __construct(array $keyPackages = [], array $associatedSecrets = [], array $extensions = []) |
| 27 | + { |
| 28 | + $this->keyPackages = $keyPackages; |
| 29 | + $this->associatedSecrets = $associatedSecrets; |
| 30 | + $this->extensions = $extensions; |
| 31 | + } |
| 32 | + |
| 33 | + /** @return KeyPackageInterface[] */ |
| 34 | + public function getKeyPackages(): array |
| 35 | + { |
| 36 | + return $this->keyPackages; |
| 37 | + } |
| 38 | + |
| 39 | + /** @return array<string,mixed> */ |
| 40 | + public function getAssociatedSecrets(): array |
| 41 | + { |
| 42 | + return $this->associatedSecrets ?? []; |
| 43 | + } |
| 44 | + |
| 45 | + /** @return array */ |
| 46 | + public function getExtensions(): array |
| 47 | + { |
| 48 | + return $this->extensions ?? []; |
| 49 | + } |
| 50 | + |
| 51 | + public function verifyAll(): bool |
| 52 | + { |
| 53 | + foreach ($this->getKeyPackages() as $kp) { |
| 54 | + if (! $kp->verify()) { |
| 55 | + return false; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + public function serialize(): string |
| 63 | + { |
| 64 | + // Minimal stable serialization for testing; concrete implementations should use real encodings |
| 65 | + return json_encode([ |
| 66 | + 'count' => count($this->keyPackages), |
| 67 | + ]); |
| 68 | + } |
| 69 | +} |
0 commit comments