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 private Type
[] output
;
46 public XmlDsigBase64Transform ()
48 Algorithm
= XmlSignature
.AlgorithmNamespaces
.XmlDsigBase64Transform
;
51 public override Type
[] InputTypes
{
55 input
[0] = typeof (System
.IO
.Stream
);
56 input
[1] = typeof (System
.Xml
.XmlDocument
);
57 input
[2] = typeof (System
.Xml
.XmlNodeList
);
63 public override Type
[] OutputTypes
{
66 output
= new Type
[1];
67 output
[0] = typeof (System
.IO
.Stream
);
73 protected override XmlNodeList
GetInnerXml ()
75 return null; // THIS IS DOCUMENTED AS SUCH
78 public override object GetOutput ()
83 public override object GetOutput (Type type
)
85 if (type
!= typeof (System
.IO
.Stream
))
86 throw new ArgumentException ("type");
90 public override void LoadInnerXml (XmlNodeList nodeList
)
92 // documented as not changing the state of the transform
95 public override void LoadInput (object obj
)
97 XmlNodeList xnl
= null;
101 stream
= (obj
as Stream
);
102 else if (obj
is XmlDocument
)
103 xnl
= (obj
as XmlDocument
).SelectNodes ("//.");
104 else if (obj
is XmlNodeList
)
105 xnl
= (XmlNodeList
) obj
;
108 stream
= new MemoryStream ();
109 StreamWriter sw
= new StreamWriter (stream
);
110 foreach (XmlNode xn
in xnl
) {
111 switch (xn
.NodeType
) {
112 case XmlNodeType
.Attribute
:
113 case XmlNodeType
.Text
:
114 case XmlNodeType
.CDATA
:
115 case XmlNodeType
.SignificantWhitespace
:
116 case XmlNodeType
.Whitespace
:
122 // ready to be re-used
127 cs
= new CryptoStream (stream
, new FromBase64Transform (), CryptoStreamMode
.Read
);
128 // note: there is no default are other types won't throw an exception