-
Notifications
You must be signed in to change notification settings - Fork 191
Convert this project to TypeScript #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ef0388
Migrate to TS
cjbarth b77f993
lint
cjbarth 493e7bf
Limit imports from `./types` to type where applicable
LoneRifle c9ba5b6
findAncestorNs: replace type coercion with type guard
LoneRifle 9109b6a
Merge remote-tracking branch 'upstream/ts-convert-polish' into ts-con…
cjbarth 68241b6
Remove support for older Node
cjbarth c880789
export correctly
cjbarth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.