2 // XmlDsigC14NTransform.cs - C14N Transform implementation for XML Signature
3 // http://www.w3.org/TR/xml-c14n
6 // Sebastien Pouliot <sebastien@ximian.com>
7 // Aleksey Sanin (aleksey@aleksey.com)
8 // Tim Coleman (tim@timcoleman.com)
10 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
11 // (C) 2003 Aleksey Sanin (aleksey@aleksey.com)
12 // Copyright (C) Tim Coleman, 2004
13 // (C) 2004 Novell (http://www.novell.com)
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System.Collections;
44 namespace System.Security.Cryptography.Xml {
46 public class XmlDsigC14NTransform : Transform {
48 private Type[] output;
49 private XmlCanonicalizer canonicalizer;
52 public XmlDsigC14NTransform ()
54 Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
55 canonicalizer = new XmlCanonicalizer (false, false);
58 public XmlDsigC14NTransform (bool includeComments)
60 canonicalizer = new XmlCanonicalizer (includeComments, false);
63 public override Type[] InputTypes {
67 // this way the result is cached if called multiple time
69 input[0] = typeof (System.IO.Stream);
70 input[1] = typeof (System.Xml.XmlDocument);
71 input[2] = typeof (System.Xml.XmlNodeList);
78 public override Type[] OutputTypes {
82 // this way the result is cached if called multiple time
83 output = new Type [1];
84 output[0] = typeof (System.IO.Stream);
91 protected override XmlNodeList GetInnerXml ()
93 return null; // THIS IS DOCUMENTED AS SUCH
98 public override byte[] GetDigestedOutput (HashAlgorithm hash)
100 throw new NotImplementedException ();
104 public override object GetOutput ()
109 public override object GetOutput (Type type)
111 if (type == Type.GetType ("Stream"))
113 throw new ArgumentException ("type");
116 public override void LoadInnerXml (XmlNodeList nodeList)
118 // documented as not changing the state of the transform
121 public override void LoadInput (object obj)
125 XmlDocument doc = new XmlDocument ();
126 doc.PreserveWhitespace = true; // REALLY IMPORTANT
127 doc.Load (obj as Stream);
128 s = canonicalizer.Canonicalize (doc);
129 } else if (obj is XmlDocument)
130 s = canonicalizer.Canonicalize ((obj as XmlDocument));
131 else if (obj is XmlNodeList)
132 s = canonicalizer.Canonicalize ((obj as XmlNodeList));
133 // note: there is no default are other types won't throw an exception