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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ To verify xml documents:
- `loadSignature(signatureXml)` - loads the signature where:
- `signatureXml` - a string or node object (like an [xmldom](https://github.com/xmldom/xmldom) node) containing the xml representation of the signature
- `checkSignature(xml)` - validates the given xml document and returns `true` if the validation was successful
- `getSignedReferences()` - returns the canonical XML of each reference, only after `checkSignature` succeeds
- `validateElementAgainstReferences(elemOrXpath, doc)` - **[deprecated]** after `checkSignature` succeeds, use the XML that `getSignedReferences()` returns instead of nodes from the original document

## Customizing Algorithms

Expand Down
11 changes: 11 additions & 0 deletions src/signed-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const warnOriginalXmlWithIds = deprecate(
"XML_CRYPTO_GET_ORIGINAL_XML_WITH_IDS",
);

const warnValidateElementAgainstReferences = deprecate(
() => {},
"`validateElementAgainstReferences()` is deprecated and will be removed in a future version. After `checkSignature()` succeeds, use the XML that `getSignedReferences()` returns instead of nodes from the original document.",
"XML_CRYPTO_VALIDATE_ELEMENT_AGAINST_REFERENCES",
);

export class SignedXml {
idMode?: "wssecurity";
idAttributes: string[];
Expand Down Expand Up @@ -503,7 +509,12 @@ export class SignedXml {
}
}

/**
* @deprecated Will be removed in a future version. After {@link checkSignature} succeeds, use
* the XML that {@link getSignedReferences} returns instead of nodes from the original document.
*/
validateElementAgainstReferences(elemOrXpath: Element | string, doc: Document): Reference {
warnValidateElementAgainstReferences();
let elem: Element;
if (typeof elemOrXpath === "string") {
const firstElem = xpath.select1(elemOrXpath, doc);
Expand Down
1 change: 1 addition & 0 deletions test/signature-unit-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ describe("Signature unit tests", function () {

const firstGrandchild = doc.firstChild?.firstChild;
isDomNode.assertIsElementNode(firstGrandchild);
/* eslint-disable-next-line deprecation/deprecation */
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const matchedReference = sig.validateElementAgainstReferences(firstGrandchild, doc);
expect(matchedReference).to.not.be.false;

Expand Down