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.
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 namespace System.Security.Cryptography.Xml
42 public class XmlDsigXsltTransform : Transform
45 private Type [] input;
46 private Type [] output;
47 private bool comments;
48 private XmlNodeList xnl;
49 private XmlDocument inputDoc;
51 public XmlDsigXsltTransform () : this (false)
55 public XmlDsigXsltTransform (bool includeComments)
57 comments = includeComments;
58 Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform;
61 public override Type [] InputTypes {
65 input [0] = typeof (System.IO.Stream);
66 input [1] = typeof (System.Xml.XmlDocument);
67 input [2] = typeof (System.Xml.XmlNodeList);
73 public override Type [] OutputTypes {
76 output = new Type [1];
77 output [0] = typeof (System.IO.Stream);
83 protected override XmlNodeList GetInnerXml ()
88 public override object GetOutput ()
92 throw new ArgumentNullException ("LoadInnerXml before transformation.");
94 XmlResolver resolver = GetResolver ();
96 XslTransform xsl = new XslTransform ();
97 XmlDocument doc = new XmlDocument ();
99 doc.XmlResolver = resolver;
101 foreach (XmlNode n in xnl)
102 doc.AppendChild (doc.ImportNode (n, true));
104 xsl.Load (doc, resolver);
109 if (inputDoc == null)
111 throw new ArgumentNullException ("LoadInput before transformation.");
113 throw new NullReferenceException ("LoadInput before transformation.");
116 MemoryStream stream = new MemoryStream ();
117 // only possible output: Stream
119 xsl.XmlResolver = resolver;
121 xsl.Transform (inputDoc, null, stream);
123 stream.Seek (0, SeekOrigin.Begin);
127 public override object GetOutput (Type type)
129 if (type != typeof (Stream))
130 throw new ArgumentException ("type");
134 public override void LoadInnerXml (XmlNodeList nodeList)
136 if (nodeList == null)
137 throw new CryptographicException ("nodeList");
141 public override void LoadInput (object obj)
143 // possible input: Stream, XmlDocument, and XmlNodeList
144 Stream s = (obj as Stream);
146 inputDoc = new XmlDocument ();
148 inputDoc.XmlResolver = GetResolver ();
150 // inputDoc.Load (obj as Stream);
151 inputDoc.Load (new XmlSignatureStreamReader (new StreamReader (s)));
155 XmlDocument xd = (obj as XmlDocument);
161 XmlNodeList nl = (obj as XmlNodeList);
163 inputDoc = new XmlDocument ();
165 inputDoc.XmlResolver = GetResolver ();
167 for (int i = 0; i < nl.Count; i++)
168 inputDoc.AppendChild (inputDoc.ImportNode (nl [i], true));