Skip to content

Commit

Permalink
Add ds:DSAKeyValue element
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 3, 2024
1 parent 6334692 commit ab12a34
Show file tree
Hide file tree
Showing 25 changed files with 875 additions and 0 deletions.
206 changes: 206 additions & 0 deletions src/XML/ds/AbstractDSAKeyValueType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?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 function array_pop;

/**
* A class implementing the ds:AbstractDSAKeyValueType element.
*
* @package simplesamlphp/xml-security
*/
abstract class AbstractDSAKeyValueType extends AbstractDsElement
{
/**
* DSAKeyValueType constructor.
*
* @param \SimpleSAML\XMLSecurity\XML\ds\Y $y
* @param \SimpleSAML\XMLSecurity\XML\ds\G|null $g
* @param \SimpleSAML\XMLSecurity\XML\ds\J|null $j
* @param \SimpleSAML\XMLSecurity\XML\ds\P|null $p
* @param \SimpleSAML\XMLSecurity\XML\ds\Q|null $q
* @param \SimpleSAML\XMLSecurity\XML\ds\Generator|null $generator
* @param \SimpleSAML\XMLSecurity\XML\ds\Seed|null $seed
* @param \SimpleSAML\XMLSecurity\XML\ds\PgenCounter|null $pgenCounter
*/
final public function __construct(
protected Y $y,
protected ?G $g = null,
protected ?J $j = null,
protected ?P $p = null,
protected ?Q $q = null,
protected ?Seed $seed = null,
protected ?PgenCounter $pgenCounter = null,
) {
if ($p !== null || $q !== null) {
Assert::allNotNull([$p, $q], SchemaViolationException::class);
} else {
Assert::allNull([$p, $q], SchemaViolationException::class);
}

if ($seed !== null || $pgenCounter !== null) {
Assert::allNotNull([$seed, $pgenCounter], SchemaViolationException::class);
} else {
Assert::allNull([$seed, $pgenCounter], SchemaViolationException::class);
}
}


/**
* Get the Y.
*
* @return \SimpleSAML\XMLSecurity\XML\ds\Y
*/
public function getY(): Y
{
return $this->y;
}


/**
* Get the G.
*
* @return \SimpleSAML\XMLSecurity\XML\ds\G
*/
public function getG(): G
{
return $this->g;
}


/**
* Get the J.
*
* @return \SimpleSAML\XMLSecurity\XML\ds\J
*/
public function getJ(): J
{
return $this->j;
}


/**
* Get the P.
*
* @return \SimpleSAML\XMLSecurity\XML\ds\P|null
*/
public function getP(): ?P
{
return $this->p;
}


/**
* Get the Q.
*
* @return \SimpleSAML\XMLSecurity\XML\ds\Q|null
*/
public function getQ(): ?Q
{
return $this->q;
}


/**
* Get the Seed.
*
* @return \SimpleSAML\XMLSecurity\XML\ds\Seed|null
*/
public function getSeed(): ?Seed
{
return $this->seed;
}


/**
* Get the PgenCounter.
*
* @return \SimpleSAML\XMLSecurity\XML\ds\PgenCounter|null
*/
public function getPgenCounter(): ?PgenCounter
{
return $this->pgenCounter;
}


/**
* Initialize an DSAKeyValue object from an existing XML.
*
* @param \DOMElement $xml
* @return static
*
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
* if the qualified name of the supplied element is wrong
* @throws \SimpleSAML\XML\Exception\MissingAttributeException
* if the supplied element is missing one of the mandatory attributes
* @throws \SimpleSAML\XML\Exception\TooManyElementsException
* if too many child-elements of a type are specified
*/
public static function fromXML(DOMElement $xml): static
{
Assert::same($xml->localName, 'DSAKeyValue', InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);

$y = Y::getChildrenOfClass($xml);
Assert::minCount($y, 1, TooManyElementsException::class);
Assert::maxCount($y, 1, TooManyElementsException::class);

$g = G::getChildrenOfClass($xml);
Assert::maxCount($g, 1, TooManyElementsException::class);

$j = J::getChildrenOfClass($xml);
Assert::maxCount($j, 1, TooManyElementsException::class);

$p = P::getChildrenOfClass($xml);
Assert::maxCount($p, 1, TooManyElementsException::class);

$q = Q::getChildrenOfClass($xml);
Assert::maxCount($q, 1, TooManyElementsException::class);

$seed = Seed::getChildrenOfClass($xml);
Assert::maxCount($seed, 1, TooManyElementsException::class);

$pgenCounter = PgenCounter::getChildrenOfClass($xml);
Assert::maxCount($pgenCounter, 1, TooManyElementsException::class);

return new static(
array_pop($y),
array_pop($g),
array_pop($j),
array_pop($p),
array_pop($q),
array_pop($seed),
array_pop($pgenCounter),
);
}


/**
* Convert this DSAKeyValue object to XML.
*
* @param \DOMElement|null $parent The element we should append this DSAKeyValue to.
* @return \DOMElement
*/
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

$this->getP()?->toXML($e);
$this->getQ()?->toXML($e);
$this->getG()?->toXML($e);
$this->getY()->toXML($e);
$this->getJ()?->toXML($e);
$this->getSeed()?->toXML($e);
$this->getPgenCounter()?->toXML($e);

return $e;
}
}
14 changes: 14 additions & 0 deletions src/XML/ds/DSAKeyValue.php
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:DSAKeyValue element.
*
* @package simplesaml/xml-security
*/
final class DSAKeyValue extends AbstractDSAKeyValueType
{
}
26 changes: 26 additions & 0 deletions src/XML/ds/G.php
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:G element.
*
* @package simplesaml/xml-security
*/
final class G extends AbstractDsElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
26 changes: 26 additions & 0 deletions src/XML/ds/J.php
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:J element.
*
* @package simplesaml/xml-security
*/
final class J extends AbstractDsElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
26 changes: 26 additions & 0 deletions src/XML/ds/P.php
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:P element.
*
* @package simplesaml/xml-security
*/
final class P extends AbstractDsElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
26 changes: 26 additions & 0 deletions src/XML/ds/PgenCounter.php
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:PgenCounter element.
*
* @package simplesaml/xml-security
*/
final class PgenCounter extends AbstractDsElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
26 changes: 26 additions & 0 deletions src/XML/ds/Q.php
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:Q element.
*
* @package simplesaml/xml-security
*/
final class Q extends AbstractDsElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
26 changes: 26 additions & 0 deletions src/XML/ds/Seed.php
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:seed element.
*
* @package simplesaml/xml-security
*/
final class Seed extends AbstractDsElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
Loading

0 comments on commit ab12a34

Please sign in to comment.