XmlDsigXsltTransform.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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, 2003 Motus Technologies Inc. (http://www.motus.com)
  10. //
  11. using System.IO;
  12. using System.Xml;
  13. using System.Xml.Xsl;
  14. namespace System.Security.Cryptography.Xml {
  15. [MonoTODO]
  16. public class XmlDsigXsltTransform : Transform {
  17. private Type[] input;
  18. private Type[] output;
  19. private bool comments;
  20. private XmlNodeList xnl;
  21. private CryptoStream cs;
  22. public XmlDsigXsltTransform () : this (false) {}
  23. public XmlDsigXsltTransform (bool includeComments)
  24. {
  25. comments = includeComments;
  26. Algorithm = "http://www.w3.org/TR/1999/REC-xslt-19991116";
  27. }
  28. public override Type[] InputTypes {
  29. get {
  30. if (input == null) {
  31. lock (this) {
  32. // this way the result is cached if called multiple time
  33. input = new Type [3];
  34. input[0] = typeof (System.IO.Stream);
  35. input[1] = typeof (System.Xml.XmlDocument);
  36. input[2] = typeof (System.Xml.XmlNodeList);
  37. }
  38. }
  39. return input;
  40. }
  41. }
  42. public override Type[] OutputTypes {
  43. get {
  44. if (output == null) {
  45. lock (this) {
  46. // this way the result is cached if called multiple time
  47. output = new Type [1];
  48. output[0] = typeof (System.IO.Stream);
  49. }
  50. }
  51. return output;
  52. }
  53. }
  54. protected override XmlNodeList GetInnerXml ()
  55. {
  56. return xnl;
  57. }
  58. [MonoTODO("Missing some action - see InvalidXslt test")]
  59. public override object GetOutput ()
  60. {
  61. return (object) cs;
  62. }
  63. public override object GetOutput (Type type)
  64. {
  65. if (type != Type.GetType ("System.IO.Stream"))
  66. throw new ArgumentException ("type");
  67. return GetOutput ();
  68. }
  69. public override void LoadInnerXml (XmlNodeList nodeList)
  70. {
  71. if (nodeList == null)
  72. throw new CryptographicException ("nodeList");
  73. xnl = nodeList;
  74. }
  75. [MonoTODO()]
  76. public override void LoadInput (object obj)
  77. {
  78. XslTransform xsl = new XslTransform ();
  79. XmlDocument doc = new XmlDocument ();
  80. doc.XmlResolver = GetResolver ();
  81. Stream stream = null;
  82. // possible input: Stream, XmlDocument, and XmlNodeList
  83. if (obj is Stream) {
  84. doc.Load (obj as Stream);
  85. xsl.Load (doc);
  86. }
  87. else if (obj is XmlDocument) {
  88. xsl.Load (obj as XmlDocument);
  89. }
  90. else if (obj is XmlNodeList) {
  91. // Is it valid operation?
  92. }
  93. if (xnl != null) {
  94. stream = new MemoryStream ();
  95. // only possible output: Stream
  96. xsl.Transform (doc, null, stream);
  97. }
  98. if (stream != null)
  99. cs = new CryptoStream (stream, new FromBase64Transform (), CryptoStreamMode.Read);
  100. else
  101. cs = null;
  102. // note: there is no default are other types won't throw an exception
  103. }
  104. }
  105. }