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)
9 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
10 // (C) 2003 Aleksey Sanin (aleksey@aleksey.com)
11 // (C) 2004 Novell (http://www.novell.com)
14 using System.Collections;
21 namespace System.Security.Cryptography.Xml {
23 public class XmlDsigC14NTransform : Transform {
25 private Type[] output;
26 private XmlCanonicalizer canonicalizer;
29 public XmlDsigC14NTransform ()
31 Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
32 canonicalizer = new XmlCanonicalizer (false, false);
35 public XmlDsigC14NTransform (bool includeComments)
37 canonicalizer = new XmlCanonicalizer (includeComments, false);
40 public override Type[] InputTypes {
44 // this way the result is cached if called multiple time
46 input[0] = typeof (System.IO.Stream);
47 input[1] = typeof (System.Xml.XmlDocument);
48 input[2] = typeof (System.Xml.XmlNodeList);
55 public override Type[] OutputTypes {
59 // this way the result is cached if called multiple time
60 output = new Type [1];
61 output[0] = typeof (System.IO.Stream);
68 protected override XmlNodeList GetInnerXml ()
70 return null; // THIS IS DOCUMENTED AS SUCH
73 public override object GetOutput ()
78 public override object GetOutput (Type type)
80 if (type == Type.GetType ("Stream"))
82 throw new ArgumentException ("type");
85 public override void LoadInnerXml (XmlNodeList nodeList)
87 // documented as not changing the state of the transform
90 public override void LoadInput (object obj)
94 XmlDocument doc = new XmlDocument ();
95 doc.PreserveWhitespace = true; // REALLY IMPORTANT
96 doc.Load (obj as Stream);
97 s = canonicalizer.Canonicalize (doc);
98 } else if (obj is XmlDocument)
99 s = canonicalizer.Canonicalize ((obj as XmlDocument));
100 else if (obj is XmlNodeList)
101 s = canonicalizer.Canonicalize ((obj as XmlNodeList));
102 // note: there is no default are other types won't throw an exception