XmlDsigXPathTransform.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. Algorithm = "http://www.w3.org/TR/1999/REC-xpath-19991116";
  26. }
  27. public override Type[] InputTypes {
  28. get {
  29. if (input == null) {
  30. lock (this) {
  31. // this way the result is cached if called multiple time
  32. input = new Type [3];
  33. input[0] = typeof (System.IO.Stream);
  34. input[1] = typeof (System.Xml.XmlDocument);
  35. input[2] = typeof (System.Xml.XmlNodeList);
  36. }
  37. }
  38. return input;
  39. }
  40. }
  41. public override Type[] OutputTypes {
  42. get {
  43. if (output == null) {
  44. lock (this) {
  45. // this way the result is cached if called multiple time
  46. output = new Type [1];
  47. output[0] = typeof (System.IO.Stream);
  48. }
  49. }
  50. return output;
  51. }
  52. }
  53. protected override XmlNodeList GetInnerXml ()
  54. {
  55. return xnl;
  56. }
  57. public override object GetOutput ()
  58. {
  59. return xpathNodes;
  60. }
  61. public override object GetOutput (Type type)
  62. {
  63. if (type != typeof (XmlNodeList))
  64. throw new ArgumentException ("type");
  65. return GetOutput ();
  66. }
  67. public override void LoadInnerXml (XmlNodeList nodeList)
  68. {
  69. if (nodeList == null)
  70. throw new CryptographicException ("nodeList");
  71. xnl = nodeList;
  72. }
  73. public override void LoadInput (object obj)
  74. {
  75. XmlNode xn = null;
  76. // possible input: Stream, XmlDocument, and XmlNodeList
  77. if (obj is Stream) {
  78. XmlDocument doc = new XmlDocument ();
  79. doc.Load (obj as Stream);
  80. }
  81. else if (obj is XmlDocument) {
  82. }
  83. else if (obj is XmlNodeList) {
  84. xnl = (XmlNodeList) obj;
  85. }
  86. if (xn != null) {
  87. string xpath = xn.InnerXml;
  88. // only possible output: XmlNodeList
  89. xpathNodes = xnl[0].SelectNodes (xpath);
  90. }
  91. else
  92. xpathNodes = null;
  93. }
  94. }
  95. }