2 // XmlDsigC14NTransform.cs - C14N Transform implementation for XML Signature
3 // http://www.w3.org/TR/xml-c14n
6 // Sebastien Pouliot (spouliot@motus.com)
8 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
15 namespace System.Security.Cryptography.Xml {
17 public class XmlDsigC14NTransform : Transform {
20 private Type[] output;
21 private bool comments;
24 public XmlDsigC14NTransform ()
26 Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
30 public XmlDsigC14NTransform (bool includeComments)
32 comments = includeComments;
35 public override Type[] InputTypes {
39 // this way the result is cached if called multiple time
41 input[0] = typeof (System.IO.Stream);
42 input[1] = typeof (System.Xml.XmlDocument);
43 input[2] = typeof (System.Xml.XmlNodeList);
50 public override Type[] OutputTypes {
54 // this way the result is cached if called multiple time
55 output = new Type [1];
56 output[0] = typeof (System.IO.Stream);
63 protected override XmlNodeList GetInnerXml ()
65 return null; // THIS IS DOCUMENTED AS SUCH
68 public override object GetOutput ()
73 public override object GetOutput (Type type)
75 if (type == Type.GetType ("Stream"))
77 throw new ArgumentException ("type");
80 public override void LoadInnerXml (XmlNodeList nodeList)
82 // documented as not changing the state of the transform
85 public override void LoadInput (object obj)
87 XmlNodeList xnl = null;
91 else if (obj is XmlDocument)
92 xnl = (obj as XmlDocument).ChildNodes;
93 else if (obj is XmlNodeList)
94 xnl = (XmlNodeList) obj;
97 StringBuilder sb = new StringBuilder ();
98 foreach (XmlNode xn in xnl)
99 sb.Append (xn.InnerText);
101 UTF8Encoding utf8 = new UTF8Encoding ();
102 byte[] data = utf8.GetBytes (sb.ToString ());
103 s = new MemoryStream (data);
106 // note: there is no default are other types won't throw an exception