Skip to content

Commit 797c984

Browse files
committed
Implement DOM schema validation
1 parent 92e2831 commit 797c984

File tree

93 files changed

+242
-178
lines changed

Some content is hidden

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

93 files changed

+242
-178
lines changed

src/Utils/XML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static function processTransforms(
106106
if ($xpath !== null) {
107107
$arXPath = [];
108108
$arXPath['query'] = '(.//. | .//@* | .//namespace::*)[' . $xpath->getExpression() . ']';
109-
$arXpath['namespaces'] = $xpath->getNamespaces();
109+
// $arXpath['namespaces'] = $xpath->getNamespaces();
110110
// TODO: review if $nsnode->localName is equivalent to the keys in getNamespaces()
111111
// $nslist = $xp->query('./namespace::*', $node);
112112
// foreach ($nslist as $nsnode) {

src/XML/ds/AbstractDSAKeyValueType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
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;
1214

1315
use function array_pop;
1416

@@ -17,8 +19,10 @@
1719
*
1820
* @package simplesamlphp/xml-security
1921
*/
20-
abstract class AbstractDSAKeyValueType extends AbstractDsElement
22+
abstract class AbstractDSAKeyValueType extends AbstractDsElement implements SchemaValidatableElementInterface
2123
{
24+
use SchemaValidatableElementTrait;
25+
2226
/**
2327
* DSAKeyValueType constructor.
2428
*

src/XML/ds/AbstractDsElement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ abstract class AbstractDsElement extends AbstractElement
1919

2020
/** @var string */
2121
public const NS_PREFIX = 'ds';
22+
23+
/** @var string */
24+
public const SCHEMA = 'resources/schemas/xmldsig-core-schema.xsd';
2225
}

src/XML/ds/AbstractPGPDataType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
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;
1315
use SimpleSAML\XML\XsNamespace as NS;
1416
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1517

@@ -20,9 +22,10 @@
2022
*
2123
* @package simplesamlphp/xml-security
2224
*/
23-
abstract class AbstractPGPDataType extends AbstractDsElement
25+
abstract class AbstractPGPDataType extends AbstractDsElement implements SchemaValidatableElementInterface
2426
{
2527
use ExtendableElementTrait;
28+
use SchemaValidatableElementTrait;
2629

2730
/** @var \SimpleSAML\XML\XsNamespace */
2831
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;

src/XML/ds/AbstractSPKIDataType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1111
use SimpleSAML\XML\Exception\SchemaViolationException;
1212
use SimpleSAML\XML\Registry\ElementRegistry;
13+
use SimpleSAML\XML\SchemaValidatableElementInterface;
14+
use SimpleSAML\XML\SchemaValidatableElementTrait;
1315
use SimpleSAML\XML\SerializableElementInterface;
1416
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1517

@@ -18,8 +20,10 @@
1820
*
1921
* @package simplesamlphp/xml-security
2022
*/
21-
abstract class AbstractSPKIDataType extends AbstractDsElement
23+
abstract class AbstractSPKIDataType extends AbstractDsElement implements SchemaValidatableElementInterface
2224
{
25+
use SchemaValidatableElementTrait;
26+
2327
/**
2428
* Initialize a SPKIData element.
2529
*

src/XML/ds/CanonicalizationMethod.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
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;
1113
use SimpleSAML\XMLSecurity\Constants as C;
1214
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
1315

@@ -16,8 +18,10 @@
1618
*
1719
* @package simplesamlphp/xml-security
1820
*/
19-
final class CanonicalizationMethod extends AbstractDsElement
21+
final class CanonicalizationMethod extends AbstractDsElement implements SchemaValidatableElementInterface
2022
{
23+
use SchemaValidatableElementTrait;
24+
2125
/**
2226
* Initialize a CanonicalizationMethod element.
2327
*

src/XML/ds/DigestMethod.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +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;
1214
use SimpleSAML\XML\XsNamespace as NS;
1315
use SimpleSAML\XMLSecurity\Constants as C;
1416
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
@@ -18,9 +20,10 @@
1820
*
1921
* @package simplesamlphp/xml-security
2022
*/
21-
final class DigestMethod extends AbstractDsElement
23+
final class DigestMethod extends AbstractDsElement implements SchemaValidatableElementInterface
2224
{
2325
use ExtendableElementTrait;
26+
use SchemaValidatableElementTrait;
2427

2528
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
2629

src/XML/ds/DigestValue.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
namespace SimpleSAML\XMLSecurity\XML\ds;
66

77
use SimpleSAML\XML\Base64ElementTrait;
8+
use SimpleSAML\XML\SchemaValidatableElementInterface;
9+
use SimpleSAML\XML\SchemaValidatableElementTrait;
810

911
/**
1012
* Class representing a ds:DigestValue element.
1113
*
1214
* @package simplesaml/xml-security
1315
*/
14-
final class DigestValue extends AbstractDsElement
16+
final class DigestValue extends AbstractDsElement implements SchemaValidatableElementInterface
1517
{
1618
use Base64ElementTrait;
19+
use SchemaValidatableElementTrait;
1720

1821

1922
/**

src/XML/ds/DsObject.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\ExtendableElementTrait;
11+
use SimpleSAML\XML\SchemaValidatableElementInterface;
12+
use SimpleSAML\XML\SchemaValidatableElementTrait;
1113
use SimpleSAML\XML\XsNamespace as NS;
1214

1315
/**
1416
* Class representing a ds:Object element.
1517
*
1618
* @package simplesamlphp/xml-security
1719
*/
18-
final class DsObject extends AbstractDsElement
20+
final class DsObject extends AbstractDsElement implements SchemaValidatableElementInterface
1921
{
2022
use ExtendableElementTrait;
23+
use SchemaValidatableElementTrait;
2124

2225
/** @var string */
2326
public const LOCALNAME = 'Object';

src/XML/ds/KeyInfo.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use DOMElement;
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10+
use SimpleSAML\XML\SchemaValidatableElementInterface;
11+
use SimpleSAML\XML\SchemaValidatableElementTrait;
1012

1113
use function array_merge;
1214

@@ -15,8 +17,10 @@
1517
*
1618
* @package simplesamlphp/xml-security
1719
*/
18-
final class KeyInfo extends AbstractKeyInfoType
20+
final class KeyInfo extends AbstractKeyInfoType implements SchemaValidatableElementInterface
1921
{
22+
use SchemaValidatableElementTrait;
23+
2024
/**
2125
* Convert XML into a KeyInfo
2226
*

0 commit comments

Comments
 (0)