2004-03-04 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / XmlDsigXsltTransform.cs
1 //
2 // XmlDsigEnvelopedSignatureTransform.cs - 
3 //      Enveloped Signature Transform implementation for XML Signature
4 // http://www.w3.org/TR/1999/REC-xslt-19991116 
5 //
6 // Author:
7 //      Sebastien Pouliot (spouliot@motus.com)
8 //
9 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
10 //
11
12 using System.IO;
13 using System.Xml;
14 using System.Xml.Xsl;
15
16 namespace System.Security.Cryptography.Xml { 
17
18         [MonoTODO]
19         public class XmlDsigXsltTransform : Transform {
20
21                 private Type[] input;
22                 private Type[] output;
23                 private bool comments;
24                 private XmlNodeList xnl;
25                 private CryptoStream cs;
26
27                 public XmlDsigXsltTransform () : this (false) {}
28
29                 public XmlDsigXsltTransform (bool includeComments) 
30                 {
31                         comments = includeComments;
32                         Algorithm = "http://www.w3.org/TR/1999/REC-xslt-19991116";
33                 }
34
35                 public override Type[] InputTypes {
36                         get {
37                                 if (input == null) {
38                                         lock (this) {
39                                                 // this way the result is cached if called multiple time
40                                                 input = new Type [3];
41                                                 input[0] = typeof (System.IO.Stream);
42                                                 input[1] = typeof (System.Xml.XmlDocument);
43                                                 input[2] = typeof (System.Xml.XmlNodeList);
44                                         }
45                                 }
46                                 return input;
47                         }
48                 }
49
50                 public override Type[] OutputTypes {
51                         get {
52                                 if (output == null) {
53                                         lock (this) {
54                                                 // this way the result is cached if called multiple time
55                                                 output = new Type [1];
56                                                 output[0] = typeof (System.IO.Stream);
57                                         }
58                                 }
59                                 return output;
60                         }
61                 }
62                         
63                 protected override XmlNodeList GetInnerXml () 
64                 {
65                         return xnl;
66                 }
67
68                 [MonoTODO("Missing some action - see InvalidXslt test")]
69                 public override object GetOutput () 
70                 {
71                         return (object) cs;
72                 }
73
74                 public override object GetOutput (Type type) 
75                 {
76                         if (type != Type.GetType ("System.IO.Stream"))
77                                 throw new ArgumentException ("type");
78                         return GetOutput ();
79                 }
80
81                 public override void LoadInnerXml (XmlNodeList nodeList) 
82                 {
83                         if (nodeList == null)
84                                 throw new CryptographicException ("nodeList");
85                         xnl = nodeList;
86                 }
87
88                 [MonoTODO()]
89                 public override void LoadInput (object obj) 
90                 {
91                         XslTransform xsl = new XslTransform ();
92                         XmlDocument doc = new XmlDocument ();
93                         doc.XmlResolver = GetResolver ();
94                         Stream stream = null;
95
96                         // possible input: Stream, XmlDocument, and XmlNodeList
97                         if (obj is Stream) {
98                                 doc.Load (obj as Stream);
99                                 xsl.Load (doc);
100                         }
101                         else if (obj is XmlDocument) {
102                                 xsl.Load (obj as XmlDocument);
103                         }
104                         else if (obj is XmlNodeList) {
105                                 // Is it valid operation?
106                         }
107
108                         if (xnl != null) {
109                                 stream = new MemoryStream ();
110                                 // only possible output: Stream
111                                 xsl.Transform (doc, null, stream);
112                         }
113
114                         if (stream != null)
115                                 cs = new CryptoStream (stream, new FromBase64Transform (), CryptoStreamMode.Read);
116                         else
117                                 cs = null;
118                         // note: there is no default are other types won't throw an exception
119                 }
120         }
121 }