XmlDsigXsltTransform.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // XmlDsigEnvelopedSignatureTransform.cs -
  3. // Enveloped Signature Transform implementation for XML Signature
  4. // http://www.w3.org/TR/1999/REC-xslt-19991116
  5. //
  6. // Author:
  7. // Sebastien Pouliot ([email protected])
  8. //
  9. // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
  10. //
  11. using System.IO;
  12. using System.Security.Cryptography;
  13. using System.Xml;
  14. using System.Xml.Xsl;
  15. namespace System.Security.Cryptography.Xml {
  16. public class XmlDsigXsltTransform : Transform {
  17. private bool comments;
  18. private XmlNodeList xnl;
  19. private CryptoStream cs;
  20. public XmlDsigXsltTransform () : this (false) {}
  21. public XmlDsigXsltTransform (bool includeComments)
  22. {
  23. comments = includeComments;
  24. algo = "http://www.w3.org/TR/1999/REC-xslt-19991116";
  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 (object) cs;
  59. }
  60. public override object GetOutput (Type type)
  61. {
  62. if (type != Type.GetType ("System.IO.Stream"))
  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. [MonoTODO()]
  73. public override void LoadInput (object obj)
  74. {
  75. XslTransform xsl = new XslTransform ();
  76. XmlDocument doc = new XmlDocument ();
  77. Stream stream = null;
  78. // possible input: Stream, XmlDocument, and XmlNodeList
  79. if (obj is Stream) {
  80. doc.Load (obj as Stream);
  81. xsl.Load (doc);
  82. }
  83. else if (obj is XmlDocument) {
  84. xsl.Load (obj as XmlDocument);
  85. }
  86. else if (obj is XmlNodeList) {
  87. // xnl = (XmlNodeList) obj;
  88. // xsl.Load (obj a);
  89. }
  90. if (xnl != null) {
  91. stream = new MemoryStream ();
  92. // only possible output: Stream
  93. xsl.Transform (doc, null, stream);
  94. }
  95. if (stream != null)
  96. cs = new CryptoStream (stream, new FromBase64Transform (), CryptoStreamMode.Read);
  97. else
  98. cs = null;
  99. // note: there is no default are other types won't throw an exception
  100. }
  101. }
  102. }