This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Security / XmlDsigExcC14NTransform.cs
1 //\r
2 // XmlDsigExcC14NTransform.cs: \r
3 //      Handles WS-Security XmlDsigExcC14NTransform\r
4 //\r
5 // Author:\r
6 //      Sebastien Pouliot <sebastien@ximian.com>\r
7 //      Aleksey Sanin (aleksey@aleksey.com)\r
8 //\r
9 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)\r
10 // (C) 2003 Aleksey Sanin (aleksey@aleksey.com)\r
11 // (C) 2004 Novell (http://www.novell.com)\r
12 //\r
13 \r
14 using System;\r
15 using System.IO;\r
16 using System.Security.Cryptography.Xml;\r
17 using System.Xml;\r
18 \r
19 using Mono.Xml;\r
20 \r
21 namespace Microsoft.Web.Services.Security {\r
22 \r
23         public class XmlDsigExcC14NTransform : Transform {\r
24 \r
25                 public const string XmlDsigExcC14NTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#";\r
26                 public const string XmlDsigExcC14NWithCommentsTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";\r
27 \r
28                 private Type[] input;\r
29                 private Type[] output;\r
30                 private XmlCanonicalizer canonicalizer;\r
31                 private Stream s;\r
32                 private string prefixList;\r
33                 private bool comments;\r
34 \r
35                 public XmlDsigExcC14NTransform () : this (false)\r
36                 {\r
37                 }\r
38 \r
39                 public XmlDsigExcC14NTransform (bool includeComments) \r
40                 {\r
41                         comments = includeComments;\r
42                         canonicalizer = new XmlCanonicalizer (includeComments, true);\r
43                 }\r
44 \r
45                 public XmlDsigExcC14NTransform (string inclusiveNamespacesPrefixList)\r
46                         : this (false, inclusiveNamespacesPrefixList)\r
47                 {\r
48                 }\r
49 \r
50                 public XmlDsigExcC14NTransform (bool includeComments, string inclusiveNamespacesPrefixList)\r
51                         : this (includeComments) \r
52                 {\r
53                         prefixList = inclusiveNamespacesPrefixList;\r
54                 }\r
55 \r
56                 public string InclusiveNamespacesPrefixList {\r
57                         get { return prefixList; }\r
58                         set { prefixList = value; }\r
59                 }\r
60 \r
61                 public override Type[] InputTypes {\r
62                         get {\r
63                                 if (input == null) {\r
64                                         lock (this) {\r
65                                                 // this way the result is cached if called multiple time\r
66                                                 input = new Type [3];\r
67                                                 input[0] = typeof (System.IO.Stream);\r
68                                                 input[1] = typeof (System.Xml.XmlDocument);\r
69                                                 input[2] = typeof (System.Xml.XmlNodeList);\r
70                                         }\r
71                                 }\r
72                                 return input;\r
73                         }\r
74                 }\r
75 \r
76                 public override Type[] OutputTypes {\r
77                         get {\r
78                                 if (output == null) {\r
79                                         lock (this) {\r
80                                                 // this way the result is cached if called multiple time\r
81                                                 output = new Type [1];\r
82                                                 output[0] = typeof (System.IO.Stream);\r
83                                         }\r
84                                 }\r
85                                 return output;\r
86                         }\r
87                 }\r
88                 protected override XmlNodeList GetInnerXml () \r
89                 {\r
90                         return null; // THIS IS DOCUMENTED AS SUCH\r
91                 }\r
92 \r
93                 public override object GetOutput () \r
94                 {\r
95                         return (object) s;\r
96                 }\r
97 \r
98                 public override object GetOutput (Type type) \r
99                 {\r
100                         if (type != typeof (Stream))\r
101                                 throw new ArgumentException ("type");\r
102                         return GetOutput ();\r
103                 }\r
104 \r
105                 public override void LoadInnerXml (XmlNodeList nodeList) \r
106                 {\r
107                         // documented as not changing the state of the transform\r
108                 }\r
109 \r
110                 public override void LoadInput (object obj) \r
111                 {\r
112                         if (obj is Stream) {\r
113                                 s = (obj as Stream);\r
114                                 XmlDocument doc = new XmlDocument ();\r
115                                 doc.PreserveWhitespace = true;  // REALLY IMPORTANT\r
116                                 doc.Load (obj as Stream);\r
117                                 s = canonicalizer.Canonicalize (doc);\r
118                         } else if (obj is XmlDocument)\r
119                                 s = canonicalizer.Canonicalize ((obj as XmlDocument));\r
120                         else if (obj is XmlNodeList)\r
121                                 s = canonicalizer.Canonicalize ((obj as XmlNodeList));\r
122                         // note: there is no default are other types won't throw an exception\r
123                 }\r
124         }\r
125 }\r