-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert this project to TypeScript (#325)
- Loading branch information
Showing
19 changed files
with
1,233 additions
and
907 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,55 @@ | ||
const xpath = require("xpath"); | ||
const utils = require("./utils"); | ||
import * as xpath from "xpath"; | ||
|
||
/** | ||
* @type { import("../index.d.ts").CanonicalizationOrTransformationAlgorithm} | ||
*/ | ||
class EnvelopedSignature { | ||
process(node, options) { | ||
import type { | ||
CanonicalizationOrTransformationAlgorithm, | ||
CanonicalizationOrTransformationAlgorithmProcessOptions, | ||
CanonicalizationOrTransformAlgorithmType, | ||
} from "./types"; | ||
|
||
export class EnvelopedSignature implements CanonicalizationOrTransformationAlgorithm { | ||
includeComments = false; | ||
process(node: Node, options: CanonicalizationOrTransformationAlgorithmProcessOptions) { | ||
if (null == options.signatureNode) { | ||
const signature = xpath.select( | ||
const signature = xpath.select1( | ||
"./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", | ||
node | ||
)[0]; | ||
if (signature) { | ||
); | ||
if (xpath.isNodeLike(signature) && signature.parentNode) { | ||
signature.parentNode.removeChild(signature); | ||
} | ||
return node; | ||
} | ||
const signatureNode = options.signatureNode; | ||
const expectedSignatureValue = utils.findFirst( | ||
signatureNode, | ||
".//*[local-name(.)='SignatureValue']/text()" | ||
).data; | ||
const signatures = xpath.select( | ||
".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", | ||
node | ||
const expectedSignatureValue = xpath.select1( | ||
".//*[local-name(.)='SignatureValue']/text()", | ||
signatureNode | ||
); | ||
for (const nodeSignature of signatures) { | ||
const signatureValue = utils.findFirst( | ||
nodeSignature, | ||
".//*[local-name(.)='SignatureValue']/text()" | ||
).data; | ||
if (expectedSignatureValue === signatureValue) { | ||
nodeSignature.parentNode.removeChild(nodeSignature); | ||
if (xpath.isTextNode(expectedSignatureValue)) { | ||
const expectedSignatureValueData = expectedSignatureValue.data; | ||
|
||
const signatures = xpath.select( | ||
".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", | ||
node | ||
); | ||
for (const nodeSignature of Array.isArray(signatures) ? signatures : []) { | ||
const signatureValue = xpath.select1( | ||
".//*[local-name(.)='SignatureValue']/text()", | ||
nodeSignature | ||
); | ||
if (xpath.isTextNode(signatureValue)) { | ||
const signatureValueData = signatureValue.data; | ||
if (expectedSignatureValueData === signatureValueData) { | ||
if (nodeSignature.parentNode) { | ||
nodeSignature.parentNode.removeChild(nodeSignature); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return node; | ||
} | ||
|
||
getAlgorithmName() { | ||
getAlgorithmName(): CanonicalizationOrTransformAlgorithmType { | ||
return "http://www.w3.org/2000/09/xmldsig#enveloped-signature"; | ||
} | ||
} | ||
|
||
module.exports = { | ||
EnvelopedSignature, | ||
}; |
Oops, something went wrong.