Make MonoTODO attributes internal.
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / XmlDsigC14NTransform.cs
1 //
2 // XmlDsigC14NTransform.cs - C14N Transform implementation for XML Signature
3 // http://www.w3.org/TR/xml-c14n
4 //
5 // Author:
6 //      Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 //
10
11 using System.IO;
12 using System.Text;
13 using System.Xml;
14
15 namespace System.Security.Cryptography.Xml { 
16
17         [MonoTODO]
18         public class XmlDsigC14NTransform : Transform {
19
20                 private Type[] input;
21                 private Type[] output;
22                 private bool comments;
23                 private Stream s;
24
25                 public XmlDsigC14NTransform () 
26                 {
27                         Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
28                         comments = false;
29                 }
30
31                 public XmlDsigC14NTransform (bool includeComments) 
32                 {
33                         comments = includeComments;
34                 }
35
36                 public override Type[] InputTypes {
37                         get {
38                                 if (input == null) {
39                                         lock (this) {
40                                                 // this way the result is cached if called multiple time
41                                                 input = new Type [3];
42                                                 input[0] = typeof (System.IO.Stream);
43                                                 input[1] = typeof (System.Xml.XmlDocument);
44                                                 input[2] = typeof (System.Xml.XmlNodeList);
45                                         }
46                                 }
47                                 return input;
48                         }
49                 }
50
51                 public override Type[] OutputTypes {
52                         get {
53                                 if (output == null) {
54                                         lock (this) {
55                                                 // this way the result is cached if called multiple time
56                                                 output = new Type [1];
57                                                 output[0] = typeof (System.IO.Stream);
58                                         }
59                                 }
60                                 return output;
61                         }
62                 }
63
64                 protected override XmlNodeList GetInnerXml () 
65                 {
66                         return null; // THIS IS DOCUMENTED AS SUCH
67                 }
68
69                 public override object GetOutput () 
70                 {
71                         return (object) s;
72                 }
73
74                 public override object GetOutput (Type type) 
75                 {
76                         if (type == Type.GetType ("Stream"))
77                                 return GetOutput ();
78                         throw new ArgumentException ("type");
79                 }
80
81                 public override void LoadInnerXml (XmlNodeList nodeList) 
82                 {
83                         // documented as not changing the state of the transform
84                 }
85
86                 public override void LoadInput (object obj) 
87                 {
88                         XmlNodeList xnl = null;
89
90                         if (obj is Stream) 
91                                 s = (obj as Stream);
92                         else if (obj is XmlDocument)
93                                 xnl = (obj as XmlDocument).ChildNodes;
94                         else if (obj is XmlNodeList)
95                                 xnl = (XmlNodeList) obj;
96
97                         if (xnl != null) {
98                                 StringBuilder sb = new StringBuilder ();
99                                 foreach (XmlNode xn in xnl)
100                                         sb.Append (xn.InnerText);
101
102                                 UTF8Encoding utf8 = new UTF8Encoding ();
103                                 byte[] data = utf8.GetBytes (sb.ToString ());
104                                 s = new MemoryStream (data);
105                         }
106
107                         // note: there is no default are other types won't throw an exception
108                 }
109         }
110 }