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
= "http://www.w3.org/TR/1999/REC-xslt-19991116";
61 public override Type
[] InputTypes
{
65 // this way the result is cached if called multiple time
67 input
[0] = typeof (System
.IO
.Stream
);
68 input
[1] = typeof (System
.Xml
.XmlDocument
);
69 input
[2] = typeof (System
.Xml
.XmlNodeList
);
76 public override Type
[] OutputTypes
{
80 // this way the result is cached if called multiple time
81 output
= new Type
[1];
82 output
[0] = typeof (System
.IO
.Stream
);
89 protected override XmlNodeList
GetInnerXml ()
94 public override object GetOutput ()
96 XmlResolver resolver
= GetResolver ();
98 XslTransform xsl
= new XslTransform ();
99 XmlDocument doc
= new XmlDocument ();
101 doc
.XmlResolver
= resolver
;
103 foreach (XmlNode n
in xnl
)
104 doc
.AppendChild (doc
.ImportNode (n
, true));
106 xsl
.Load (doc
, resolver
);
111 if (inputDoc
== null)
112 throw new NullReferenceException ("Load input document before transformation.");
114 MemoryStream stream
= new MemoryStream ();
115 // only possible output: Stream
117 xsl
.XmlResolver
= resolver
;
119 xsl
.Transform (inputDoc
, null, stream
);
121 stream
.Seek (0, SeekOrigin
.Begin
);
125 public override object GetOutput (Type type
)
127 if (type
!= Type
.GetType ("System.IO.Stream"))
128 throw new ArgumentException ("type");
132 public override void LoadInnerXml (XmlNodeList nodeList
)
134 if (nodeList
== null)
135 throw new CryptographicException ("nodeList");
139 public override void LoadInput (object obj
)
141 // possible input: Stream, XmlDocument, and XmlNodeList
143 inputDoc
= new XmlDocument ();
145 inputDoc
.XmlResolver
= GetResolver ();
147 inputDoc
.Load (obj
as Stream
);
149 else if (obj
is XmlDocument
) {
150 inputDoc
= obj
as XmlDocument
;
152 else if (obj
is XmlNodeList
) {
153 inputDoc
= new XmlDocument ();
155 inputDoc
.XmlResolver
= GetResolver ();
157 XmlNodeList nl
= (XmlNodeList
) obj
;
158 for (int i
= 0; i
< nl
.Count
; i
++)
159 inputDoc
.AppendChild (inputDoc
.ImportNode (nl
[i
], true));