Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
155
vendor/web-auth/cose-lib/src/Encryption/CoseEncrypt0Tag.php
vendored
Normal file
155
vendor/web-auth/cose-lib/src/Encryption/CoseEncrypt0Tag.php
vendored
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cose\Encryption;
|
||||
|
||||
use CBOR\ByteStringObject;
|
||||
use CBOR\CBORObject;
|
||||
use CBOR\Decoder;
|
||||
use CBOR\ListObject;
|
||||
use CBOR\MapObject;
|
||||
use CBOR\OtherObject\OtherObjectManager;
|
||||
use CBOR\StringStream;
|
||||
use CBOR\Tag;
|
||||
use CBOR\Tag\CoseEncrypt0Tag as UpstreamTag;
|
||||
use CBOR\Tag\TagManager;
|
||||
use const E_USER_DEPRECATED;
|
||||
use InvalidArgumentException;
|
||||
use function sprintf;
|
||||
use function trigger_error;
|
||||
|
||||
/**
|
||||
* A tagged COSE_Encrypt0 (RFC 9052, CBOR tag 16).
|
||||
*
|
||||
* @deprecated since 4.8.0, use \CBOR\Tag\CoseEncrypt0Tag from spomky-labs/cbor-php 3.4.0 or later instead. Will be removed
|
||||
* in 5.0.0.
|
||||
*
|
||||
* The six COSE structures were ported upstream in cbor-php 3.4.0, where they share AbstractCoseTag and are
|
||||
* registered in the default decoder, so Decoder::create() resolves tag 16 on its own. The replacement accepts what
|
||||
* this class rejects -- a zero-length protected header, a detached (nil) payload, the indefinite-length encodings --
|
||||
* and reads every item through the list it carries, so its accessors cannot drift from the bytes it serializes.
|
||||
*
|
||||
* What does not move upstream is the RFC 9052 layer above the CBOR shape, and that stays here: {@see \Cose\Structure\CoseHeaders}
|
||||
* for header labels typed as RFC 9052 section 1.5 defines them, and the Sig_structure, MAC_structure and
|
||||
* Enc_structure builders that a signature or a MAC is actually computed over. Both work on the upstream classes.
|
||||
*
|
||||
* Migrating: the class name changes, and the four-argument create() becomes createFromComponents() -- upstream
|
||||
* create() takes the whole list instead.
|
||||
*
|
||||
* @see https://github.com/web-auth/cose-lib/issues/176
|
||||
* @see \Cose\Tests\Structure\DeprecatedTagClassesTest
|
||||
*/
|
||||
final class CoseEncrypt0Tag extends Tag
|
||||
{
|
||||
/**
|
||||
* A COSE header is a flat map of a handful of parameters whose values nest a couple of levels at most, so the
|
||||
* decoder built when none is given is bounded far below the cbor-php default of 1000: a protected header crafted
|
||||
* to nest thousands of levels is rejected instead of being walked.
|
||||
*/
|
||||
public const DEFAULT_PROTECTED_HEADER_MAX_DEPTH = 32;
|
||||
|
||||
private const TAG_ID = 16;
|
||||
|
||||
private readonly ByteStringObject $protectedHeader;
|
||||
|
||||
private readonly MapObject $unprotectedHeader;
|
||||
|
||||
private readonly ByteStringObject $ciphertext;
|
||||
|
||||
public function __construct(int $additionalInformation, ?string $data, CBORObject $object)
|
||||
{
|
||||
trigger_error(sprintf(
|
||||
'The class "%s" is deprecated since 4.8.0 and will be removed in 5.0.0. Use "%s" from spomky-labs/cbor-php 3.4.0 or later instead.',
|
||||
self::class,
|
||||
UpstreamTag::class
|
||||
), E_USER_DEPRECATED);
|
||||
|
||||
if (! $object instanceof ListObject) {
|
||||
throw new InvalidArgumentException('Not a valid CoseEncrypt0 object. No list.');
|
||||
}
|
||||
if ($object->count() !== 3) {
|
||||
throw new InvalidArgumentException('Not a valid CoseEncrypt0 object. The list shall have 3 items.');
|
||||
}
|
||||
|
||||
$protectedHeader = $object->get(0);
|
||||
$unprotectedHeader = $object->get(1);
|
||||
$ciphertext = $object->get(2);
|
||||
|
||||
if (! $protectedHeader instanceof ByteStringObject) {
|
||||
throw new InvalidArgumentException(
|
||||
'Not a valid CoseEncrypt0 object. The item 1 shall be a ByteString object.'
|
||||
);
|
||||
}
|
||||
if (! $unprotectedHeader instanceof MapObject) {
|
||||
throw new InvalidArgumentException('Not a valid CoseEncrypt0 object. The item 2 shall be a Map object.');
|
||||
}
|
||||
if (! $ciphertext instanceof ByteStringObject) {
|
||||
throw new InvalidArgumentException(
|
||||
'Not a valid CoseEncrypt0 object. The item 3 shall be a ByteString object.'
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($additionalInformation, $data, $object);
|
||||
$this->protectedHeader = $protectedHeader;
|
||||
$this->unprotectedHeader = $unprotectedHeader;
|
||||
$this->ciphertext = $ciphertext;
|
||||
}
|
||||
|
||||
public static function getTagId(): int
|
||||
{
|
||||
return self::TAG_ID;
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data, CBORObject $object): self
|
||||
{
|
||||
return new self($additionalInformation, $data, $object);
|
||||
}
|
||||
|
||||
public static function create(
|
||||
MapObject $protectedHeader,
|
||||
MapObject $unprotectedHeader,
|
||||
ByteStringObject $ciphertext
|
||||
): self {
|
||||
$protectedHeaderAsBytesString = ByteStringObject::create((string) $protectedHeader);
|
||||
$object = ListObject::create([$protectedHeaderAsBytesString, $unprotectedHeader, $ciphertext]);
|
||||
|
||||
[$additionalInformation, $data] = self::determineComponents(self::TAG_ID);
|
||||
|
||||
return new self($additionalInformation, $data, $object);
|
||||
}
|
||||
|
||||
public function getProtectedHeader(): ByteStringObject
|
||||
{
|
||||
return $this->protectedHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* The nesting bound only applies to the decoder created here: a caller passing its own $decoder sets its own
|
||||
* bound, and $maxDepth is then ignored.
|
||||
*/
|
||||
public function getProtectedHeaderAsMap(
|
||||
?Decoder $decoder = null,
|
||||
int $maxDepth = self::DEFAULT_PROTECTED_HEADER_MAX_DEPTH
|
||||
): MapObject {
|
||||
$stream = new StringStream($this->protectedHeader->getValue());
|
||||
$decoder ??= Decoder::create(TagManager::create(), OtherObjectManager::create(), $maxDepth);
|
||||
$decoded = $decoder->decode($stream);
|
||||
|
||||
if (! $decoded instanceof MapObject) {
|
||||
throw new InvalidArgumentException('Protected header is not a valid Map object.');
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
public function getUnprotectedHeader(): MapObject
|
||||
{
|
||||
return $this->unprotectedHeader;
|
||||
}
|
||||
|
||||
public function getCiphertext(): ByteStringObject
|
||||
{
|
||||
return $this->ciphertext;
|
||||
}
|
||||
}
|
||||
173
vendor/web-auth/cose-lib/src/Encryption/CoseEncryptTag.php
vendored
Normal file
173
vendor/web-auth/cose-lib/src/Encryption/CoseEncryptTag.php
vendored
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cose\Encryption;
|
||||
|
||||
use CBOR\ByteStringObject;
|
||||
use CBOR\CBORObject;
|
||||
use CBOR\Decoder;
|
||||
use CBOR\ListObject;
|
||||
use CBOR\MapObject;
|
||||
use CBOR\OtherObject\OtherObjectManager;
|
||||
use CBOR\StringStream;
|
||||
use CBOR\Tag;
|
||||
use CBOR\Tag\CoseEncryptTag as UpstreamTag;
|
||||
use CBOR\Tag\TagManager;
|
||||
use const E_USER_DEPRECATED;
|
||||
use InvalidArgumentException;
|
||||
use function sprintf;
|
||||
use function trigger_error;
|
||||
|
||||
/**
|
||||
* A tagged COSE_Encrypt (RFC 9052, CBOR tag 96).
|
||||
*
|
||||
* @deprecated since 4.8.0, use \CBOR\Tag\CoseEncryptTag from spomky-labs/cbor-php 3.4.0 or later instead. Will be removed
|
||||
* in 5.0.0.
|
||||
*
|
||||
* The six COSE structures were ported upstream in cbor-php 3.4.0, where they share AbstractCoseTag and are
|
||||
* registered in the default decoder, so Decoder::create() resolves tag 96 on its own. The replacement accepts what
|
||||
* this class rejects -- a zero-length protected header, a detached (nil) payload, the indefinite-length encodings --
|
||||
* and reads every item through the list it carries, so its accessors cannot drift from the bytes it serializes.
|
||||
*
|
||||
* What does not move upstream is the RFC 9052 layer above the CBOR shape, and that stays here: {@see \Cose\Structure\CoseHeaders}
|
||||
* for header labels typed as RFC 9052 section 1.5 defines them, and the Sig_structure, MAC_structure and
|
||||
* Enc_structure builders that a signature or a MAC is actually computed over. Both work on the upstream classes.
|
||||
*
|
||||
* Migrating: the class name changes, and the four-argument create() becomes createFromComponents() -- upstream
|
||||
* create() takes the whole list instead.
|
||||
*
|
||||
* @see https://github.com/web-auth/cose-lib/issues/176
|
||||
* @see \Cose\Tests\Structure\DeprecatedTagClassesTest
|
||||
*/
|
||||
final class CoseEncryptTag extends Tag
|
||||
{
|
||||
/**
|
||||
* A COSE header is a flat map of a handful of parameters whose values nest a couple of levels at most, so the
|
||||
* decoder built when none is given is bounded far below the cbor-php default of 1000: a protected header crafted
|
||||
* to nest thousands of levels is rejected instead of being walked.
|
||||
*/
|
||||
public const DEFAULT_PROTECTED_HEADER_MAX_DEPTH = 32;
|
||||
|
||||
private const TAG_ID = 96;
|
||||
|
||||
private readonly ByteStringObject $protectedHeader;
|
||||
|
||||
private readonly MapObject $unprotectedHeader;
|
||||
|
||||
private readonly ByteStringObject $ciphertext;
|
||||
|
||||
private readonly ListObject $recipients;
|
||||
|
||||
public function __construct(int $additionalInformation, ?string $data, CBORObject $object)
|
||||
{
|
||||
trigger_error(sprintf(
|
||||
'The class "%s" is deprecated since 4.8.0 and will be removed in 5.0.0. Use "%s" from spomky-labs/cbor-php 3.4.0 or later instead.',
|
||||
self::class,
|
||||
UpstreamTag::class
|
||||
), E_USER_DEPRECATED);
|
||||
|
||||
if (! $object instanceof ListObject) {
|
||||
throw new InvalidArgumentException('Not a valid CoseEncrypt object. No list.');
|
||||
}
|
||||
if ($object->count() !== 4) {
|
||||
throw new InvalidArgumentException('Not a valid CoseEncrypt object. The list shall have 4 items.');
|
||||
}
|
||||
|
||||
$protectedHeader = $object->get(0);
|
||||
$unprotectedHeader = $object->get(1);
|
||||
$ciphertext = $object->get(2);
|
||||
$recipients = $object->get(3);
|
||||
|
||||
if (! $protectedHeader instanceof ByteStringObject) {
|
||||
throw new InvalidArgumentException(
|
||||
'Not a valid CoseEncrypt object. The item 1 shall be a ByteString object.'
|
||||
);
|
||||
}
|
||||
if (! $unprotectedHeader instanceof MapObject) {
|
||||
throw new InvalidArgumentException('Not a valid CoseEncrypt object. The item 2 shall be a Map object.');
|
||||
}
|
||||
if (! $ciphertext instanceof ByteStringObject) {
|
||||
throw new InvalidArgumentException(
|
||||
'Not a valid CoseEncrypt object. The item 3 shall be a ByteString object.'
|
||||
);
|
||||
}
|
||||
if (! $recipients instanceof ListObject) {
|
||||
throw new InvalidArgumentException('Not a valid CoseEncrypt object. The item 4 shall be a List object.');
|
||||
}
|
||||
|
||||
parent::__construct($additionalInformation, $data, $object);
|
||||
$this->protectedHeader = $protectedHeader;
|
||||
$this->unprotectedHeader = $unprotectedHeader;
|
||||
$this->ciphertext = $ciphertext;
|
||||
$this->recipients = $recipients;
|
||||
}
|
||||
|
||||
public static function getTagId(): int
|
||||
{
|
||||
return self::TAG_ID;
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data, CBORObject $object): self
|
||||
{
|
||||
return new self($additionalInformation, $data, $object);
|
||||
}
|
||||
|
||||
public static function create(
|
||||
MapObject $protectedHeader,
|
||||
MapObject $unprotectedHeader,
|
||||
ByteStringObject $ciphertext,
|
||||
ListObject $recipients
|
||||
): self {
|
||||
$protectedHeaderAsBytesString = ByteStringObject::create((string) $protectedHeader);
|
||||
$object = ListObject::create([
|
||||
$protectedHeaderAsBytesString,
|
||||
$unprotectedHeader,
|
||||
$ciphertext,
|
||||
$recipients,
|
||||
]);
|
||||
|
||||
[$additionalInformation, $data] = self::determineComponents(self::TAG_ID);
|
||||
|
||||
return new self($additionalInformation, $data, $object);
|
||||
}
|
||||
|
||||
public function getProtectedHeader(): ByteStringObject
|
||||
{
|
||||
return $this->protectedHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* The nesting bound only applies to the decoder created here: a caller passing its own $decoder sets its own
|
||||
* bound, and $maxDepth is then ignored.
|
||||
*/
|
||||
public function getProtectedHeaderAsMap(
|
||||
?Decoder $decoder = null,
|
||||
int $maxDepth = self::DEFAULT_PROTECTED_HEADER_MAX_DEPTH
|
||||
): MapObject {
|
||||
$stream = new StringStream($this->protectedHeader->getValue());
|
||||
$decoder ??= Decoder::create(TagManager::create(), OtherObjectManager::create(), $maxDepth);
|
||||
$decoded = $decoder->decode($stream);
|
||||
|
||||
if (! $decoded instanceof MapObject) {
|
||||
throw new InvalidArgumentException('Protected header is not a valid Map object.');
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
public function getUnprotectedHeader(): MapObject
|
||||
{
|
||||
return $this->unprotectedHeader;
|
||||
}
|
||||
|
||||
public function getCiphertext(): ByteStringObject
|
||||
{
|
||||
return $this->ciphertext;
|
||||
}
|
||||
|
||||
public function getRecipients(): ListObject
|
||||
{
|
||||
return $this->recipients;
|
||||
}
|
||||
}
|
||||
64
vendor/web-auth/cose-lib/src/Encryption/Encrypt0Structure.php
vendored
Normal file
64
vendor/web-auth/cose-lib/src/Encryption/Encrypt0Structure.php
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cose\Encryption;
|
||||
|
||||
use CBOR\ByteStringObject;
|
||||
use CBOR\IndefiniteLengthByteStringObject;
|
||||
use Cose\Structure\CoseStructure;
|
||||
|
||||
/**
|
||||
* The Enc_structure of a COSE_Encrypt0 (RFC 9052 section 5.3).
|
||||
*
|
||||
* Enc_structure = [ "Encrypt0", protected : empty_or_serialized_map, external_aad : bstr ]
|
||||
*
|
||||
* This is the additional authenticated data of the content encryption. Unlike the signature and MAC structures it
|
||||
* carries no payload: the content itself is what the AEAD encrypts, and this structure is what it authenticates
|
||||
* alongside it.
|
||||
*
|
||||
*
|
||||
* The fields a decoded message supplies are typed to accept the indefinite-length byte strings the cbor-php
|
||||
* accessors can hand back, and are kept exactly as they were given: a cryptographic structure has to embed the
|
||||
* protected bucket byte for byte, or the signature the sender computed over it no longer verifies.
|
||||
* @see https://www.rfc-editor.org/rfc/rfc9052#section-5.3
|
||||
* @see \Cose\Tests\Structure\CoseStructureTest
|
||||
*/
|
||||
final class Encrypt0Structure extends CoseStructure
|
||||
{
|
||||
private readonly ByteStringObject $externalAad;
|
||||
|
||||
public function __construct(
|
||||
private readonly ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
) {
|
||||
$this->externalAad = $externalAad ?? self::emptyExternalAad();
|
||||
}
|
||||
|
||||
public static function create(
|
||||
ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
): self {
|
||||
return new self($protectedHeader, $externalAad);
|
||||
}
|
||||
|
||||
public function getProtectedHeader(): ByteStringObject|IndefiniteLengthByteStringObject
|
||||
{
|
||||
return $this->protectedHeader;
|
||||
}
|
||||
|
||||
public function getExternalAad(): ByteStringObject
|
||||
{
|
||||
return $this->externalAad;
|
||||
}
|
||||
|
||||
protected function context(): string
|
||||
{
|
||||
return 'Encrypt0';
|
||||
}
|
||||
|
||||
protected function items(): array
|
||||
{
|
||||
return [$this->protectedHeader, $this->externalAad];
|
||||
}
|
||||
}
|
||||
64
vendor/web-auth/cose-lib/src/Encryption/EncryptStructure.php
vendored
Normal file
64
vendor/web-auth/cose-lib/src/Encryption/EncryptStructure.php
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cose\Encryption;
|
||||
|
||||
use CBOR\ByteStringObject;
|
||||
use CBOR\IndefiniteLengthByteStringObject;
|
||||
use Cose\Structure\CoseStructure;
|
||||
|
||||
/**
|
||||
* The Enc_structure of a COSE_Encrypt (RFC 9052 section 5.3).
|
||||
*
|
||||
* Enc_structure = [ "Encrypt", protected : empty_or_serialized_map, external_aad : bstr ]
|
||||
*
|
||||
* This is the additional authenticated data of the content encryption. Unlike the signature and MAC structures it
|
||||
* carries no payload: the content itself is what the AEAD encrypts, and this structure is what it authenticates
|
||||
* alongside it.
|
||||
*
|
||||
*
|
||||
* The fields a decoded message supplies are typed to accept the indefinite-length byte strings the cbor-php
|
||||
* accessors can hand back, and are kept exactly as they were given: a cryptographic structure has to embed the
|
||||
* protected bucket byte for byte, or the signature the sender computed over it no longer verifies.
|
||||
* @see https://www.rfc-editor.org/rfc/rfc9052#section-5.3
|
||||
* @see \Cose\Tests\Structure\CoseStructureTest
|
||||
*/
|
||||
final class EncryptStructure extends CoseStructure
|
||||
{
|
||||
private readonly ByteStringObject $externalAad;
|
||||
|
||||
public function __construct(
|
||||
private readonly ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
) {
|
||||
$this->externalAad = $externalAad ?? self::emptyExternalAad();
|
||||
}
|
||||
|
||||
public static function create(
|
||||
ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
): self {
|
||||
return new self($protectedHeader, $externalAad);
|
||||
}
|
||||
|
||||
public function getProtectedHeader(): ByteStringObject|IndefiniteLengthByteStringObject
|
||||
{
|
||||
return $this->protectedHeader;
|
||||
}
|
||||
|
||||
public function getExternalAad(): ByteStringObject
|
||||
{
|
||||
return $this->externalAad;
|
||||
}
|
||||
|
||||
protected function context(): string
|
||||
{
|
||||
return 'Encrypt';
|
||||
}
|
||||
|
||||
protected function items(): array
|
||||
{
|
||||
return [$this->protectedHeader, $this->externalAad];
|
||||
}
|
||||
}
|
||||
96
vendor/web-auth/cose-lib/src/Encryption/RecipientStructure.php
vendored
Normal file
96
vendor/web-auth/cose-lib/src/Encryption/RecipientStructure.php
vendored
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Cose\Encryption;
|
||||
|
||||
use CBOR\ByteStringObject;
|
||||
use CBOR\IndefiniteLengthByteStringObject;
|
||||
use Cose\Structure\CoseStructure;
|
||||
|
||||
/**
|
||||
* The Enc_structure of a recipient (RFC 9052 section 5.3).
|
||||
*
|
||||
* Enc_structure = [ context : "Enc_Recipient" / "Mac_Recipient" / "Rec_Recipient", protected :
|
||||
* empty_or_serialized_map, external_aad : bstr ]
|
||||
*
|
||||
* The three remaining contexts of Enc_structure name where the key being wrapped comes from: the recipient of a
|
||||
* COSE_Encrypt, the recipient of a COSE_Mac, or a recipient nested inside another recipient. Binding the context is
|
||||
* what stops a wrapped key from being replayed at a different level of the same structure, so it is a named
|
||||
* constructor rather than a free string.
|
||||
*
|
||||
*
|
||||
* The fields a decoded message supplies are typed to accept the indefinite-length byte strings the cbor-php
|
||||
* accessors can hand back, and are kept exactly as they were given: a cryptographic structure has to embed the
|
||||
* protected bucket byte for byte, or the signature the sender computed over it no longer verifies.
|
||||
* @see https://www.rfc-editor.org/rfc/rfc9052#section-5.3
|
||||
* @see \Cose\Tests\Structure\CoseStructureTest
|
||||
*/
|
||||
final class RecipientStructure extends CoseStructure
|
||||
{
|
||||
/**
|
||||
* The recipient of a COSE_Encrypt.
|
||||
*/
|
||||
public const CONTEXT_ENC_RECIPIENT = 'Enc_Recipient';
|
||||
|
||||
/**
|
||||
* The recipient of a COSE_Mac.
|
||||
*/
|
||||
public const CONTEXT_MAC_RECIPIENT = 'Mac_Recipient';
|
||||
|
||||
/**
|
||||
* A recipient nested inside another recipient.
|
||||
*/
|
||||
public const CONTEXT_REC_RECIPIENT = 'Rec_Recipient';
|
||||
|
||||
private readonly ByteStringObject $externalAad;
|
||||
|
||||
private function __construct(
|
||||
private readonly string $context,
|
||||
private readonly ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
) {
|
||||
$this->externalAad = $externalAad ?? self::emptyExternalAad();
|
||||
}
|
||||
|
||||
public static function forEncryptRecipient(
|
||||
ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
): self {
|
||||
return new self(self::CONTEXT_ENC_RECIPIENT, $protectedHeader, $externalAad);
|
||||
}
|
||||
|
||||
public static function forMacRecipient(
|
||||
ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
): self {
|
||||
return new self(self::CONTEXT_MAC_RECIPIENT, $protectedHeader, $externalAad);
|
||||
}
|
||||
|
||||
public static function forNestedRecipient(
|
||||
ByteStringObject|IndefiniteLengthByteStringObject $protectedHeader,
|
||||
?ByteStringObject $externalAad = null
|
||||
): self {
|
||||
return new self(self::CONTEXT_REC_RECIPIENT, $protectedHeader, $externalAad);
|
||||
}
|
||||
|
||||
public function getProtectedHeader(): ByteStringObject|IndefiniteLengthByteStringObject
|
||||
{
|
||||
return $this->protectedHeader;
|
||||
}
|
||||
|
||||
public function getExternalAad(): ByteStringObject
|
||||
{
|
||||
return $this->externalAad;
|
||||
}
|
||||
|
||||
protected function context(): string
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
protected function items(): array
|
||||
{
|
||||
return [$this->protectedHeader, $this->externalAad];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue