|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace MLS\Enums; |
| 6 | + |
| 7 | +/** |
| 8 | + * MLS Extension Types (RFC 9420 - Section 17.3, Table 9). |
| 9 | + */ |
| 10 | +final class ExtensionType |
| 11 | +{ |
| 12 | + public const RESERVED = 0x0000; |
| 13 | + public const APPLICATION_ID = 0x0001; |
| 14 | + public const RATCHET_TREE = 0x0002; |
| 15 | + public const REQUIRED_CAPABILITIES = 0x0003; |
| 16 | + public const EXTERNAL_PUB = 0x0004; |
| 17 | + public const EXTERNAL_SENDERS = 0x0005; |
| 18 | + |
| 19 | + // GREASE values |
| 20 | + public const GREASE_0A0A = 0x0A0A; |
| 21 | + public const GREASE_1A1A = 0x1A1A; |
| 22 | + public const GREASE_2A2A = 0x2A2A; |
| 23 | + public const GREASE_3A3A = 0x3A3A; |
| 24 | + public const GREASE_4A4A = 0x4A4A; |
| 25 | + public const GREASE_5A5A = 0x5A5A; |
| 26 | + public const GREASE_6A6A = 0x6A6A; |
| 27 | + public const GREASE_7A7A = 0x7A7A; |
| 28 | + public const GREASE_8A8A = 0x8A8A; |
| 29 | + public const GREASE_9A9A = 0x9A9A; |
| 30 | + public const GREASE_AAAA = 0xAAAA; |
| 31 | + public const GREASE_BABA = 0xBABA; |
| 32 | + public const GREASE_CACA = 0xCACA; |
| 33 | + public const GREASE_DADA = 0xDADA; |
| 34 | + public const GREASE_EAEA = 0xEAEA; |
| 35 | + |
| 36 | + public const PRIVATE_USE_START = 0xF000; |
| 37 | + public const PRIVATE_USE_END = 0xFFFF; |
| 38 | + |
| 39 | + private const NAME_MAP = [ |
| 40 | + self::RESERVED => 'reserved', |
| 41 | + self::APPLICATION_ID => 'application_id', |
| 42 | + self::RATCHET_TREE => 'ratchet_tree', |
| 43 | + self::REQUIRED_CAPABILITIES => 'required_capabilities', |
| 44 | + self::EXTERNAL_PUB => 'external_pub', |
| 45 | + self::EXTERNAL_SENDERS => 'external_senders', |
| 46 | + self::GREASE_0A0A => 'grease_0a0a', |
| 47 | + self::GREASE_1A1A => 'grease_1a1a', |
| 48 | + self::GREASE_2A2A => 'grease_2a2a', |
| 49 | + self::GREASE_3A3A => 'grease_3a3a', |
| 50 | + self::GREASE_4A4A => 'grease_4a4a', |
| 51 | + self::GREASE_5A5A => 'grease_5a5a', |
| 52 | + self::GREASE_6A6A => 'grease_6a6a', |
| 53 | + self::GREASE_7A7A => 'grease_7a7a', |
| 54 | + self::GREASE_8A8A => 'grease_8a8a', |
| 55 | + self::GREASE_9A9A => 'grease_9a9a', |
| 56 | + self::GREASE_AAAA => 'grease_aaaa', |
| 57 | + self::GREASE_BABA => 'grease_baba', |
| 58 | + self::GREASE_CACA => 'grease_caca', |
| 59 | + self::GREASE_DADA => 'grease_dada', |
| 60 | + self::GREASE_EAEA => 'grease_eaea', |
| 61 | + ]; |
| 62 | + |
| 63 | + private const MESSAGE_MAP = [ |
| 64 | + self::APPLICATION_ID => ['LN'], |
| 65 | + self::RATCHET_TREE => ['GI'], |
| 66 | + self::REQUIRED_CAPABILITIES => ['GC'], |
| 67 | + self::EXTERNAL_PUB => ['GI'], |
| 68 | + self::EXTERNAL_SENDERS => ['GC'], |
| 69 | + self::GREASE_0A0A => ['KP','GI','LN'], |
| 70 | + self::GREASE_1A1A => ['KP','GI','LN'], |
| 71 | + self::GREASE_2A2A => ['KP','GI','LN'], |
| 72 | + self::GREASE_3A3A => ['KP','GI','LN'], |
| 73 | + self::GREASE_4A4A => ['KP','GI','LN'], |
| 74 | + self::GREASE_5A5A => ['KP','GI','LN'], |
| 75 | + self::GREASE_6A6A => ['KP','GI','LN'], |
| 76 | + self::GREASE_7A7A => ['KP','GI','LN'], |
| 77 | + self::GREASE_8A8A => ['KP','GI','LN'], |
| 78 | + self::GREASE_9A9A => ['KP','GI','LN'], |
| 79 | + self::GREASE_AAAA => ['KP','GI','LN'], |
| 80 | + self::GREASE_BABA => ['KP','GI','LN'], |
| 81 | + self::GREASE_CACA => ['KP','GI','LN'], |
| 82 | + self::GREASE_DADA => ['KP','GI','LN'], |
| 83 | + self::GREASE_EAEA => ['KP','GI','LN'], |
| 84 | + ]; |
| 85 | + |
| 86 | + private const RECOMMENDED = [ |
| 87 | + self::APPLICATION_ID => true, |
| 88 | + self::RATCHET_TREE => true, |
| 89 | + self::REQUIRED_CAPABILITIES => true, |
| 90 | + self::EXTERNAL_PUB => true, |
| 91 | + self::EXTERNAL_SENDERS => true, |
| 92 | + ]; |
| 93 | + |
| 94 | + private function __construct() |
| 95 | + { |
| 96 | + } |
| 97 | + |
| 98 | + public static function nameOf(int $type): ?string |
| 99 | + { |
| 100 | + if (isset(self::NAME_MAP[$type])) { |
| 101 | + return self::NAME_MAP[$type]; |
| 102 | + } |
| 103 | + |
| 104 | + if ($type >= self::PRIVATE_USE_START && $type <= self::PRIVATE_USE_END) { |
| 105 | + return 'private_use'; |
| 106 | + } |
| 107 | + |
| 108 | + return null; |
| 109 | + } |
| 110 | + |
| 111 | + public static function messagesFor(int $type): ?array |
| 112 | + { |
| 113 | + return self::MESSAGE_MAP[$type] ?? null; |
| 114 | + } |
| 115 | + |
| 116 | + public static function isRecommended(int $type): ?bool |
| 117 | + { |
| 118 | + return self::RECOMMENDED[$type] ?? null; |
| 119 | + } |
| 120 | + |
| 121 | + public static function isPrivateUse(int $type): bool |
| 122 | + { |
| 123 | + return $type >= self::PRIVATE_USE_START && $type <= self::PRIVATE_USE_END; |
| 124 | + } |
| 125 | +} |
0 commit comments