XmlDsigXPathTransform.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // XmlDsigXPathTransform.cs -
  3. // XmlDsigXPathTransform implementation for XML Signature
  4. // http://www.w3.org/TR/1999/REC-xpath-19991116
  5. //
  6. // Author:
  7. // Sebastien Pouliot ([email protected])
  8. //
  9. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  10. //
  11. using System.IO;
  12. using System.Text;
  13. using System.Xml;
  14. namespace System.Security.Cryptography.Xml {
  15. // www.w3.org/TR/xmldsig-core/
  16. // see Section 6.6.3 of the XMLDSIG specification
  17. [MonoTODO]
  18. public class XmlDsigXPathTransform : Transform {
  19. private Type[] input;
  20. private Type[] output;
  21. private XmlNodeList xnl;
  22. private XmlNodeList xpathNodes;
  23. public XmlDsigXPathTransform ()
  24. {
  25. }
  26. public override Type[] InputTypes {
  27. get {
  28. if (input == null) {
  29. lock (this) {
  30. // this way the result is cached if called multiple time
  31. input = new Type [3];
  32. input[0] = typeof (System.IO.Stream);
  33. input[1] = typeof (System.Xml.XmlDocument);
  34. input[2] = typeof (System.Xml.XmlNodeList);
  35. }
  36. }
  37. return input;
  38. }
  39. }
  40. public override Type[] OutputTypes {
  41. get {
  42. if (output == null) {
  43. lock (this) {
  44. // this way the result is cached if called multiple time
  45. output = new Type [1];
  46. output[0] = typeof (System.IO.Stream);
  47. }
  48. }
  49. return output;
  50. }
  51. }
  52. protected override XmlNodeList GetInnerXml ()
  53. {
  54. return xnl;
  55. }
  56. public override object GetOutput ()
  57. {
  58. return xpathNodes;
  59. }
  60. public override object GetOutput (Type type)
  61. {
  62. if (type != typeof (XmlNodeList))
  63. throw new ArgumentException ("type");
  64. return GetOutput ();
  65. }
  66. public override void LoadInnerXml (XmlNodeList nodeList)
  67. {
  68. if (nodeList == null)
  69. throw new CryptographicException ("nodeList");
  70. xnl = nodeList;
  71. }
  72. public override void LoadInput (object obj)
  73. {
  74. XmlNode xn = null;
  75. // possible input: Stream, XmlDocument, and XmlNodeList
  76. if (obj is Stream) {
  77. XmlDocument doc = new XmlDocument ();
  78. doc.Load (obj as Stream);
  79. }
  80. else if (obj is XmlDocument) {
  81. }
  82. else if (obj is XmlNodeList) {
  83. xnl = (XmlNodeList) obj;
  84. }
  85. if (xn != null) {
  86. string xpath = xn.InnerXml;
  87. // only possible output: XmlNodeList
  88. xpathNodes = xnl[0].SelectNodes (xpath);
  89. }
  90. else
  91. xpathNodes = null;
  92. }
  93. }
  94. }