From f349654eabb4026f1dd0c01b8db1737d0cd2a383 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 24 May 2023 09:39:15 +0200 Subject: [PATCH] Add support for appending attributes to KeyInfo element --- index.d.ts | 1 + lib/signed-xml.js | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 2166a10a..29850ee8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -79,6 +79,7 @@ export class SignedXml { export interface KeyInfo { getKey(keyInfo?: Node[] | null): Buffer; getKeyInfo(key?: string, prefix?: string): string; + attrs?: {[key: string]: any} | undefined; } export class FileKeyInfo implements KeyInfo { diff --git a/lib/signed-xml.js b/lib/signed-xml.js index f582bb19..d1c13ff5 100644 --- a/lib/signed-xml.js +++ b/lib/signed-xml.js @@ -845,7 +845,13 @@ SignedXml.prototype.getKeyInfo = function(prefix) { currentPrefix = currentPrefix ? currentPrefix + ':' : currentPrefix if (this.keyInfoProvider) { - res += "<" + currentPrefix + "KeyInfo>" + var keyInfoAttrs = "" + if (this.keyInfoProvider.attrs) { + Object.keys(this.keyInfoProvider.attrs).forEach((name) => { + keyInfoAttrs += " " + name + "=\"" + this.keyInfoProvider.attrs[name] + "\"" + }) + } + res += "<" + currentPrefix + "KeyInfo" + keyInfoAttrs + ">" res += this.keyInfoProvider.getKeyInfo(this.signingCert || this.signingKey, prefix) res += "" }