Skip to content

Commit a6cd55c

Browse files
committed
fix: correct maxTransforms check to handle zero as a valid limit
refactor: consistent naming
1 parent 8fd99f2 commit a6cd55c

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/signed-xml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ export class SignedXml {
804804
? refNode.getAttribute("URI") || undefined
805805
: undefined;
806806

807-
if (this.maxTransforms) {
807+
if (this.maxTransforms !== null) {
808808
if (transforms.length > this.maxTransforms) {
809809
throw new Error(
810810
`Number of transforms (${transforms.length}) exceeds the maximum allowed (${this.maxTransforms})`,

src/xmldsig-validator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ export class XmlDSigValidator {
108108
private readonly truststore: KeyObject[] | undefined;
109109

110110
/**
111-
* Creates a new XmlValidator instance. The instance can be reused for multiple validations.
111+
* Creates a new XmlDSigValidator instance. The instance can be reused for multiple validations.
112112
*
113113
* @param options Configuration options for validation
114114
*/
115115
constructor(options: Partial<XmlDSigValidatorOptions>) {
116116
if (!options.keySelector) {
117-
throw new Error("XmlValidator requires a keySelector in options.");
117+
throw new Error("XmlDSigValidator requires a keySelector in options.");
118118
}
119119
this.options = {
120120
...options,
@@ -211,7 +211,7 @@ export class XmlDSigValidator {
211211
!("getCertFromKeyInfo" in this.options.keySelector)
212212
) {
213213
throw new Error(
214-
"XmlValidator requires either a publicCert or getCertFromKeyInfo function in options.",
214+
"XmlDSigValidator requires either a publicCert or getCertFromKeyInfo function in options.",
215215
);
216216
}
217217

test/xmldsig-validator.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function createMultiSignedXml(xml: string): string {
7373
return sig2.getSignedXml();
7474
}
7575

76-
describe("XmlValidator", function () {
76+
describe("XmlDSigValidator", function () {
7777
describe("constructor", function () {
7878
it("should create validator with public certificate", function () {
7979
const validator = new XmlDSigValidator({
@@ -113,7 +113,7 @@ describe("XmlValidator", function () {
113113

114114
it("should throw error when keySelector is missing", function () {
115115
expect(() => new XmlDSigValidator({})).to.throw(
116-
"XmlValidator requires a keySelector in options.",
116+
"XmlDSigValidator requires a keySelector in options.",
117117
);
118118
});
119119
});
@@ -284,7 +284,7 @@ describe("XmlValidator", function () {
284284
});
285285
});
286286

287-
describe("XmlValidator Certificate Expiration", function () {
287+
describe("XmlDSigValidator Certificate Expiration", function () {
288288
it("should reject expired certificate when checkCertExpiration is true", function () {
289289
const xml = "<root><test>content</test></root>";
290290

@@ -396,7 +396,7 @@ describe("XmlValidator Certificate Expiration", function () {
396396
});
397397
});
398398

399-
describe("XmlValidator Security Features", function () {
399+
describe("XmlDSigValidator Security Features", function () {
400400
it("should prevent signature wrapping attacks by only returning signed content", function () {
401401
const xml = "<root><test>content</test><unsigned>malicious</unsigned></root>";
402402
const signedXml = createSignedXml(xml);
@@ -458,7 +458,7 @@ describe("XmlValidator Security Features", function () {
458458
});
459459
});
460460

461-
describe("XmlValidator Truststore", function () {
461+
describe("XmlDSigValidator Truststore", function () {
462462
it("should validate document signed with chain certificate when root is in truststore", function () {
463463
const xml = "<root><test>content</test></root>";
464464

@@ -618,7 +618,7 @@ describe("XmlValidator Truststore", function () {
618618
});
619619
});
620620

621-
describe("XmlValidator Integration", function () {
621+
describe("XmlDSigValidator Integration", function () {
622622
it("should work with real-world signed XML documents", function () {
623623
// Test with a more complex XML structure
624624
const xml = `
@@ -680,11 +680,11 @@ describe("XmlValidator Integration", function () {
680680
expect(result.signedReferences).to.have.length(1);
681681
});
682682

683-
it("should validate signatures created by XmlSigner", function () {
684-
// This test ensures compatibility between XmlSigner and XmlValidator
683+
it("should validate signatures created by XmlDSigSigner", function () {
684+
// This test ensures compatibility between XmlDSigSigner and XmlDSigValidator
685685
const xml = '<root><test id="test1">content</test></root>';
686686

687-
// Create signature using SignedXml (simulating XmlSigner output)
687+
// Create signature using SignedXml (simulating XmlDSigSigner output)
688688
const sig = new SignedXml({
689689
privateKey,
690690
canonicalizationAlgorithm: canonicalization.EXCLUSIVE_C14N,
@@ -700,7 +700,7 @@ describe("XmlValidator Integration", function () {
700700
sig.computeSignature(xml);
701701
const signedXml = sig.getSignedXml();
702702

703-
// Validate using XmlValidator
703+
// Validate using XmlDSigValidator
704704
const validator = new XmlDSigValidator({
705705
keySelector: { publicCert },
706706
});

0 commit comments

Comments
 (0)