Skip to content

Commit a78ea6f

Browse files
committed
Add minimal DTOs
1 parent 6a9216b commit a78ea6f

13 files changed

Lines changed: 507 additions & 1 deletion
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\Credentials;
15+
16+
class BasicCredential implements CredentialInterface
17+
{
18+
protected string $type;
19+
protected string $identity;
20+
protected string $publicKey;
21+
22+
public function __construct(string $type, string $identity, string $publicKey)
23+
{
24+
$this->type = $type;
25+
$this->identity = $identity;
26+
$this->publicKey = $publicKey;
27+
}
28+
29+
public function getCredentialType(): string
30+
{
31+
return $this->type;
32+
}
33+
34+
public function getIdentity(): string
35+
{
36+
return $this->identity;
37+
}
38+
39+
public function getPublicKey(): string
40+
{
41+
return $this->publicKey;
42+
}
43+
44+
public function verifySignature(string $message, string $signature): bool
45+
{
46+
// Minimal stub: concrete implementations should verify with the proper algorithm.
47+
return false;
48+
}
49+
50+
public function __toString(): string
51+
{
52+
return $this->identity;
53+
}
54+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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\Crypto;
15+
16+
class BasicCipherSuite implements CipherSuiteInterface
17+
{
18+
protected int $id;
19+
20+
public function __construct(int $id = 1)
21+
{
22+
$this->id = $id;
23+
}
24+
25+
public function getId(): int
26+
{
27+
return $this->id;
28+
}
29+
30+
public function getHpkeKemId(): int
31+
{
32+
return 32;
33+
}
34+
35+
public function getHpkeKdfId(): int
36+
{
37+
return 1;
38+
}
39+
40+
public function getHpkeAeadId(): int
41+
{
42+
return 1;
43+
}
44+
45+
public function getHashLength(): int
46+
{
47+
return 32;
48+
}
49+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
use MLS\Credentials\CredentialInterface;
17+
use MLS\Crypto\CipherSuiteInterface;
18+
19+
class BasicKeyPackage implements KeyPackageInterface
20+
{
21+
protected int $version;
22+
protected CipherSuiteInterface $suite;
23+
protected string $initKey;
24+
protected CredentialInterface $credential;
25+
protected array $extensions;
26+
27+
public function __construct(int $version, CipherSuiteInterface $suite, string $initKey, CredentialInterface $credential, array $extensions = [])
28+
{
29+
$this->version = $version;
30+
$this->suite = $suite;
31+
$this->initKey = $initKey;
32+
$this->credential = $credential;
33+
$this->extensions = $extensions;
34+
}
35+
36+
public function getProtocolVersion(): int
37+
{
38+
return $this->version;
39+
}
40+
41+
public function getCipherSuite(): CipherSuiteInterface
42+
{
43+
return $this->suite;
44+
}
45+
46+
public function getInitKey(): string
47+
{
48+
return $this->initKey;
49+
}
50+
51+
public function getCredential(): CredentialInterface
52+
{
53+
return $this->credential;
54+
}
55+
56+
public function getExtensions(): array
57+
{
58+
return $this->extensions;
59+
}
60+
61+
public function verify(): bool
62+
{
63+
// Minimal stub: assume credential verifies signature of KeyPackage
64+
return true;
65+
}
66+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}

src/MLS/Message/BasicSender.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\Message;
15+
16+
class BasicSender implements SenderInterface
17+
{
18+
protected int $type;
19+
protected ?int $leafIndex;
20+
protected ?int $senderIndex;
21+
22+
public function __construct(int $type = self::TYPE_MEMBER, ?int $leafIndex = null, ?int $senderIndex = null)
23+
{
24+
$this->type = $type;
25+
$this->leafIndex = $leafIndex;
26+
$this->senderIndex = $senderIndex;
27+
}
28+
29+
public function getType(): int
30+
{
31+
return $this->type;
32+
}
33+
34+
public function getLeafIndex(): ?int
35+
{
36+
return $this->leafIndex;
37+
}
38+
39+
public function getSenderIndex(): ?int
40+
{
41+
return $this->senderIndex;
42+
}
43+
}

src/MLS/Proposal/BasicProposal.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\Proposal;
15+
16+
use MLS\Message\SenderInterface;
17+
18+
class BasicProposal implements ProposalInterface
19+
{
20+
protected string $type;
21+
protected SenderInterface $sender;
22+
protected array $proposal;
23+
24+
public function __construct(string $type, SenderInterface $sender, array $proposal = [])
25+
{
26+
$this->type = $type;
27+
$this->sender = $sender;
28+
$this->proposal = $proposal;
29+
}
30+
31+
public function getType(): string
32+
{
33+
return $this->type;
34+
}
35+
36+
public function getSender(): SenderInterface
37+
{
38+
return $this->sender;
39+
}
40+
41+
public function getProposal(): array
42+
{
43+
return $this->proposal;
44+
}
45+
}

src/MLS/Proposal/ProposalList.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\Proposal;
15+
16+
class ProposalList implements ProposalListInterface
17+
{
18+
/** @var ProposalInterface[] */
19+
protected array $proposals = [];
20+
21+
/** @param ProposalInterface[] $proposals */
22+
public function __construct(array $proposals = [])
23+
{
24+
foreach ($proposals as $p) {
25+
$this->addProposal($p);
26+
}
27+
}
28+
29+
/** @return ProposalInterface[] */
30+
public function getProposals(): array
31+
{
32+
return $this->proposals;
33+
}
34+
35+
public function addProposal(ProposalInterface $proposal): void
36+
{
37+
$this->proposals[] = $proposal;
38+
}
39+
40+
public function count(): int
41+
{
42+
return count($this->proposals);
43+
}
44+
}

src/MLS/Tree/TreeInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getParent(int $index): ?ParentNodeInterface;
3030
/**
3131
* Compute the path for a leaf index.
3232
*
33-
* @param int $leafIndex
33+
* @param int $leafIndex
3434
* @return \MLS\Commit\UpdatePathInterface
3535
*/
3636
public function computePath(int $leafIndex): UpdatePathInterface;

0 commit comments

Comments
 (0)