Skip to content

Commit efe8ae3

Browse files
committed
More enums
1 parent 2a82b04 commit efe8ae3

5 files changed

Lines changed: 290 additions & 3 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ Implemented (interface files) — ordered by RFC section
5151

5252
Enums / identifiers
5353

54-
- [`src/MLS/Enums/ProposalType.php`](src/MLS/Enums/ProposalType.php) — Proposal type identifiers (add/update/remove/etc.)
55-
- [`src/MLS/Enums/MessageWireFormat.php`](src/MLS/Enums/MessageWireFormat.php) — Message wire-format identifiers (`plaintext` / `ciphertext`)
56-
- [`src/MLS/Enums/ContentType.php`](src/MLS/Enums/ContentType.php) — Content-type identifiers used inside payloads
54+
- [`src/MLS/Enums/MessageWireFormat.php`](src/MLS/Enums/MessageWireFormat.php) — RFC 9420: MLS Wire Formats ([Table 8](https://www.rfc-editor.org/rfc/rfc9420.html#table-9))
55+
- [`src/MLS/Enums/ExtensionType.php`](src/MLS/Enums/ExtensionType.php) — RFC 9420: MLS Extension Types ([Table 9](https://www.rfc-editor.org/rfc/rfc9420.html#table-9))
56+
- [`src/MLS/Enums/ProposalType.php`](src/MLS/Enums/ProposalType.php) — RFC 9420: MLS Proposal Types ([Table 10](https://www.rfc-editor.org/rfc/rfc9420.html#table-9))
57+
- [`src/MLS/Enums/CredentialType.php`](src/MLS/Enums/CredentialType.php) — RFC 9420: MLS Credential Types ([Table 11](https://www.rfc-editor.org/rfc/rfc9420.html#table-11))
58+
- [`src/MLS/Enums/SignatureLabels.php`](src/MLS/Enums/SignatureLabels.php) — RFC 9420: MLS Signature Labels ([Table 12](https://www.rfc-editor.org/rfc/rfc9420.html#table-12))
59+
- [`src/MLS/Enums/PublicKeyEncryptionLabels.php`](src/MLS/Enums/PublicKeyEncryptionLabels.php) — RFC 9420: MLS Public Key Encryption Labels ([Table 13](https://www.rfc-editor.org/rfc/rfc9420.html#table-13))
5760

5861
All RFC sections listed in the original TODO have corresponding interface files and identifiers in this repository. See the `Implemented` list above for file-level cross-references to RFC sections.
5962

@@ -94,6 +97,7 @@ RFC coverage
9497
- Handshake: `KeyPackage` and `Welcome` interfaces added; key package bundles and encrypted secrets not implemented.
9598
- Crypto: Cipher suite, KeySchedule, HPKE, and signature scheme abstractions provided; implementations required.
9699
- Extensions & Transcript: extension and transcript interfaces included for payloads and hash tracking.
100+
- RFC registries mirrored: wire formats, proposal types, extension types, credential types, signature labels, and public-key encryption labels are represented under `src/MLS/Enums/`.
97101

98102
Roadmap
99103

src/MLS/Enums/CredentialType.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MLS\Enums;
6+
7+
/**
8+
* MLS Credential Types (RFC 9420 - Section 17.5, Table 11).
9+
*/
10+
final class CredentialType
11+
{
12+
public const RESERVED = 0x0000;
13+
public const BASIC = 0x0001;
14+
public const X509 = 0x0002;
15+
16+
// GREASE values
17+
public const GREASE_0A0A = 0x0A0A;
18+
public const GREASE_1A1A = 0x1A1A;
19+
public const GREASE_2A2A = 0x2A2A;
20+
public const GREASE_3A3A = 0x3A3A;
21+
public const GREASE_4A4A = 0x4A4A;
22+
public const GREASE_5A5A = 0x5A5A;
23+
public const GREASE_6A6A = 0x6A6A;
24+
public const GREASE_7A7A = 0x7A7A;
25+
public const GREASE_8A8A = 0x8A8A;
26+
public const GREASE_9A9A = 0x9A9A;
27+
public const GREASE_AAAA = 0xAAAA;
28+
public const GREASE_BABA = 0xBABA;
29+
public const GREASE_CACA = 0xCACA;
30+
public const GREASE_DADA = 0xDADA;
31+
public const GREASE_EAEA = 0xEAEA;
32+
33+
public const PRIVATE_USE_START = 0xF000;
34+
public const PRIVATE_USE_END = 0xFFFF;
35+
36+
private const NAME_MAP = [
37+
self::RESERVED => 'reserved',
38+
self::BASIC => 'basic',
39+
self::X509 => 'x509',
40+
self::GREASE_0A0A => 'grease_0a0a',
41+
self::GREASE_1A1A => 'grease_1a1a',
42+
self::GREASE_2A2A => 'grease_2a2a',
43+
self::GREASE_3A3A => 'grease_3a3a',
44+
self::GREASE_4A4A => 'grease_4a4a',
45+
self::GREASE_5A5A => 'grease_5a5a',
46+
self::GREASE_6A6A => 'grease_6a6a',
47+
self::GREASE_7A7A => 'grease_7a7a',
48+
self::GREASE_8A8A => 'grease_8a8a',
49+
self::GREASE_9A9A => 'grease_9a9a',
50+
self::GREASE_AAAA => 'grease_aaaa',
51+
self::GREASE_BABA => 'grease_baba',
52+
self::GREASE_CACA => 'grease_caca',
53+
self::GREASE_DADA => 'grease_dada',
54+
self::GREASE_EAEA => 'grease_eaea',
55+
];
56+
57+
private const RECOMMENDED = [
58+
self::BASIC => true,
59+
self::X509 => true,
60+
];
61+
62+
private function __construct()
63+
{
64+
}
65+
66+
public static function nameOf(int $type): ?string
67+
{
68+
if (isset(self::NAME_MAP[$type])) {
69+
return self::NAME_MAP[$type];
70+
}
71+
72+
if ($type >= self::PRIVATE_USE_START && $type <= self::PRIVATE_USE_END) {
73+
return 'private_use';
74+
}
75+
76+
return null;
77+
}
78+
79+
public static function isRecommended(int $type): ?bool
80+
{
81+
return self::RECOMMENDED[$type] ?? null;
82+
}
83+
84+
public static function isPrivateUse(int $type): bool
85+
{
86+
return $type >= self::PRIVATE_USE_START && $type <= self::PRIVATE_USE_END;
87+
}
88+
}

src/MLS/Enums/ExtensionType.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MLS\Enums;
6+
7+
/**
8+
* MLS Public Key Encryption Labels (RFC 9420 - Section 17.7)
9+
*/
10+
final class PublicKeyEncryptionLabels
11+
{
12+
public const UPDATE_PATH_NODE = 'UpdatePathNode';
13+
public const WELCOME = 'Welcome';
14+
15+
private const RECOMMENDED = [
16+
self::UPDATE_PATH_NODE => true,
17+
self::WELCOME => true,
18+
];
19+
20+
private function __construct()
21+
{
22+
}
23+
24+
public static function list(): array
25+
{
26+
return array_keys(self::RECOMMENDED);
27+
}
28+
29+
public static function isRecommended(string $label): bool
30+
{
31+
return isset(self::RECOMMENDED[$label]) && self::RECOMMENDED[$label] === true;
32+
}
33+
}

src/MLS/Enums/SignatureLabels.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MLS\Enums;
6+
7+
/**
8+
* MLS Signature Labels (RFC 9420 - Section 17.6)
9+
*/
10+
final class SignatureLabels
11+
{
12+
public const FRAMED_CONTENT_TBS = 'FramedContentTBS';
13+
public const LEAF_NODE_TBS = 'LeafNodeTBS';
14+
public const KEY_PACKAGE_TBS = 'KeyPackageTBS';
15+
public const GROUP_INFO_TBS = 'GroupInfoTBS';
16+
17+
private const RECOMMENDED = [
18+
self::FRAMED_CONTENT_TBS => true,
19+
self::LEAF_NODE_TBS => true,
20+
self::KEY_PACKAGE_TBS => true,
21+
self::GROUP_INFO_TBS => true,
22+
];
23+
24+
private function __construct()
25+
{
26+
}
27+
28+
public static function list(): array
29+
{
30+
return array_keys(self::RECOMMENDED);
31+
}
32+
33+
public static function isRecommended(string $label): bool
34+
{
35+
return isset(self::RECOMMENDED[$label]) && self::RECOMMENDED[$label] === true;
36+
}
37+
}

0 commit comments

Comments
 (0)