Skip to content

Commit

Permalink
Add support for tracking which notes have been validated
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth committed Sep 18, 2023
1 parent 3cf5e51 commit 16b81bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/signed-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export class SignedXml {
const validationError = new Error(
`invalid signature: the signature references an element with uri ${ref.uri} but could not find such element in the xml`,
);
ref.validationError = validationError;
this.validationErrors.push(validationError.message);
return false;
}
Expand All @@ -463,11 +464,20 @@ export class SignedXml {
const validationError = new Error(
`invalid signature: for uri ${ref.uri} calculated digest is ${digest} but the xml to validate supplies digest ${ref.digestValue}`,
);
ref.validationError = validationError;
this.validationErrors.push(validationError.message);

return false;
}

ref.getValidatedNode = () => {
if (typeof ref.xpath !== "string") {
return null;

Check warning on line 475 in src/signed-xml.ts

View check run for this annotation

Codecov / codecov/patch

src/signed-xml.ts#L475

Added line #L475 was not covered by tests
}
const selectedValue = xpath.select1(ref.xpath, doc);

Check warning on line 477 in src/signed-xml.ts

View check run for this annotation

Codecov / codecov/patch

src/signed-xml.ts#L477

Added line #L477 was not covered by tests
return isDomNode.isNodeLike(selectedValue) ? selectedValue : null;
};

return true;
}

Expand Down Expand Up @@ -657,6 +667,7 @@ export class SignedXml {
digestValue,
inclusiveNamespacesPrefixList,
isEmptyUri,
getValidatedNode: () => null,

Check warning on line 670 in src/signed-xml.ts

View check run for this annotation

Codecov / codecov/patch

src/signed-xml.ts#L670

Added line #L670 was not covered by tests
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export interface Reference {

// Optional. The type of the reference node.
ancestorNamespaces?: NamespacePrefix[];

validationError?: Error;

getValidatedNode(): Node | null;
}

/** Implement this to create a new CanonicalizationOrTransformationAlgorithm */
Expand Down

0 comments on commit 16b81bc

Please sign in to comment.