Permalink
Browse files

initial checkin

  • Loading branch information...
0 parents commit b80b861fff4c0f75ebe076c3239fa064254c004a @yaronn committed May 13, 2012
Showing with 522 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +64 −0 old/acord.xml
  3. +32 −0 old/baseline.cs
  4. +142 −0 old/lib.js
  5. +281 −0 old/tests.js
@@ -0,0 +1,3 @@
+node_modules/
+p.js
+*.svclog
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
+ <Body>
+ <ACORD xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/">
+ <SignonRq>
+ <SessKey />
+ <ClientDt />
+ <CustLangPref />
+ <ClientApp>
+ <Org p6:type="AssignedIdentifier" id="wewe" xmlns:p6="http://www.w3.org/2001/XMLSchema-instance" />
+ <Name />
+ <Version />
+ </ClientApp>
+ <ProxyClient>
+ <Org p6:type="AssignedIdentifier" id="erer" xmlns:p6="http://www.w3.org/2001/XMLSchema-instance" />
+ <Name>ererer</Name>
+ <Version>dfdf</Version>
+ </ProxyClient>
+ </SignonRq>
+ <InsuranceSvcRq>
+ <RqUID />
+ <SPName id="rter" />
+ <QuickHit xmlns="urn:com.thehartford.bi.acord-extensions">
+ <StateProvCd CodeListRef="dfdf" xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/" />
+ </QuickHit>
+ <WorkCompPolicyQuoteInqRq>
+ <RqUID>erer</RqUID>
+ <TransactionRequestDt id="erer" />
+ <CurCd />
+ <BroadLOBCd id="erer" />
+ <InsuredOrPrincipal>
+ <ItemIdInfo>
+ <AgencyId id="3434" />
+ <OtherIdentifier>
+ <CommercialName id="3434" />
+ <ContractTerm>
+ <EffectiveDt id="3434" />
+ <StartTime id="3434" />
+ </ContractTerm>
+ </OtherIdentifier>
+ </ItemIdInfo>
+ </InsuredOrPrincipal>
+ <InsuredOrPrincipal>
+ </InsuredOrPrincipal>
+ <CommlPolicy>
+ <PolicyNumber id="3434" />
+ <LOBCd />
+ </CommlPolicy>
+ <WorkCompLineBusiness>
+ <LOBCd />
+ <WorkCompRateState>
+ <WorkCompLocInfo>
+ </WorkCompLocInfo>
+ </WorkCompRateState>
+ </WorkCompLineBusiness>
+ <RemarkText IdRef="">
+ </RemarkText>
+ <RemarkText IdRef="2323" id="3434">
+ </RemarkText>
+ </WorkCompPolicyQuoteInqRq>
+ </InsuranceSvcRq>
+ </ACORD>
+ </Body>
+</Envelope>
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Security.Cryptography.Xml;
+using System.Security.Cryptography;
+using System.Xml;
+using System.IO;
+
+namespace ConsoleApplication31
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ var c = new XmlDsigExcC14NTransform(true, "");
+ var doc = new XmlDocument();
+ doc.PreserveWhitespace = true;
+ doc.LoadXml("<root xmlns=\"ns1\"><child xmlns=\"ns2\"><inner xmlns=\"ns2\">123</inner></child></root>");
+ var node = doc.SelectSingleNode("//*[local-name(.)='child']");
+ var nodes = node.SelectNodes(".|.//*|.//text()|.//@*");
+ c.LoadInput(nodes);
+
+ //var h = new SHA1CryptoServiceProvider();
+ //var b = c.GetDigestedOutput(h);
+ //var b64 = Convert.ToBase64String(b);
+
+ var res = c.GetOutput() as MemoryStream;
+ string s2 = System.Text.Encoding.UTF8.GetString(res.ToArray());
+ }
+ }
+}
@@ -0,0 +1,142 @@
+exports.ExclusiveCanonicalization = ExclusiveCanonicalization
+
+function ExclusiveCanonicalization() {
+
+}
+
+function attrCompare (a,b) {
+ if (!a.prefix) return -1
+ if (!b.prefix) return 1
+ return a.name.localeCompare(b.name)
+}
+
+function nsCompare (a,b) {
+ var attr1 = a.prefix+a.namespaceURI
+ var attr2 = b.prefix+b.namespaceURI
+ return attr1.localeCompare(attr2)
+}
+
+function renderAttrs(node) {
+ var res = ""
+ var attrListToRender = []
+
+ if (node.attributes) {
+ for (i=0;i<node.attributes.length;i++) {
+ var attr = node.attributes[i]
+ //ignore namespace definition attributes
+ if (attr.name.indexOf("xmlns")==0) continue;
+ attrListToRender.push(attr)
+ }
+ }
+
+ attrListToRender.sort(attrCompare)
+
+ for (var a in attrListToRender) {
+ var attr = attrListToRender[a]
+ res += " " + attr.name + "=\"" + normalizeXml(attr.value) + "\"";
+ }
+
+ return res;
+}
+
+function renderNs(node, prefixesInScope, defaultNs) {
+ var res = ""
+ var newDefaultNs = defaultNs
+ var nsListToRender = []
+
+ var currNs = node.namespaceURI || ""
+ //handle the node namespace
+
+ if (node.prefix) {
+ if (prefixesInScope.indexOf(node.prefix)==-1) {
+ nsListToRender.push({"prefix": node.prefix, "namespaceURI": node.namespaceURI})
+ prefixesInScope.push(node.prefix);
+ }
+ }
+ else if (defaultNs!=currNs) {
+ //new default ns
+ newDefaultNs = node.namespaceURI
+ res += " xmlns=\"" + newDefaultNs + "\""
+ }
+
+ //handle the attributes namespace
+ if (node.attributes) {
+ for (i=0;i<node.attributes.length;i++) {
+ var attr = node.attributes[i]
+ //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(nsCompare)
+
+ for (var a in nsListToRender) {
+ var p = nsListToRender[a]
+ res += " xmlns:" + p.prefix + "=\"" + p.namespaceURI + "\"";
+ }
+
+ return {"rendered": res, "newDefaultNs": newDefaultNs};
+}
+
+function processInner(node, prefixesInScope, defaultNs) {
+
+ if (node.data) return normalizeXml(node.data)
+
+ var res = "<"
+ res += node.tagName
+ var temp = renderNs(node, prefixesInScope, defaultNs)
+ res += temp.rendered
+ res += renderAttrs(node)
+ res+=">";
+
+ for (var i=0;i<node.childNodes.length;i++) {
+ res += processInner(node.childNodes[i], prefixesInScope.slice(0), temp.newDefaultNs)
+ }
+
+ res+= "</" + node.tagName + ">"
+ return res
+}
+
+ExclusiveCanonicalization.prototype.process = function(node) {
+ return processInner(node, [], "")
+}
+
+ExclusiveCanonicalization.prototype.getHash = function(xml) {
+ var crypto = require('crypto')
+ , shasum = crypto.createHash('sha1');
+ shasum.update(xml);
+ return shasum.digest('base64');
+}
+
+var xml_special_to_escaped_one_map = {
+ '&': '&amp;',
+ '"': '&quot;',
+ '<': '&lt;',
+ '>': '&gt;',
+ '\r': '&#xD;'
+};
+
+var escaped_one_to_xml_special_map = {
+ '&amp;': '&',
+ '&quot;': '"',
+ '&lt;': '<',
+ '&gt;': '>',
+ '&#xD;': '\r'
+};
+
+function normalizeXml(string) {
+ return string.replace(/([\&"<>\r])/g, function(str, item) {
+ return xml_special_to_escaped_one_map[item];
+ });
+};
+
+function deNormalizeXml(string) {
+ return string.replace(/(&quot;|&lt;|&gt;|&amp;|&#xD;)/g,
+ function(str, item) {
+ return escaped_one_to_xml_special_map[item];
+ });
+}
Oops, something went wrong.

0 comments on commit b80b861

Please sign in to comment.