Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/ts-convert-polish' into ts-con…
Browse files Browse the repository at this point in the history
…vert
  • Loading branch information
cjbarth committed Jul 17, 2023
2 parents b77f993 + c9ba5b6 commit 9109b6a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/c14n-canonicalization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
CanonicalizationOrTransformationAlgorithm,
CanonicalizationOrTransformationAlgorithmProcessOptions,
NamespacePrefix,
Expand Down
2 changes: 1 addition & 1 deletion src/enveloped-signature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as xpath from "xpath";

import {
import type {
CanonicalizationOrTransformationAlgorithm,
CanonicalizationOrTransformationAlgorithmProcessOptions,
CanonicalizationOrTransformAlgorithmType,
Expand Down
2 changes: 1 addition & 1 deletion src/exclusive-canonicalization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
CanonicalizationOrTransformationAlgorithm,
CanonicalizationOrTransformationAlgorithmProcessOptions,
NamespacePrefix,
Expand Down
2 changes: 1 addition & 1 deletion src/hash-algorithms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from "crypto";
import { HashAlgorithm } from "./types";
import type { HashAlgorithm } from "./types";

export class Sha1 implements HashAlgorithm {
getHash = function (xml) {
Expand Down
2 changes: 1 addition & 1 deletion src/signature-algorithms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from "crypto";
import { SignatureAlgorithm, createOptionalCallbackFunction } from "./types";
import { type SignatureAlgorithm, createOptionalCallbackFunction } from "./types";

export class RsaSha1 implements SignatureAlgorithm {
getSignature = createOptionalCallbackFunction(
Expand Down
2 changes: 1 addition & 1 deletion src/signed-xml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
CanonicalizationAlgorithmType,
CanonicalizationOrTransformationAlgorithm,
ComputeSignatureOptions,
Expand Down
13 changes: 7 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as xpath from "xpath";
import { NamespacePrefix } from "./types";
import type { NamespacePrefix } from "./types";

export function isArrayHasLength(array: unknown): array is unknown[] {
return Array.isArray(array) && array.length > 0;
Expand Down Expand Up @@ -207,6 +207,10 @@ function findNSPrefix(subset) {
return subset.prefix || "";
}

function isElementSubset(docSubset: Node[]): docSubset is Element[] {
return docSubset.every((node) => xpath.isElement(node))
}

/**
* Extract ancestor namespaces in order to import it to root of document subset
* which is being canonicalized for non-exclusive c14n.
Expand All @@ -222,20 +226,17 @@ export function findAncestorNs(
namespaceResolver?: XPathNSResolver
) {
const docSubset = xpath.selectWithResolver(docSubsetXpath, doc, namespaceResolver);
let elementSubset: Element[] = [];

if (!isArrayHasLength(docSubset)) {
return [];
}

if (!docSubset.every((node) => xpath.isElement(node))) {
if (!isElementSubset(docSubset)) {
throw new Error("Document subset must be list of elements");
} else {
elementSubset = docSubset as Element[];
}

// Remove duplicate on ancestor namespace
const ancestorNs = collectAncestorNamespaces(elementSubset[0]);
const ancestorNs = collectAncestorNamespaces(docSubset[0]);
const ancestorNsWithoutDuplicate: NamespacePrefix[] = [];
for (let i = 0; i < ancestorNs.length; i++) {
let notOnTheList = true;
Expand Down

0 comments on commit 9109b6a

Please sign in to comment.