Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ext-spl": "*",

"simplesamlphp/assert": "~1.9",
"simplesamlphp/xml-common": "~2.3"
"simplesamlphp/xml-common": "~2.4"
},
"require-dev": {
"simplesamlphp/simplesamlphp-test-framework": "~1.10"
Expand Down
33 changes: 5 additions & 28 deletions src/Utils/XPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

namespace SimpleSAML\XMLSecurity\Utils;

use DOMDocument;
use DOMElement;
use DOMNode;
use DOMXPath;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
use SimpleSAML\XPath\XPath as XPathUtils;

/**
Expand All @@ -23,38 +20,18 @@ class XPath extends XPathUtils
* Get a DOMXPath object that can be used to search for XMLDSIG elements.
*
* @param \DOMNode $node The document to associate to the DOMXPath object.
* @param bool $autoregister Whether to auto-register all namespaces used in the document
*
* @return \DOMXPath A DOMXPath object ready to use in the given document, with the XMLDSIG namespace already
* registered.
*/
public static function getXPath(DOMNode $node): DOMXPath
public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath
{
$xp = parent::getXPath($node);
$xp = parent::getXPath($node, $autoregister);

$xp->registerNamespace('ds', C::NS_XDSIG);
$xp->registerNamespace('xenc', C::NS_XENC);
return $xp;
}


/**
* Search for an element with a certain name among the children of a reference element.
*
* @param \DOMNode $ref The DOMDocument or DOMElement where encrypted data is expected to be found as a child.
* @param string $name The name (possibly prefixed) of the element we are looking for.
*
* @return \DOMElement|false The element we are looking for, or false when not found.
*
* @throws \SimpleSAML\XMLSecurity\Exception\RuntimeException If no DOM document is available.
*/
public static function findElement(DOMNode $ref, string $name): DOMElement|false
{
$doc = $ref instanceof DOMDocument ? $ref : $ref->ownerDocument;
if ($doc === null) {
throw new RuntimeException('Cannot search, no DOMDocument available');
}

$nodeset = self::getXPath($doc)->query('./' . $name, $ref);

return $nodeset->item(0) ?? false;
return $xp;
}
}