2 // XmlDsigXPathTransform.cs -
3 // XmlDsigXPathTransform implementation for XML Signature
4 // http://www.w3.org/TR/1999/REC-xpath-19991116
7 // Sebastien Pouliot <sebastien@ximian.com>
9 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
10 // (C) 2004 Novell (http://www.novell.com)
17 namespace System.Security.Cryptography.Xml {
19 // www.w3.org/TR/xmldsig-core/
20 // see Section 6.6.3 of the XMLDSIG specification
22 public class XmlDsigXPathTransform : Transform {
25 private Type[] output;
26 private XmlNodeList xpath;
27 private XmlDocument doc;
29 public XmlDsigXPathTransform ()
31 Algorithm = "http://www.w3.org/TR/1999/REC-xpath-19991116";
34 public override Type[] InputTypes {
38 // this way the result is cached if called multiple time
40 input[0] = typeof (System.IO.Stream);
41 input[1] = typeof (System.Xml.XmlDocument);
42 input[2] = typeof (System.Xml.XmlNodeList);
49 public override Type[] OutputTypes {
53 // this way the result is cached if called multiple time
54 output = new Type [1];
55 output[0] = typeof (System.Xml.XmlNodeList);
62 protected override XmlNodeList GetInnerXml ()
66 XmlDocument doc = new XmlDocument ();
67 doc.LoadXml ("<XPath xmlns=\"" + XmlSignature.NamespaceURI + "\"></XPath>");
68 xpath = doc.ChildNodes;
73 public override object GetOutput ()
75 // note: this will throw a NullReferenceException if
76 // doc is null - just like MS implementation does
77 if ((xpath == null) || (xpath.Count < 1)) {
78 // can't create an XmlNodeList
79 XmlDocument xd = new XmlDocument ();
82 return doc.ChildNodes;
83 //* I know it doesn't make a lot of sense - but this is what the MS framework
84 //* returns - I must miss something really bad
85 //* return doc.DocumentElement.SelectNodes (xpath [0].InnerXml);
88 public override object GetOutput (Type type)
90 if (type != typeof (XmlNodeList))
91 throw new ArgumentException ("type");
95 public override void LoadInnerXml (XmlNodeList nodeList)
98 throw new CryptographicException ("nodeList");
102 public override void LoadInput (object obj)
104 // possible input: Stream, XmlDocument, and XmlNodeList
106 doc = new XmlDocument ();
107 doc.XmlResolver = GetResolver ();
108 doc.Load (obj as Stream);
110 else if (obj is XmlDocument) {
111 doc = (obj as XmlDocument);
113 else if (obj is XmlNodeList) {
114 doc = new XmlDocument ();
115 doc.XmlResolver = GetResolver ();
116 foreach (XmlNode xn in (obj as XmlNodeList)) {
117 XmlNode importedNode = doc.ImportNode (xn, true);
118 doc.AppendChild (importedNode);