private XmlCanonicalizer canonicalizer;
private Stream s;
- public XmlDsigC14NTransform ()
+ public XmlDsigC14NTransform () : this (false)
{
- Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
- canonicalizer = new XmlCanonicalizer (false, false);
}
public XmlDsigC14NTransform (bool includeComments)
{
- canonicalizer = new XmlCanonicalizer (includeComments, false);
+ if (includeComments)
+ Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform;
+ else
+ Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform;
+ canonicalizer = new XmlCanonicalizer (includeComments, false, PropagatedNamespaces);
}
public override Type[] InputTypes {
get {
if (input == null) {
- lock (this) {
- // this way the result is cached if called multiple time
- input = new Type [3];
- input[0] = typeof (System.IO.Stream);
- input[1] = typeof (System.Xml.XmlDocument);
- input[2] = typeof (System.Xml.XmlNodeList);
- }
+ input = new Type [3];
+ input[0] = typeof (System.IO.Stream);
+ input[1] = typeof (System.Xml.XmlDocument);
+ input[2] = typeof (System.Xml.XmlNodeList);
}
return input;
}
public override Type[] OutputTypes {
get {
if (output == null) {
- lock (this) {
- // this way the result is cached if called multiple time
- output = new Type [1];
- output[0] = typeof (System.IO.Stream);
- }
+ output = new Type [1];
+ output[0] = typeof (System.IO.Stream);
}
return output;
}
return null; // THIS IS DOCUMENTED AS SUCH
}
-#if NET_2_0
[ComVisible (false)]
public override byte[] GetDigestedOutput (HashAlgorithm hash)
{
+ // no null check, MS throws a NullReferenceException here
return hash.ComputeHash ((Stream) GetOutput ());
}
-#endif
public override object GetOutput ()
{
public override object GetOutput (Type type)
{
- if (type == Type.GetType ("Stream"))
+ if (type == typeof (Stream))
return GetOutput ();
throw new ArgumentException ("type");
}
public override void LoadInput (object obj)
{
- if (obj is Stream) {
- s = (obj as Stream);
+ // possible input: Stream, XmlDocument, and XmlNodeList
+ Stream stream = (obj as Stream);
+ if (stream != null) {
XmlDocument doc = new XmlDocument ();
doc.PreserveWhitespace = true; // REALLY IMPORTANT
-#if NET_1_1
doc.XmlResolver = GetResolver ();
-#endif
- doc.Load (new XmlSignatureStreamReader (
- new StreamReader ((Stream) obj)));
+ doc.Load (new XmlSignatureStreamReader (new StreamReader (stream)));
// doc.Load ((Stream) obj);
s = canonicalizer.Canonicalize (doc);
- } else if (obj is XmlDocument)
- s = canonicalizer.Canonicalize ((obj as XmlDocument));
- else if (obj is XmlNodeList)
- s = canonicalizer.Canonicalize ((obj as XmlNodeList));
-#if NET_2_0
+ return;
+ }
+
+ XmlDocument xd = (obj as XmlDocument);
+ if (xd != null) {
+ s = canonicalizer.Canonicalize (xd);
+ return;
+ }
+
+ XmlNodeList nl = (obj as XmlNodeList);
+ if (nl != null) {
+ s = canonicalizer.Canonicalize (nl);
+ }
else
throw new ArgumentException ("obj");
-#else
- // note: there is no default are other types won't throw an exception
-#endif
}
}
}