2004-05-05 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / Transform.cs
1 //
2 // Transform.cs - Transform implementation for XML Signature
3 //
4 // Author:
5 //      Sebastien Pouliot <sebastien@ximian.com>
6 //      Atsushi Enomoto <atsushi@ximian.com>
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 // (C) 2004 Novell (http://www.novell.com)
10 //
11
12 using System.Runtime.InteropServices;
13 using System.Security.Policy;
14 using System.Xml;
15
16 namespace System.Security.Cryptography.Xml { 
17
18         public abstract class Transform {
19
20                 private string algo;
21                 private XmlResolver xmlResolver;
22
23                 public Transform ()
24                 {
25                 // FIXME: enable it after CAS implementation
26 #if false // NET_1_1
27                         xmlResolver = new XmlSecureResolver (new XmlUrlResolver (), (Evidence) new Evidence ());
28 #else
29                         xmlResolver = new XmlUrlResolver ();
30 #endif
31                 }
32
33                 public string Algorithm {
34                         get { return algo; }
35                         set { algo = value; }
36                 }
37
38                 public abstract Type[] InputTypes {
39                         get;
40                 }
41
42                 public abstract Type[] OutputTypes {
43                         get;
44                 }
45
46                 protected abstract XmlNodeList GetInnerXml ();
47
48                 public abstract object GetOutput ();
49
50                 public abstract object GetOutput (Type type);
51
52                 public XmlElement GetXml () 
53                 {
54                         XmlDocument document = new XmlDocument ();
55                         document.XmlResolver = GetResolver ();
56                         XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI);
57                         xel.SetAttribute (XmlSignature.AttributeNames.Algorithm, algo);
58                         XmlNodeList xnl = this.GetInnerXml ();
59                         if (xnl != null) {
60                                 foreach (XmlNode xn in xnl) {
61                                         XmlNode importedNode = document.ImportNode (xn, true);
62                                         xel.AppendChild (importedNode);
63                                 }
64                         }
65                         return xel;
66                 }
67
68                 public abstract void LoadInnerXml (XmlNodeList nodeList);
69
70                 public abstract void LoadInput (object obj);
71
72                 internal XmlResolver GetResolver ()
73                 {
74                         return xmlResolver;
75                 }
76
77 #if NET_1_1
78                 [ComVisible(false)]
79                 public XmlResolver Resolver {
80                         set { xmlResolver = value; }
81                 }
82 #endif
83         }
84 }