XmlDsigXPathTransform.cs 2.1 KB

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