Author: atsushi
Date: 2007-03-22 10:29:11 -0500 (Thu, 22 Mar 2007)
New Revision: 74812
Modified:
trunk/mcs/class/System.Security/Mono.Xml/ChangeLog
trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs
Log:
2007-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlCanonicalizer.cs : fill prefixes which should be actually
written. It must be actually done before canonicalization (so
that node list filtering still takes spec-conformant effect).
* Transform.cs, XmlDsigC14NTransform.cs, XmlDsigExcC14NTransform.cs :
handle PropagatedNamespaces.
* XmlDsigC14NTransformTest.cs : added test for xmlns attribute
completion for input nodes, as well as test for
PropagatedNamespaces (ignored so far).
Modified: trunk/mcs/class/System.Security/Mono.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.Security/Mono.Xml/ChangeLog 2007-03-22 14:59:57 UTC
(rev 74811)
+++ trunk/mcs/class/System.Security/Mono.Xml/ChangeLog 2007-03-22 15:29:11 UTC
(rev 74812)
@@ -1,3 +1,9 @@
+2007-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlCanonicalizer.cs : fill prefixes which should be actually
+ written. It must be actually done before canonicalization (so
+ that node list filtering still takes spec-conformant effect).
+
2007-01-23 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlCanonicalizer.cs : in Canonicalize(XmlNodeList), nodes [0] could
Modified: trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
===================================================================
--- trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
2007-03-22 14:59:57 UTC (rev 74811)
+++ trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
2007-03-22 15:29:11 UTC (rev 74812)
@@ -59,12 +59,14 @@
private ArrayList visibleNamespaces;
private int prevVisibleNamespacesStart;
private int prevVisibleNamespacesEnd;
+ private Hashtable propagatedNss;
- public XmlCanonicalizer (bool withComments, bool excC14N)
+ public XmlCanonicalizer (bool withComments, bool excC14N,
Hashtable propagatedNamespaces)
{
res = new StringBuilder ();
comments = withComments;
exclusive = excC14N;
+ propagatedNss = propagatedNamespaces;
}
void Initialize ()
@@ -82,6 +84,7 @@
throw new ArgumentNullException ("doc");
Initialize ();
+ FillMissingPrefixes (doc, new XmlNamespaceManager
(doc.NameTable), new ArrayList ());
WriteDocumentNode (doc);
UTF8Encoding utf8 = new UTF8Encoding ();
@@ -104,6 +107,55 @@
set { inclusiveNamespacesPrefixList = value; }
}
+ XmlAttribute CreateXmlns (XmlNode n)
+ {
+ XmlAttribute a = n.Prefix.Length == 0 ?
+ n.OwnerDocument.CreateAttribute ("xmlns",
"http://www.w3.org/2000/xmlns/") :
+ n.OwnerDocument.CreateAttribute ("xmlns",
n.Prefix, "http://www.w3.org/2000/xmlns/");
+ a.Value = n.NamespaceURI;
+ return a;
+ }
+
+ // Note that this must be done *before* filtering nodes out
+ // by context node list.
+ private void FillMissingPrefixes (XmlNode n,
XmlNamespaceManager nsmgr, ArrayList tmpList)
+ {
+ if (n.Prefix.Length == 0 && propagatedNss != null) {
+ foreach (DictionaryEntry de in propagatedNss)
+ if ((string) de.Value ==
n.NamespaceURI) {
+ n.Prefix = (string) de.Key;
+ break;
+ }
+ }
+
+ if (n.NodeType == XmlNodeType.Element && ((XmlElement)
n).HasAttributes) {
+ foreach (XmlAttribute a in n.Attributes)
+ if (a.NamespaceURI ==
"http://www.w3.org/2000/xmlns/")
+ nsmgr.AddNamespace
(a.Prefix.Length == 0 ? String.Empty : a.LocalName, a.Value);
+ nsmgr.PushScope ();
+ }
+
+ if (n.NamespaceURI.Length > 0 && nsmgr.LookupPrefix
(n.NamespaceURI) == null)
+ tmpList.Add (CreateXmlns (n));
+
+ if (n.NodeType == XmlNodeType.Element && ((XmlElement)
n).HasAttributes) {
+ foreach (XmlAttribute a in n.Attributes)
+ if (a.NamespaceURI.Length > 0 &&
nsmgr.LookupNamespace (a.Prefix) == null)
+ tmpList.Add (CreateXmlns (a));
+ }
+
+ foreach (XmlAttribute a in tmpList)
+ ((XmlElement) n).SetAttributeNode (a);
+ tmpList.Clear ();
+
+ if (n.HasChildNodes) {
+ for (XmlNode c = n.FirstChild; c != null; c =
c.NextSibling)
+ if (c.NodeType == XmlNodeType.Element)
+ FillMissingPrefixes (c, nsmgr,
tmpList);
+ }
+ nsmgr.PopScope ();
+ }
+
private void WriteNode (XmlNode node)
{
// Console.WriteLine ("C14N Debug: node=" + node.Name);
Modified:
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
2007-03-22 14:59:57 UTC (rev 74811)
+++ trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
2007-03-22 15:29:11 UTC (rev 74812)
@@ -1,3 +1,8 @@
+2007-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * Transform.cs, XmlDsigC14NTransform.cs, XmlDsigExcC14NTransform.cs :
+ handle PropagatedNamespaces.
+
2007-02-01 Atsushi Enomoto <[EMAIL PROTECTED]>
* SignedXml.cs : for internal URI (#blah) resolution, use
Modified:
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs
===================================================================
---
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs
2007-03-22 14:59:57 UTC (rev 74811)
+++
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs
2007-03-22 15:29:11 UTC (rev 74812)
@@ -43,6 +43,7 @@
private string algo;
private XmlResolver xmlResolver;
+ private Hashtable propagated_namespaces = new Hashtable ();
#if NET_2_0
protected Transform ()
@@ -86,13 +87,17 @@
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
+#endif
- [MonoTODO]
[ComVisible (false)]
- public Hashtable PropagatedNamespaces {
- get { throw new NotImplementedException (); }
+#if NET_2_0
+ public
+#else
+ internal
+#endif
+ Hashtable PropagatedNamespaces {
+ get { return propagated_namespaces; }
}
-#endif
#endregion // Properties
Modified:
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs
===================================================================
---
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs
2007-03-22 14:59:57 UTC (rev 74811)
+++
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs
2007-03-22 15:29:11 UTC (rev 74812)
@@ -51,12 +51,12 @@
public XmlDsigC14NTransform ()
{
Algorithm =
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
- canonicalizer = new XmlCanonicalizer (false, false);
+ canonicalizer = new XmlCanonicalizer (false, false,
PropagatedNamespaces);
}
public XmlDsigC14NTransform (bool includeComments)
{
- canonicalizer = new XmlCanonicalizer (includeComments,
false);
+ canonicalizer = new XmlCanonicalizer (includeComments,
false, PropagatedNamespaces);
}
public override Type[] InputTypes {
Modified:
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
===================================================================
---
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
2007-03-22 14:59:57 UTC (rev 74811)
+++
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
2007-03-22 15:29:11 UTC (rev 74812)
@@ -68,7 +68,7 @@
public XmlDsigExcC14NTransform (bool includeComments, string
inclusiveNamespacesPrefixList)
{
Algorithm =
XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform;
- canonicalizer = new XmlCanonicalizer (includeComments,
true);
+ canonicalizer = new XmlCanonicalizer (includeComments,
true, PropagatedNamespaces);
}
public string InclusiveNamespacesPrefixList {
Modified:
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
===================================================================
---
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
2007-03-22 14:59:57 UTC (rev 74811)
+++
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
2007-03-22 15:29:11 UTC (rev 74812)
@@ -1,3 +1,9 @@
+2007-03-22 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlDsigC14NTransformTest.cs : added test for xmlns attribute
+ completion for input nodes, as well as test for
+ PropagatedNamespaces (ignored so far).
+
2007-01-25 Atsushi Enomoto <[EMAIL PROTECTED]>
* SignedXmlTest.cs : enable SignElementWithPrefixedNamespace().
Modified:
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs
===================================================================
---
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs
2007-03-22 14:59:57 UTC (rev 74811)
+++
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs
2007-03-22 15:29:11 UTC (rev 74812)
@@ -486,5 +486,38 @@
Stream s = t.GetOutput () as Stream;
AssertEquals (expected, new StreamReader (s,
Encoding.UTF8).ReadToEnd ());
}
+
+#if NET_2_0
+ [Test]
+ public void PrefixlessNamespaceOutput ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.AppendChild (doc.CreateElement ("foo", "urn:foo"));
+ doc.DocumentElement.AppendChild (doc.CreateElement
("bar", "urn:bar"));
+ AssertEquals ("#1", String.Empty,
doc.DocumentElement.GetAttribute ("xmlns"));
+ XmlDsigC14NTransform t = new XmlDsigC14NTransform ();
+ t.LoadInput (doc);
+ Stream s = t.GetOutput () as Stream;
+ AssertEquals ("<foo xmlns=\"urn:foo\"><bar
xmlns=\"urn:bar\"></bar></foo>", new StreamReader (s, Encoding.UTF8).ReadToEnd
());
+ AssertEquals ("#2", "urn:foo",
doc.DocumentElement.GetAttribute ("xmlns"));
+ }
+
+ [Test]
+ [Ignore ("find out how PropagatedNamespaces returns non-null
instance on .NET")]
+ public void PropagatedNamespaces ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.AppendChild (doc.CreateElement ("foo", "urn:foo"));
+ doc.DocumentElement.AppendChild (doc.CreateElement
("bar", "urn:bar"));
+ AssertEquals ("#1", String.Empty,
doc.DocumentElement.GetAttribute ("xmlns:f"));
+ XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform
();
+ t.LoadInput (doc);
+ t.PropagatedNamespaces.Add ("f", "urn:foo");
+ t.PropagatedNamespaces.Add ("b", "urn:bar");
+ Stream s = t.GetOutput () as Stream;
+ AssertEquals ("<f:foo xmlns:f=\"urn:foo\"><b:bar
xmlns:b=\"urn:bar\"></b:bar></f:foo>", new StreamReader (s,
Encoding.UTF8).ReadToEnd ());
+ AssertEquals ("#2", "urn:foo",
doc.DocumentElement.GetAttribute ("xmlns:f"));
+ }
+#endif
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches