From ca13069f5e2a5c8451fde6c6c57a683887ee84e6 Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Thu, 27 Jul 2023 06:28:24 -0400 Subject: [PATCH] Rename `findChilds()` to `findChildren()` (#363) --- src/exclusive-canonicalization.ts | 4 ++-- src/signed-xml.ts | 14 +++++++------- src/utils.ts | 7 ++++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/exclusive-canonicalization.ts b/src/exclusive-canonicalization.ts index 4bf1ed08..5be0a5c3 100644 --- a/src/exclusive-canonicalization.ts +++ b/src/exclusive-canonicalization.ts @@ -267,9 +267,9 @@ export class ExclusiveCanonicalization implements CanonicalizationOrTransformati * If the inclusiveNamespacesPrefixList has not been explicitly provided then look it up in CanonicalizationMethod/InclusiveNamespaces */ if (!utils.isArrayHasLength(inclusiveNamespacesPrefixList)) { - const CanonicalizationMethod = utils.findChilds(node, "CanonicalizationMethod"); + const CanonicalizationMethod = utils.findChildren(node, "CanonicalizationMethod"); if (CanonicalizationMethod.length !== 0) { - const inclusiveNamespaces = utils.findChilds( + const inclusiveNamespaces = utils.findChildren( CanonicalizationMethod[0], "InclusiveNamespaces", ); diff --git a/src/signed-xml.ts b/src/signed-xml.ts index 77f8d47f..13de8fbb 100644 --- a/src/signed-xml.ts +++ b/src/signed-xml.ts @@ -283,7 +283,7 @@ export class SignedXml { throw new Error("No signature found."); } - const signedInfo = utils.findChilds(this.signatureNode, "SignedInfo"); + const signedInfo = utils.findChildren(this.signatureNode, "SignedInfo"); if (signedInfo.length === 0) { throw new Error("could not find SignedInfo element in the message"); } @@ -516,7 +516,7 @@ export class SignedXml { * */ loadReference(ref) { - let nodes = utils.findChilds(ref, "DigestMethod"); + let nodes = utils.findChildren(ref, "DigestMethod"); if (nodes.length === 0) { throw new Error(`could not find DigestMethod in reference ${ref.toString()}`); } @@ -528,7 +528,7 @@ export class SignedXml { } const digestAlgo = attr.value; - nodes = utils.findChilds(ref, "DigestValue"); + nodes = utils.findChildren(ref, "DigestValue"); if (nodes.length === 0) { throw new Error(`could not find DigestValue node in reference ${ref.toString()}`); } @@ -540,10 +540,10 @@ export class SignedXml { const transforms: string[] = []; let inclusiveNamespacesPrefixList: string[] = []; - nodes = utils.findChilds(ref, "Transforms"); + nodes = utils.findChildren(ref, "Transforms"); if (nodes.length !== 0) { const transformsNode = nodes[0]; - const transformsAll = utils.findChilds(transformsNode, "Transform"); + const transformsAll = utils.findChildren(transformsNode, "Transform"); for (const transform of transformsAll) { const transformAttr = utils.findAttr(transform, "Algorithm"); @@ -553,7 +553,7 @@ export class SignedXml { } // This is a little strange, we are looking for children of the last child of `transformsNode` - const inclusiveNamespaces = utils.findChilds( + const inclusiveNamespaces = utils.findChildren( transformsAll[transformsAll.length - 1], "InclusiveNamespaces", ); @@ -799,7 +799,7 @@ export class SignedXml { } this.signatureNode = signatureDoc; - const signedInfoNodes = utils.findChilds(this.signatureNode, "SignedInfo"); + const signedInfoNodes = utils.findChildren(this.signatureNode, "SignedInfo"); if (signedInfoNodes.length === 0) { const err3 = new Error("could not find SignedInfo element in the message"); if (!callback) { diff --git a/src/utils.ts b/src/utils.ts index c1f886fe..3146cc5b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -30,7 +30,7 @@ export function findAttr(element: Element, localName: string, namespace?: string return null; } -export function findChilds(node: Node | Document, localName: string, namespace?: string) { +export function findChildren(node: Node | Document, localName: string, namespace?: string) { const element = (node as Document).documentElement ?? node; const res: Element[] = []; for (let i = 0; i < element.childNodes.length; i++) { @@ -46,6 +46,11 @@ export function findChilds(node: Node | Document, localName: string, namespace?: return res; } +/** @deprecated */ +export function findChilds(node: Node | Document, localName: string, namespace?: string) { + return findChildren(node, localName, namespace); +} + const xml_special_to_encoded_attribute = { "&": "&", "<": "<",