2 // XmlDsigEnvelopedSignatureTransform.cs -
3 // Enveloped Signature Transform implementation for XML Signature
4 // http://www.w3.org/TR/1999/REC-xslt-19991116
7 // Sebastien Pouliot (spouliot@motus.com)
8 // Atsushi Enomoto (atsushi@ximian.com)
10 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
11 // (C) 2004 Novell Inc.
18 namespace System.Security.Cryptography.Xml
21 public class XmlDsigXsltTransform : Transform
24 private Type [] input;
25 private Type [] output;
26 private bool comments;
27 private XmlNodeList xnl;
28 private XmlDocument inputDoc;
30 public XmlDsigXsltTransform () : this (false)
34 public XmlDsigXsltTransform (bool includeComments)
36 comments = includeComments;
37 Algorithm = "http://www.w3.org/TR/1999/REC-xslt-19991116";
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 ()
73 public override object GetOutput ()
75 XslTransform xsl = new XslTransform ();
76 XmlDocument doc = new XmlDocument ();
77 doc.XmlResolver = GetResolver ();
78 foreach (XmlNode n in xnl)
79 doc.AppendChild (doc.ImportNode (n, true));
84 stream = new MemoryStream ();
85 // only possible output: Stream
86 xsl.Transform (inputDoc, null, stream);
88 CryptoStream cs = null;
90 cs = new CryptoStream (stream, new FromBase64Transform (), CryptoStreamMode.Read);
91 // note: there is no default are other types won't throw an exception
95 public override object GetOutput (Type type)
97 if (type != Type.GetType ("System.IO.Stream"))
98 throw new ArgumentException ("type");
102 public override void LoadInnerXml (XmlNodeList nodeList)
104 if (nodeList == null)
105 throw new CryptographicException ("nodeList");
109 public override void LoadInput (object obj)
111 // possible input: Stream, XmlDocument, and XmlNodeList
113 inputDoc = new XmlDocument ();
114 inputDoc.Load (obj as Stream);
116 else if (obj is XmlDocument) {
117 inputDoc= obj as XmlDocument;
119 else if (obj is XmlNodeList) {
120 inputDoc = new XmlDocument ();
121 XmlNodeList nl = (XmlNodeList) obj;
122 for (int i = 0; i < nl.Count; i++)
123 inputDoc.AppendChild (inputDoc.ImportNode (nl [i], true));