Skip to content

Commit 5a73f15

Browse files
committed
Use xsd-types in new dsig11-classes
1 parent b98def2 commit 5a73f15

Some content is hidden

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

52 files changed

+377
-693
lines changed

src/XML/ds/KeyValue.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\XML\Chunk;
10-
use SimpleSAML\XML\ElementInterface;
1110
use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException};
1211
use SimpleSAML\XML\ExtendableElementTrait;
1312
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};

src/XML/dsig11/A.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace SimpleSAML\XMLSecurity\XML\dsig11;
66

7-
use SimpleSAML\XML\Base64ElementTrait;
7+
use SimpleSAML\XML\TypedTextContentTrait;
8+
use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue;
89

910
/**
1011
* Class representing a dsig11:A element.
@@ -13,17 +14,8 @@
1314
*/
1415
final class A extends AbstractDsig11Element
1516
{
16-
use Base64ElementTrait;
17+
use TypedTextContentTrait;
1718

18-
19-
/**
20-
* Initialize a A element.
21-
*
22-
* @param string $value
23-
*/
24-
public function __construct(
25-
string $value,
26-
) {
27-
$this->setContent($value);
28-
}
19+
/** @var string */
20+
public const TEXTCONTENT_TYPE = CryptoBinaryValue::class;
2921
}

src/XML/dsig11/AbstractECKeyValueType.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use DOMElement;
88
use SimpleSAML\XML\Assert\Assert;
99
use SimpleSAML\XML\Exception\SchemaViolationException;
10+
use SimpleSAML\XML\Type\IDValue;
11+
12+
use function strval;
1013

