[corlib] Fixes security tests failures
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / XmlDsigC14NTransform.cs
index 49e4727d749c2f399f3fd3c956544b097d10674c..acbf322dc5e7ec80e8afffaaa284b26bc85691e6 100644 (file)
@@ -48,27 +48,26 @@ namespace System.Security.Cryptography.Xml {
                private XmlCanonicalizer canonicalizer;
                private Stream s;
                
-               public XmlDsigC14NTransform () 
+               public XmlDsigC14NTransform () : this (false)
                {
-                       Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
-                       canonicalizer = new XmlCanonicalizer (false, false);
                }
 
                public XmlDsigC14NTransform (bool includeComments) 
                {
-                       canonicalizer = new XmlCanonicalizer (includeComments, false);
+                       if (includeComments)
+                               Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform;
+                       else
+                               Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform;
+                       canonicalizer = new XmlCanonicalizer (includeComments, false, PropagatedNamespaces);
                }
 
                public override Type[] InputTypes {
                        get {
                                if (input == null) {
-                                       lock (this) {
-                                               // this way the result is cached if called multiple time
-                                               input = new Type [3];
-                                               input[0] = typeof (System.IO.Stream);
-                                               input[1] = typeof (System.Xml.XmlDocument);
-                                               input[2] = typeof (System.Xml.XmlNodeList);
-                                       }
+                                       input = new Type [3];
+                                       input[0] = typeof (System.IO.Stream);
+                                       input[1] = typeof (System.Xml.XmlDocument);
+                                       input[2] = typeof (System.Xml.XmlNodeList);
                                }
                                return input;
                        }
@@ -77,11 +76,8 @@ namespace System.Security.Cryptography.Xml {
                public override Type[] OutputTypes {
                        get {
                                if (output == null) {
-                                       lock (this) {
-                                               // this way the result is cached if called multiple time
-                                               output = new Type [1];
-                                               output[0] = typeof (System.IO.Stream);
-                                       }
+                                       output = new Type [1];
+                                       output[0] = typeof (System.IO.Stream);
                                }
                                return output;
                        }
@@ -92,13 +88,12 @@ namespace System.Security.Cryptography.Xml {
                        return null; // THIS IS DOCUMENTED AS SUCH
                }
 
-#if NET_2_0
                [ComVisible (false)]
                public override byte[] GetDigestedOutput (HashAlgorithm hash)
                {
+                       // no null check, MS throws a NullReferenceException here
                        return hash.ComputeHash ((Stream) GetOutput ());
                }
-#endif
 
                public override object GetOutput () 
                {
@@ -107,7 +102,7 @@ namespace System.Security.Cryptography.Xml {
 
                public override object GetOutput (Type type) 
                {
-                       if (type == Type.GetType ("Stream"))
+                       if (type == typeof (Stream))
                                return GetOutput ();
                        throw new ArgumentException ("type");
                }
@@ -119,27 +114,30 @@ namespace System.Security.Cryptography.Xml {
 
                public override void LoadInput (object obj) 
                {
-                       if (obj is Stream) {
-                               s = (obj as Stream);
+                       // possible input: Stream, XmlDocument, and XmlNodeList
+                       Stream stream = (obj as Stream);
+                       if (stream != null) {
                                XmlDocument doc = new XmlDocument ();
                                doc.PreserveWhitespace = true;  // REALLY IMPORTANT
-#if NET_1_1
                                doc.XmlResolver = GetResolver ();
-#endif
-                               doc.Load (new XmlSignatureStreamReader (
-                                       new StreamReader ((Stream) obj)));
+                               doc.Load (new XmlSignatureStreamReader (new StreamReader (stream)));
 //                             doc.Load ((Stream) obj);
                                s = canonicalizer.Canonicalize (doc);
-                       } else if (obj is XmlDocument)
-                               s = canonicalizer.Canonicalize ((obj as XmlDocument));
-                       else if (obj is XmlNodeList)
-                               s = canonicalizer.Canonicalize ((obj as XmlNodeList));
-#if NET_2_0
+                               return;
+                       }
+
+                       XmlDocument xd = (obj as XmlDocument);
+                       if (xd != null) {
+                               s = canonicalizer.Canonicalize (xd);
+                               return;
+                       }
+
+                       XmlNodeList nl = (obj as XmlNodeList);
+                       if (nl != null) {
+                               s = canonicalizer.Canonicalize (nl);
+                       }
                        else
                                throw new ArgumentException ("obj");
-#else
-                       // note: there is no default are other types won't throw an exception
-#endif
                }
        }
 }