-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor X509SerialNumber * Implement IntegerElementTrait * Add HMACOutputLength element * Refactor ds:SignatureMethod * Add ds:MgmtData element * Add ds:PGPKeyID element * Add ds:PGPKeyPacket element * Add ds:PGPData element * Add ds:MgmtData element * Add ds:SPKISexp element * Add ds:SPKIData element
- Loading branch information
Showing
42 changed files
with
1,132 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\ds; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\SchemaViolationException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
use SimpleSAML\XML\ExtendableElementTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; | ||
|
||
use function array_pop; | ||
|
||
/** | ||
* Abstract class representing the PGPDataType. | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
abstract class AbstractPGPDataType extends AbstractDsElement | ||
{ | ||
use ExtendableElementTrait; | ||
|
||
/** @var \SimpleSAML\XML\XsNamespace */ | ||
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* Initialize a PGPData element. | ||
* | ||
* @param \SimpleSAML\XMLSecurity\XML\ds\PGPKeyID|null $pgpKeyId | ||
* @param \SimpleSAML\XMLSecurity\XML\ds\PGPKeyPacket|null $pgpKeyPacket | ||
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children | ||
*/ | ||
final public function __construct( | ||
protected ?PGPKeyID $pgpKeyId = null, | ||
protected ?PGPKeyPacket $pgpKeyPacket = null, | ||
array $children = [], | ||
) { | ||
if ($pgpKeyId === null && $pgpKeyPacket === null) { | ||
throw new SchemaViolationException("ds:PGPKeyID and ds:PGPKeyPacket can't both be null."); | ||
} | ||
|
||
$this->setElements($children); | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the PGPKeyID-property | ||
* | ||
* @return \SimpleSAML\XMLSecurity\XML\ds\PGPKeyID|null | ||
*/ | ||
public function getPGPKeyID(): ?PGPKeyID | ||
{ | ||
return $this->pgpKeyId; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the PGPKeyPacket-property | ||
* | ||
* @return \SimpleSAML\XMLSecurity\XML\ds\PGPKeyPacket|null | ||
*/ | ||
public function getPGPKeyPacket(): ?PGPKeyPacket | ||
{ | ||
return $this->pgpKeyPacket; | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into a PGPData | ||
* | ||
* @param \DOMElement $xml The XML element we should load | ||
* @return static | ||
* | ||
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException | ||
* If the qualified name of the supplied element is wrong | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); | ||
|
||
$pgpKeyId = PGPKeyID::getChildrenOfClass($xml); | ||
Assert::maxCount($pgpKeyId, 1, TooManyElementsException::class); | ||
|
||
$pgpKeyPacket = PGPKeyPacket::getChildrenOfClass($xml); | ||
Assert::maxCount($pgpKeyPacket, 1, TooManyElementsException::class); | ||
|
||
return new static( | ||
array_pop($pgpKeyId), | ||
array_pop($pgpKeyPacket), | ||
self::getChildElementsFromXML($xml), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Convert this PGPData to XML. | ||
* | ||
* @param \DOMElement|null $parent The element we should append this PGPData to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(?DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
|
||
$this->getPGPKeyId()?->toXML($e); | ||
$this->getPGPKeyPacket()?->toXML($e); | ||
|
||
foreach ($this->getElements() as $elt) { | ||
$elt->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\ds; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\SchemaViolationException; | ||
use SimpleSAML\XML\Registry\ElementRegistry; | ||
use SimpleSAML\XML\SerializableElementInterface; | ||
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; | ||
|
||
/** | ||
* Abstract class representing the SPKIDataType. | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
abstract class AbstractSPKIDataType extends AbstractDsElement | ||
{ | ||
/** | ||
* Initialize a SPKIData element. | ||
* | ||
* @param array{array{\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, \SimpleSAML\XML\SerializableElementInterface|null}} $tuples | ||
*/ | ||
final public function __construct( | ||
protected array $tuples, | ||
) { | ||
Assert::allIsArray($tuples, SchemaViolationException::class); | ||
Assert::allCount($tuples, 2); | ||
|
||
foreach ($tuples as $tuple) { | ||
Assert::isInstanceOf($tuple[0], SPKISexp::class, SchemaViolationException::class); | ||
Assert::nullOrIsInstanceOf($tuple[1], SerializableElementInterface::class, SchemaViolationException::class); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the SPKISexp-property | ||
* | ||
* @return array{array{\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, \SimpleSAML\XML\SerializableElementInterface|null}} | ||
*/ | ||
public function getTuples(): array | ||
{ | ||
return $this->tuples; | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into a SPKIData | ||
* | ||
* @param \DOMElement $xml The XML element we should load | ||
* @return static | ||
* | ||
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException | ||
* If the qualified name of the supplied element is wrong | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); | ||
|
||
$registry = ElementRegistry::getInstance(); | ||
$tuples = []; | ||
$tuple = [null, null]; | ||
foreach ($xml->childNodes as $node) { | ||
if ($node instanceof DOMElement) { | ||
if ($node->namespaceURI === static::NS && $node->localName === 'SPKISexp') { | ||
if ($tuple[0] !== null) { | ||
$tuples[] = $tuple; | ||
} | ||
$tuple = [SPKISexp::fromXML($node), null]; | ||
} elseif ($node->namespaceURI !== static::NS && $tuple[0] !== null) { | ||
$handler = $registry->getElementHandler($node->namespaceURI, $node->localName); | ||
$tuple[1] = ($handler === null) ? Chunk::fromXML($node) : $handler::fromXML($node); | ||
$tuples[] = $tuple; | ||
$tuple = [null, null]; | ||
} | ||
} | ||
} | ||
|
||
if ($tuple[0] !== null) { | ||
$tuples[] = $tuple; | ||
} | ||
|
||
return new static($tuples); | ||
} | ||
|
||
|
||
/** | ||
* Convert this SPKIData to XML. | ||
* | ||
* @param \DOMElement|null $parent The element we should append this SPKIData to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(?DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
|
||
foreach ($this->getTuples() as $tuple) { | ||
$tuple[0]->toXML($e); | ||
$tuple[1]?->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\ds; | ||
|
||
use SimpleSAML\XML\IntegerElementTrait; | ||
|
||
/** | ||
* Class representing a ds:HMACOutputLength element. | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
final class HMACOutputLength extends AbstractDsElement | ||
{ | ||
use IntegerElementTrait; | ||
|
||
|
||
/** | ||
* @param string $length | ||
*/ | ||
public function __construct(string $length) | ||
{ | ||
$this->setContent($length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\ds; | ||
|
||
use SimpleSAML\XML\StringElementTrait; | ||
|
||
/** | ||
* Class representing a ds:MgmtData element. | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
final class MgmtData extends AbstractDsElement | ||
{ | ||
use StringElementTrait; | ||
|
||
|
||
/** | ||
* @param string $content | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->setContent($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\ds; | ||
|
||
/** | ||
* Class representing a ds:PGPData element. | ||
* | ||
* @package simplesaml/xml-security | ||
*/ | ||
final class PGPData extends AbstractPGPDataType | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\ds; | ||
|
||
use SimpleSAML\XML\Base64ElementTrait; | ||
|
||
/** | ||
* Class representing a ds:PGPKeyID element. | ||
* | ||
* @package simplesaml/xml-security | ||
*/ | ||
final class PGPKeyID extends AbstractDsElement | ||
{ | ||
use Base64ElementTrait; | ||
|
||
|
||
/** | ||
* @param string $content | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->setContent($content); | ||
} | ||
} |
Oops, something went wrong.