1114
/**
1215
* Abstract class representing a dsig11:ECKeyValueType
@@ -19,17 +22,16 @@ abstract class AbstractECKeyValueType extends AbstractDsig11Element
1922
* Initialize a FieldIDType element.
2023
*
2124
* @param \SimpleSAML\XMLSecurity\XML\dsig11\PublicKey $publicKey
22-
* @param string|null $id
25+
* @param \SimpleSAML\XML\Type\IDValue|null $id
2326
* @param \SimpleSAML\XMLSecurity\XML\dsig11\ECParameters|null $ecParameters
2427
* @param \SimpleSAML\XMLSecurity\XML\dsig11\NamedCurve|null $namedCurve
2528
*/
2629
public function __construct(
2730
protected PublicKey $publicKey,
28-
protected ?string $id = null,
31+
protected ?IDValue $id = null,
2932
protected ?ECParameters $ecParameters = null,
3033
protected ?NamedCurve $namedCurve = null,
3134
) {
32-
Assert::validNCName($id, SchemaViolationException::class);
3335
Assert::oneOf(
3436
null,
3537
[$ecParameters, $namedCurve],
@@ -75,9 +77,9 @@ public function getPublicKey(): PublicKey
7577
/**
7678
* Collect the value of the id-property
7779
*
78-
* @return string|null
80+
* @return \SimpleSAML\XML\Type\IDValue|null
7981
*/
80-
public function getId(): ?string
82+
public function getId(): ?IDValue
8183
{
8284
return $this->id;
8385
}
@@ -94,7 +96,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
9496
$e = $this->instantiateParentElement($parent);
9597

9698
if ($this->getId() !== null) {
97-
$e->setAttribute('Id', $this->getId());
99+
$e->setAttribute('Id', strval($this->getId()));
98100
}
99101

100102
$this->getECParameters()?->toXML($e);

src/XML/dsig11/AbstractECValidationDataType.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
namespace SimpleSAML\XMLSecurity\XML\dsig11;
66

77
use DOMElement;
8-
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\XML\Exception\SchemaViolationException;
8+
use SimpleSAML\XML\Type\AnyURIValue;
9+
10+
use function strval;
1011

1112
/**
1213
* Abstract class representing a dsig11:ECValidationDataType
@@ -19,13 +20,12 @@ abstract class AbstractECValidationDataType extends AbstractDsig11Element
1920
* Initialize a ECValidationDataType element.
2021
*
2122
* @param \SimpleSAML\XMLSecurity\XML\dsig11\Seed $seed
22-
* @param string $hashAlgorithm
23+
* @param \SimpleSAML\XML\Type\AnyURIValue $hashAlgorithm
2324
*/
2425
public function __construct(
2526
protected Seed $seed,
26-
protected string $hashAlgorithm,
27+
protected AnyURIValue $hashAlgorithm,
2728
) {
28-
Assert::validURI($hashAlgorithm, SchemaViolationException::class);
2929
}
3030

3131

@@ -43,9 +43,9 @@ public function getSeed(): Seed
4343
/**
4444
* Collect the value of the hashAlgorithm-property
4545
*
46-
* @return string
46+
* @return \SimpleSAML\XML\Type\AnyURIValue
4747
*/
48-
public function getHashAlgorithm(): string
48+
public function getHashAlgorithm(): AnyURIValue
4949
{
5050
return $this->hashAlgorithm;
5151
}
@@ -60,7 +60,7 @@ public function getHashAlgorithm(): string
6060
public function toXML(?DOMElement $parent = null): DOMElement
6161
{
6262
$e = $this->instantiateParentElement($parent);
63-
$e->setAttribute('hashAlgorithm', $this->getHashAlgorithm());
63+
$e->setAttribute('hashAlgorithm', strval($this->getHashAlgorithm()));
6464

6565
$this->getSeed()->toXML($e);
6666

src/XML/dsig11/AbstractNamedCurveType.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
namespace SimpleSAML\XMLSecurity\XML\dsig11;
66

77
use DOMElement;
8-
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\XML\Exception\SchemaViolationException;
8+
use SimpleSAML\XML\Type\AnyURIValue;
9+
10+
use function strval;
1011

1112
/**
1213
* Abstract class representing a dsig11:NamedCurveType
@@ -18,21 +19,20 @@ abstract class AbstractNamedCurveType extends AbstractDsig11Element
1819
/**
1920
* Initialize a NamedCurveType element.
2021
*
21-
* @param string $URI
22+
* @param \SimpleSAML\XML\Type\AnyURIValue $URI
2223
*/
2324
public function __construct(
24-
protected string $URI,
25+
protected AnyURIValue $URI,
2526
) {
26-
Assert::validURI($URI, SchemaViolationException::class);
2727
}
2828

2929

3030
/**
3131
* Collect the value of the URI-property
3232
*
33-
* @return string
33+
* @return \SimpleSAML\XML\Type\AnyURIValue
3434
*/
35-
public function getURI(): string
35+
public function getURI(): AnyURIValue
3636
{
3737
return $this->URI;
3838
}
@@ -47,7 +47,7 @@ public function getURI(): string
4747
public function toXML(?DOMElement $parent = null): DOMElement
4848
{
4949
$e = $this->instantiateParentElement($parent);
50-
$e->setAttribute('URI', $this->getURI());
50+
$e->setAttribute('URI', strval($this->getURI()));
5151

5252
return $e;
5353
}

src/XML/dsig11/B.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace SimpleSAML\XMLSecurity\XML\dsig11;
66

7-
use SimpleSAML\XML\Base64ElementTrait;
7+
use SimpleSAML\XML\TypedTextContentTrait;
8+
use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue;
89

910
/**
1011
* Class representing a dsig11:B element.
@@ -13,17 +14,8 @@
1314
*/
1415
final class B extends AbstractDsig11Element
1516
{
16-
use Base64ElementTrait;
17+
use TypedTextContentTrait;
1718

18-
19-
/**
20-
* Initialize a B element.
21-
*
22-
* @param string $value
23-
*/
24-
public function __construct(
25-
string $value,
26-
) {
27-
$this->setContent($value);
28-
}
19+
/** @var string */
20+
public const TEXTCONTENT_TYPE = CryptoBinaryValue::class;
2921
}

src/XML/dsig11/Base.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace SimpleSAML\XMLSecurity\XML\dsig11;
66

7-
use SimpleSAML\XML\Base64ElementTrait;
7+
use SimpleSAML\XML\TypedTextContentTrait;
8+
use SimpleSAML\XMLSecurity\Type\ECPointValue;
89

910
/**
1011
* Class representing a dsig11:Base element.
@@ -13,17 +14,8 @@
1314
*/
1415
final class Base extends AbstractDsig11Element
1516
{
16-
use Base64ElementTrait;
17+
use TypedTextContentTrait;
1718

18-
19-
/**
20-
* Initialize a Base element.
21-
*
22-
* @param string $value
23-
*/
24-
public function __construct(
25-
string $value,
26-
) {
27-
$this->setContent($value);
28-
}
19+
/** @var string */
20+
public const TEXTCONTENT_TYPE = ECPointValue::class;
2921
}

src/XML/dsig11/CoFactor.php

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44

55
namespace SimpleSAML\XMLSecurity\XML\dsig11;
66

7-
use DOMElement;
8-
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\SchemaViolationException;
11-
12-
use function intval;
13-
use function strval;
7+
use SimpleSAML\XML\Type\IntegerValue;
8+
use SimpleSAML\XML\TypedTextContentTrait;
149

1510
/**
1611
* Class representing a dsig11:CoFactor element.
@@ -19,55 +14,8 @@
1914
*/
2015
final class CoFactor extends AbstractDsig11Element
2116
{
22-
/**
23-
* @param int $value
24-
*/
25-
public function __construct(
26-
protected int $value,
27-
) {
28-
Assert::positiveInteger($value, SchemaViolationException::class);
29-
}
30-
31-
32-
/**
33-
* @return int
34-
*/
35-
public function getValue(): int
36-
{
37-
return $this->value;
38-
}
39-
40-
41-
/**
42-
* Convert XML into a class instance
43-
*
44-
* @param \DOMElement $xml The XML element we should load
45-
* @return static
46-
*
47-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
48-
* If the qualified name of the supplied element is wrong
49-
*/
50-
public static function fromXML(DOMElement $xml): static
51-
{
52-
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
53-
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
54-
Assert::numeric($xml->textContent);
55-
56-
return new static(intval($xml->textContent));
57-
}
58-
59-
60-
/**
61-
* Convert this element to XML.
62-
*
63-
* @param \DOMElement|null $parent The element we should append this element to.
64-
* @return \DOMElement
65-
*/
66-
public function toXML(?DOMElement $parent = null): DOMElement
67-
{
68-
$e = $this->instantiateParentElement($parent);
69-
$e->textContent = strval($this->getValue());
17+
use TypedTextContentTrait;
7018

71-
return $e;
72-
}
19+
/** @var string */
20+
public const TEXTCONTENT_TYPE = IntegerValue::class;
7321
}

src/XML/dsig11/Curve.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\MissingElementException;
11-
use SimpleSAML\XML\Exception\TooManyElementsException;
12-
use SimpleSAML\XMLSecurity\XML\dsig11\A;
13-
use SimpleSAML\XMLSecurity\XML\dsig11\B;
9+
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
10+
use SimpleSAML\XMLSecurity\XML\dsig11\{A, B};
11+
12+
use function array_pop;
1413

1514
/**
1615
* Class representing a dsig11:Curve element.

0 commit comments

Comments
 (0)