2002-11-28 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / XmlDsigXPathTransform.cs
1 //
2 // XmlDsigXPathTransform.cs - 
3 //      XmlDsigXPathTransform implementation for XML Signature
4 // http://www.w3.org/TR/1999/REC-xpath-19991116 
5 //
6 // Author:
7 //      Sebastien Pouliot (spouliot@motus.com)
8 //
9 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
10 //
11
12 using System.IO;
13 using System.Security.Cryptography;
14 using System.Text;
15 using System.Xml;
16
17 namespace System.Security.Cryptography.Xml {
18
19 // www.w3.org/TR/xmldsig-core/
20 // see Section 6.6.3 of the XMLDSIG specification
21 public class XmlDsigXPathTransform : Transform {
22
23         private XmlNodeList xnl;
24         private XmlNodeList xpathNodes;
25
26         public XmlDsigXPathTransform () 
27         {
28         }
29
30         public override Type[] InputTypes {
31                 get {
32                         if (input == null) {
33                                 lock (this) {
34                                         // this way the result is cached if called multiple time
35                                         input = new Type [3];
36                                         input[0] = typeof (System.IO.Stream);
37                                         input[1] = typeof (System.Xml.XmlDocument);
38                                         input[2] = typeof (System.Xml.XmlNodeList);
39                                 }
40                         }
41                         return input;
42                 }
43         }
44
45         public override Type[] OutputTypes {
46                 get {
47                         if (output == null) {
48                                 lock (this) {
49                                         // this way the result is cached if called multiple time
50                                         output = new Type [1];
51                                         output[0] = typeof (System.IO.Stream);
52                                 }
53                         }
54                         return output;
55                 }
56         }
57
58         protected override XmlNodeList GetInnerXml () 
59         {
60                 return xnl;
61         }
62
63         public override object GetOutput () 
64         {
65                 return xpathNodes;
66         }
67
68         public override object GetOutput (Type type) 
69         {
70                 if (type != typeof (XmlNodeList))
71                         throw new ArgumentException ("type");
72                 return GetOutput ();
73         }
74
75         public override void LoadInnerXml (XmlNodeList nodeList) 
76         {
77                 if (nodeList == null)
78                         throw new CryptographicException ("nodeList");
79                 xnl = nodeList;
80         }
81
82         public override void LoadInput (object obj) 
83         {
84                 XmlNode xn = null;
85                 // possible input: Stream, XmlDocument, and XmlNodeList
86                 if (obj is Stream) {
87                         XmlDocument doc = new XmlDocument ();
88                         doc.Load (obj as Stream);
89                 }
90                 else if (obj is XmlDocument) {
91                 }
92                 else if (obj is XmlNodeList) {
93                         xnl = (XmlNodeList) obj;
94                 }
95
96                 if (xn != null) {
97                         string xpath = xn.InnerXml;
98                         // only possible output: XmlNodeList
99                         xpathNodes = xnl[0].SelectNodes (xpath);
100                 }
101                 else
102                         xpathNodes = null;
103         }
104 }
105
106 }