xml-crypto
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -0,45 +1,45 @@ | ||
/* jshint laxcomma: true */ | ||
var utils = require('./utils') | ||
, Dom = require('xmldom').DOMParser | ||
, Dom = require('xmldom').DOMParser; | ||
exports.ExclusiveCanonicalization = ExclusiveCanonicalization | ||
exports.ExclusiveCanonicalization = ExclusiveCanonicalization; | ||
function ExclusiveCanonicalization() { | ||
function ExclusiveCanonicalization() {} | ||
} | ||
ExclusiveCanonicalization.prototype.attrCompare = function(a,b) { | ||
if (!a.prefix && b.prefix) return -1; | ||
if (!b.prefix && a.prefix) return 1; | ||
return a.name.localeCompare(b.name); | ||
}; | ||
ExclusiveCanonicalization.prototype.attrCompare = function(a,b) { | ||
if (!a.prefix && b.prefix) return -1 | ||
if (!b.prefix && a.prefix) return 1 | ||
return a.name.localeCompare(b.name) | ||
} | ||
ExclusiveCanonicalization.prototype.nsCompare = function(a,b) { | ||
var attr1 = a.prefix+a.namespaceURI; | ||
var attr2 = b.prefix+b.namespaceURI; | ||
if (attr1 == attr2) return 0; | ||
return attr1.localeCompare(attr2); | ||
}; | ||
ExclusiveCanonicalization.prototype.nsCompare = function(a,b) { | ||
var attr1 = a.prefix+a.namespaceURI | ||
var attr2 = b.prefix+b.namespaceURI | ||
if (attr1 == attr2) return 0 | ||
return attr1.localeCompare(attr2) | ||
} | ||
ExclusiveCanonicalization.prototype.renderAttrs = function(node) { | ||
var res = "" | ||
var attrListToRender = [] | ||
var a, i, attr | ||
, res = [] | ||
, attrListToRender = []; | ||
if (node.attributes) { | ||
for (var i=0;i<node.attributes.length;i++) { | ||
var attr = node.attributes[i] | ||
for (i = 0; i < node.attributes.length; ++i) { | ||
attr = node.attributes[i]; | ||
//ignore namespace definition attributes | ||
if (attr.name.indexOf("xmlns")==0) continue; | ||
attrListToRender.push(attr) | ||
if (attr.name.indexOf("xmlns") === 0) continue; | ||
attrListToRender.push(attr); | ||
} | ||
} | ||
attrListToRender.sort(this.attrCompare) | ||
attrListToRender.sort(this.attrCompare); | ||
for (var a in attrListToRender) { | ||
var attr = attrListToRender[a] | ||
res += " " + attr.name + "=\"" + utils.normalizeXmlIncludingCR(attr.value) + "\""; | ||
for (a in attrListToRender) { | ||
attr = attrListToRender[a]; | ||
res.push(" ", attr.name, '="', utils.normalizeXmlIncludingCR(attr.value), '"'); | ||
} | ||
return res; | ||
} | ||
return res.join(""); | ||
}; | ||
@@ -58,19 +58,19 @@ | ||
ExclusiveCanonicalization.prototype.renderNs = function(node, prefixesInScope, defaultNs, inclusiveNamespacesPrefixList) { | ||
var res = "" | ||
var newDefaultNs = defaultNs | ||
var nsListToRender = [] | ||
var a, i, p, attr | ||
, res = [] | ||
, newDefaultNs = defaultNs | ||
, nsListToRender = [] | ||
, currNs = node.namespaceURI || ""; | ||
var currNs = node.namespaceURI || "" | ||
//handle the namespaceof the node itself | ||
if (node.prefix) { | ||
if (prefixesInScope.indexOf(node.prefix)==-1) { | ||
nsListToRender.push({"prefix": node.prefix, "namespaceURI": node.namespaceURI}) | ||
prefixesInScope.push(node.prefix); | ||
if (prefixesInScope.indexOf(node.prefix)==-1) { | ||
nsListToRender.push({"prefix": node.prefix, "namespaceURI": node.namespaceURI}); | ||
prefixesInScope.push(node.prefix); | ||
} | ||
} | ||
else if (defaultNs!=currNs) { | ||
else if (defaultNs!=currNs) { | ||
//new default ns | ||
newDefaultNs = node.namespaceURI | ||
res += " xmlns=\"" + newDefaultNs + "\"" | ||
newDefaultNs = node.namespaceURI; | ||
res.push(' xmlns="', newDefaultNs, '"'); | ||
} | ||
@@ -80,7 +80,7 @@ | ||
if (node.attributes) { | ||
for (var i=0;i<node.attributes.length;i++) { | ||
var attr = node.attributes[i] | ||
for (i = 0; i < node.attributes.length; ++i) { | ||
attr = node.attributes[i]; | ||
//handle all prefixed attributes that are included in the prefix list and where | ||
//the prefix is not defined already | ||
//the prefix is not defined already | ||
if (attr.prefix && prefixesInScope.indexOf(attr.localName) === -1 && inclusiveNamespacesPrefixList.indexOf(attr.localName) >= 0) { | ||
@@ -90,43 +90,39 @@ nsListToRender.push({"prefix": attr.localName, "namespaceURI": attr.value}); | ||
} | ||
//handle all prefixed attributes that are not xmlns definitions and where | ||
//the prefix is not defined already | ||
if (attr.prefix && prefixesInScope.indexOf(attr.prefix)==-1 && attr.prefix!="xmlns") { | ||
nsListToRender.push({"prefix": attr.prefix, "namespaceURI": attr.namespaceURI}) | ||
//handle all prefixed attributes that are not xmlns definitions and where | ||
//the prefix is not defined already | ||
if (attr.prefix && prefixesInScope.indexOf(attr.prefix)==-1 && attr.prefix!="xmlns") { | ||
nsListToRender.push({"prefix": attr.prefix, "namespaceURI": attr.namespaceURI}); | ||
prefixesInScope.push(attr.prefix); | ||
} | ||
} | ||
} | ||
} | ||
nsListToRender.sort(this.nsCompare) | ||
nsListToRender.sort(this.nsCompare); | ||
//render namespaces | ||
for (var a in nsListToRender) { | ||
var p = nsListToRender[a] | ||
res += " xmlns:" + p.prefix + "=\"" + p.namespaceURI + "\""; | ||
for (a in nsListToRender) { | ||
p = nsListToRender[a]; | ||
res.push(" xmlns:", p.prefix, '="', p.namespaceURI, '"'); | ||
} | ||
return {"rendered": res, "newDefaultNs": newDefaultNs}; | ||
} | ||
return {"rendered": res.join(""), "newDefaultNs": newDefaultNs}; | ||
}; | ||
ExclusiveCanonicalization.prototype.processInner = function(node, prefixesInScope, defaultNs, inclusiveNamespacesPrefixList) { | ||
if (node.data) return utils.normalizeXmlIncludingCR(node.data); | ||
if (node.data) return utils.normalizeXmlIncludingCR(node.data) | ||
var i, pfxCopy | ||
, ns = this.renderNs(node, prefixesInScope, defaultNs, inclusiveNamespacesPrefixList) | ||
, res = ["<", node.tagName, ns.rendered, this.renderAttrs(node), ">"]; | ||
var res = "<" | ||
res += node.tagName | ||
var ns = this.renderNs(node, prefixesInScope, defaultNs, inclusiveNamespacesPrefixList) | ||
res += ns.rendered | ||
res += this.renderAttrs(node) | ||
res+=">"; | ||
for (var i=0;i<node.childNodes.length;i++) { | ||
var pfxCopy = prefixesInScope.slice(0) | ||
res += this.processInner(node.childNodes[i], pfxCopy, ns.newDefaultNs, inclusiveNamespacesPrefixList) | ||
for (i = 0; i < node.childNodes.length; ++i) { | ||
pfxCopy = prefixesInScope.slice(0); | ||
res.push(this.processInner(node.childNodes[i], pfxCopy, ns.newDefaultNs, inclusiveNamespacesPrefixList)); | ||
} | ||
res+= "</" + node.tagName + ">" | ||
return res | ||
} | ||
res.push("</", node.tagName, ">"); | ||
return res.join(""); | ||
}; | ||
/** | ||
@@ -139,18 +135,15 @@ * Perform canonicalization of the given node | ||
*/ | ||
ExclusiveCanonicalization.prototype.process = function(node, options) { | ||
var options = options || {}; | ||
ExclusiveCanonicalization.prototype.process = function(node, options) { | ||
options = options || {}; | ||
var inclusiveNamespacesPrefixList = options.inclusiveNamespacesPrefixList || []; | ||
if (!(inclusiveNamespacesPrefixList instanceof Array)) inclusiveNamespacesPrefixList = inclusiveNamespacesPrefixList.split(' '); | ||
var res = this.processInner(node, [], "", inclusiveNamespacesPrefixList) | ||
return res | ||
//var doc = new Dom().parseFromString(res) | ||
var res = this.processInner(node, [], "", inclusiveNamespacesPrefixList); | ||
return res; | ||
//var doc = new Dom().parseFromString(res) | ||
//return doc.documentElement | ||
} | ||
}; | ||
ExclusiveCanonicalization.prototype.getAlgorithmName = function() { | ||
return "http://www.w3.org/2001/10/xml-exc-c14n#" | ||
} | ||
ExclusiveCanonicalization.prototype.getAlgorithmName = function() { | ||
return "http://www.w3.org/2001/10/xml-exc-c14n#"; | ||
}; |
{ | ||
"name": "xml-crypto", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "Xml digital signature and encryption library for Node.js", | ||
@@ -5,0 +5,0 @@ "engines": { "node": ">=0.4.0" }, |
@@ -23,3 +23,3 @@ ## xml-crypto | ||
"<name>Harry Potter</name>" + | ||
"</book>" | ||
"</book>" + | ||
"</library>" | ||
@@ -35,3 +35,3 @@ | ||
The result wil be: | ||
The result will be: | ||
@@ -38,0 +38,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
239804
1448