Skip to content

Commit b88f13d

Browse files
committed
Migrate to value types
1 parent feb95e1 commit b88f13d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+483
-610
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"ext-spl": "*",
4545

4646
"simplesamlphp/assert": "~1.8.0",
47-
"simplesamlphp/xml-common": "~1.24.0"
47+
"simplesamlphp/xml-common": "dev-feature/xsd-types"
4848
},
4949
"require-dev": {
5050
"simplesamlphp/simplesamlphp-test-framework": "~1.8.0"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Exception;
6+
7+
/**
8+
* This exception may be raised when a violation of the xmldsig specification is detected
9+
*
10+
* @package simplesamlphp/xml-security
11+
*/
12+
class ProtocolViolationException extends RuntimeException
13+
{
14+
/**
15+
* @param string|null $message
16+
*/
17+
public function __construct(?string $message = null)
18+
{
19+
if ($message === null) {
20+
if (defined('static::DEFAULT_MESSAGE')) {
21+
$message = static::DEFAULT_MESSAGE;
22+
} else {
23+
$message = 'A violation of the XML Signature Syntax and Processing specification occurred.';
24+
}
25+
}
26+
27+
parent::__construct($message);
28+
}
29+
}

src/XML/ds/AbstractDSAKeyValueType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
1111
use SimpleSAML\XML\Exception\TooManyElementsException;
12-
use SimpleSAML\XML\SchemaValidatableElementInterface;
13-
use SimpleSAML\XML\SchemaValidatableElementTrait;
12+
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
1413

1514
use function array_pop;
1615

src/XML/ds/AbstractKeyInfoType.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
use SimpleSAML\XML\Exception\SchemaViolationException;
99
use SimpleSAML\XML\ExtendableElementTrait;
1010
use SimpleSAML\XML\SerializableElementInterface;
11+
use SimpleSAML\XML\Type\IDValue;
1112
use SimpleSAML\XML\XsNamespace as NS;
1213
use SimpleSAML\XMLSecurity\Assert\Assert;
1314
use SimpleSAML\XMLSecurity\Constants as C;
1415
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
1516
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1617

18+
use function strval;
19+
1720
/**
1821
* Abstract class representing the KeyInfoType.
1922
*
@@ -44,7 +47,7 @@ abstract class AbstractKeyInfoType extends AbstractDsElement
4447
*/
4548
final public function __construct(
4649
protected array $info,
47-
protected ?string $Id = null,
50+
protected ?IDValue $Id = null,
4851
) {
4952
Assert::notEmpty(
5053
$info,
@@ -61,7 +64,6 @@ final public function __construct(
6164
SerializableElementInterface::class,
6265
InvalidArgumentException::class,
6366
);
64-
Assert::nullOrValidNCName($Id);
6567

6668
foreach ($info as $item) {
6769
if ($item instanceof AbstractDsElement) {
@@ -86,9 +88,9 @@ final public function __construct(
8688
/**
8789
* Collect the value of the Id-property
8890
*
89-
* @return string|null
91+
* @return \SimpleSAML\XML\Type\IDValue|null
9092
*/
91-
public function getId(): ?string
93+
public function getId(): ?IDValue
9294
{
9395
return $this->Id;
9496
}
@@ -116,7 +118,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
116118
$e = $this->instantiateParentElement($parent);
117119

118120
if ($this->getId() !== null) {
119-
$e->setAttribute('Id', $this->getId());
121+
$e->setAttribute('Id', strval($this->getId()));
120122
}
121123

122124
foreach ($this->getInfo() as $elt) {

src/XML/ds/AbstractPGPDataType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
1111
use SimpleSAML\XML\Exception\TooManyElementsException;
1212
use SimpleSAML\XML\ExtendableElementTrait;
13-
use SimpleSAML\XML\SchemaValidatableElementInterface;
14-
use SimpleSAML\XML\SchemaValidatableElementTrait;
13+
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
1514
use SimpleSAML\XML\XsNamespace as NS;
1615
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1716

src/XML/ds/AbstractSPKIDataType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
use SimpleSAML\XML\Exception\SchemaViolationException;
1212
use SimpleSAML\XML\Registry\ElementRegistry;
1313
use SimpleSAML\XML\SchemaValidatableElementInterface;
14-
use SimpleSAML\XML\SchemaValidatableElementTrait;
15-
use SimpleSAML\XML\SerializableElementInterface;
14+
use SimpleSAML\XML\{SchemaValidatableElementTrait, SerializableElementInterface};
1615
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1716

1817
/**

src/XML/ds/CanonicalizationMethod.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
11-
use SimpleSAML\XML\SchemaValidatableElementInterface;
12-
use SimpleSAML\XML\SchemaValidatableElementTrait;
11+
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
12+
use SimpleSAML\XML\Type\AnyURIValue;
1313
use SimpleSAML\XMLSecurity\Constants as C;
1414
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
1515

16+
use function strval;
17+
1618
/**
1719
* Class representing a ds:CanonicalizationMethod element.
1820
*
@@ -25,12 +27,11 @@ final class CanonicalizationMethod extends AbstractDsElement implements SchemaVa
2527
/**
2628
* Initialize a CanonicalizationMethod element.
2729
*
28-
* @param string $Algorithm
30+
* @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm
2931
*/
3032
public function __construct(
31-
protected string $Algorithm,
33+
protected AnyURIValue $Algorithm,
3234
) {
33-
Assert::validURI($Algorithm, SchemaViolationException::class);
3435
Assert::oneOf(
3536
$Algorithm,
3637
[
@@ -48,9 +49,9 @@ public function __construct(
4849
/**
4950
* Collect the value of the Algorithm-property
5051
*
51-
* @return string
52+
* @return \SimpleSAML\XML\Type\AnyURIValue
5253
*/
53-
public function getAlgorithm(): string
54+
public function getAlgorithm(): AnyURIValue
5455
{
5556
return $this->Algorithm;
5657
}
@@ -70,7 +71,7 @@ public static function fromXML(DOMElement $xml): static
7071
Assert::same($xml->localName, 'CanonicalizationMethod', InvalidDOMElementException::class);
7172
Assert::same($xml->namespaceURI, CanonicalizationMethod::NS, InvalidDOMElementException::class);
7273

73-
$Algorithm = CanonicalizationMethod::getAttribute($xml, 'Algorithm');
74+
$Algorithm = self::getAttribute($xml, 'Algorithm', AnyURIValue::class);
7475

7576
return new static($Algorithm);
7677
}
@@ -85,7 +86,7 @@ public static function fromXML(DOMElement $xml): static
8586
public function toXML(?DOMElement $parent = null): DOMElement
8687
{
8788
$e = $this->instantiateParentElement($parent);
88-
$e->setAttribute('Algorithm', $this->getAlgorithm());
89+
$e->setAttribute('Algorithm', strval($this->getAlgorithm()));
8990

9091
return $e;
9192
}

src/XML/ds/DigestMethod.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
1111
use SimpleSAML\XML\ExtendableElementTrait;
12-
use SimpleSAML\XML\SchemaValidatableElementInterface;
13-
use SimpleSAML\XML\SchemaValidatableElementTrait;
12+
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
13+
use SimpleSAML\XML\Type\AnyURIType;
1414
use SimpleSAML\XML\XsNamespace as NS;
1515
use SimpleSAML\XMLSecurity\Constants as C;
1616
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
@@ -30,14 +30,13 @@ final class DigestMethod extends AbstractDsElement implements SchemaValidatableE
3030
/**
3131
* Initialize a DigestMethod element.
3232
*
33-
* @param string $Algorithm
33+
* @param \SimpleSAML\XML\Type\AnyURIValuestring $Algorithm
3434
* @param list<\SimpleSAML\XML\SerializableElementInterface> $elements
3535
*/
3636
public function __construct(
37-
protected string $Algorithm,
37+
protected AnyURIValue $Algorithm,
3838
array $elements = [],
3939
) {
40-
Assert::validURI($Algorithm, SchemaViolationException::class);
4140
Assert::oneOf(
4241
$Algorithm,
4342
array_keys(C::$DIGEST_ALGORITHMS),
@@ -52,9 +51,9 @@ public function __construct(
5251
/**
5352
* Collect the value of the Algorithm-property
5453
*
55-
* @return string
54+
* @return \SimpleSAML\XML\Type\AnyURIValue
5655
*/
57-
public function getAlgorithm(): string
56+
public function getAlgorithm(): AnyURIValue
5857
{
5958
return $this->Algorithm;
6059
}
@@ -74,7 +73,7 @@ public static function fromXML(DOMElement $xml): static
7473
Assert::same($xml->localName, 'DigestMethod', InvalidDOMElementException::class);
7574
Assert::same($xml->namespaceURI, DigestMethod::NS, InvalidDOMElementException::class);
7675

77-
$Algorithm = DigestMethod::getAttribute($xml, 'Algorithm');
76+
$Algorithm = self::getAttribute($xml, 'Algorithm', AnyURIValue::class);
7877
$elements = self::getChildElementsFromXML($xml);
7978

8079
return new static($Algorithm, $elements);
@@ -90,7 +89,7 @@ public static function fromXML(DOMElement $xml): static
9089
public function toXML(?DOMElement $parent = null): DOMElement
9190
{
9291
$e = $this->instantiateParentElement($parent);
93-
$e->setAttribute('Algorithm', $this->getAlgorithm());
92+
$e->setAttribute('Algorithm', strval($this->getAlgorithm()));
9493

9594
foreach ($this->elements as $elt) {
9695
if (!$elt->isEmptyElement()) {

src/XML/ds/DigestValue.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace SimpleSAML\XMLSecurity\XML\ds;
66

7-
use SimpleSAML\XML\Base64ElementTrait;
8-
use SimpleSAML\XML\SchemaValidatableElementInterface;
9-
use SimpleSAML\XML\SchemaValidatableElementTrait;
7+
use SimpleSAML\XML\Type\Base64BinaryValue;
8+
use SimpleSAML\XML\TypedTextContentTrait;
9+
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
1010

1111
/**
1212
* Class representing a ds:DigestValue element.
@@ -15,15 +15,9 @@
1515
*/
1616
final class DigestValue extends AbstractDsElement implements SchemaValidatableElementInterface
1717
{
18-
use Base64ElementTrait;
1918
use SchemaValidatableElementTrait;
19+
use TypedTextContentTrait;
2020

21-
22-
/**
23-
* @param string $content
24-
*/
25-
public function __construct(string $content)
26-
{
27-
$this->setContent($content);
28-
}
21+
/** @var string */
22+
public const TEXTCONTENT_TYPE = Base64BinaryValue::class;
2923
}

0 commit comments

Comments
 (0)