X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mcs%2Fclass%2FSystem.Security%2FSystem.Security.Cryptography.Xml%2FXmlDsigC14NTransform.cs;h=1a78700c57b83c9b5647df3c6d773f357b59710a;hb=c0a8ef12af1f473bfc837325581fe738f1b3178c;hp=19a5a5444a6ccfe441c0597c526f9cb7b14a8d8a;hpb=b321edc78e2df302fc2d1c80a1bcd69f7a49edb4;p=mono.git diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs index 19a5a5444a6..1a78700c57b 100644 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs +++ b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs @@ -10,9 +10,7 @@ // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) // (C) 2003 Aleksey Sanin (aleksey@aleksey.com) // Copyright (C) Tim Coleman, 2004 -// (C) 2004 Novell (http://www.novell.com) -// - +// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -36,6 +34,7 @@ using System.Collections; using System.IO; +using System.Runtime.InteropServices; using System.Text; using System.Xml; @@ -49,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; } @@ -78,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; } @@ -94,10 +89,11 @@ namespace System.Security.Cryptography.Xml { } #if NET_2_0 - [MonoTODO] + [ComVisible (false)] public override byte[] GetDigestedOutput (HashAlgorithm hash) { - throw new NotImplementedException (); + // no null check, MS throws a NullReferenceException here + return hash.ComputeHash ((Stream) GetOutput ()); } #endif @@ -108,7 +104,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"); } @@ -120,22 +116,34 @@ 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)); + 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); + } +#if NET_2_0 + else + throw new ArgumentException ("obj"); +#else // note: there is no default are other types won't throw an exception +#endif } } }