2 // XmlDsigBase64Transform.cs - Base64 Transform implementation for XML Signature
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 // (C) 2004 Novell (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Security
.Cryptography
;
37 namespace System
.Security
.Cryptography
.Xml
{
39 // http://www.w3.org/2000/09/xmldsig#base64
40 public class XmlDsigBase64Transform
: Transform
{
42 private CryptoStream cs
;
44 public XmlDsigBase64Transform ()
46 Algorithm
= "http://www.w3.org/2000/09/xmldsig#base64";
49 public override Type
[] InputTypes
{
51 Type
[] input
= new Type
[3];
52 input
[0] = typeof (System
.IO
.Stream
);
53 input
[1] = typeof (System
.Xml
.XmlDocument
);
54 input
[2] = typeof (System
.Xml
.XmlNodeList
);
59 public override Type
[] OutputTypes
{
61 Type
[] output
= new Type
[1];
62 output
[0] = typeof (System
.IO
.Stream
);
67 protected override XmlNodeList
GetInnerXml ()
69 return null; // THIS IS DOCUMENTED AS SUCH
72 public override object GetOutput ()
77 public override object GetOutput (Type type
)
79 if (type
!= typeof (System
.IO
.Stream
))
80 throw new ArgumentException ("type");
84 public override void LoadInnerXml (XmlNodeList nodeList
)
86 // documented as not changing the state of the transform
89 public override void LoadInput (object obj
)
91 XmlNodeList xnl
= null;
95 stream
= (obj
as Stream
);
96 else if (obj
is XmlDocument
)
97 xnl
= (obj
as XmlDocument
).SelectNodes ("//.");
98 else if (obj
is XmlNodeList
)
99 xnl
= (XmlNodeList
) obj
;
102 stream
= new MemoryStream ();
103 StreamWriter sw
= new StreamWriter (stream
);
104 foreach (XmlNode xn
in xnl
) {
105 switch (xn
.NodeType
) {
106 case XmlNodeType
.Attribute
:
107 case XmlNodeType
.Text
:
108 case XmlNodeType
.CDATA
:
109 case XmlNodeType
.SignificantWhitespace
:
110 case XmlNodeType
.Whitespace
:
116 // ready to be re-used
121 cs
= new CryptoStream (stream
, new FromBase64Transform (), CryptoStreamMode
.Read
);
122 // note: there is no default are other types won't throw an exception