XmlDsigC14NTransform.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // XmlDsigC14NTransform.cs - C14N Transform implementation for XML Signature
  3. // http://www.w3.org/TR/xml-c14n
  4. //
  5. // Author:
  6. // Sebastien Pouliot ([email protected])
  7. //
  8. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  9. //
  10. using System.IO;
  11. using System.Text;
  12. using System.Xml;
  13. namespace System.Security.Cryptography.Xml {
  14. [MonoTODO]
  15. public class XmlDsigC14NTransform : Transform {
  16. private Type[] input;
  17. private Type[] output;
  18. private bool comments;
  19. private Stream s;
  20. public XmlDsigC14NTransform ()
  21. {
  22. Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
  23. comments = false;
  24. }
  25. public XmlDsigC14NTransform (bool includeComments)
  26. {
  27. comments = includeComments;
  28. }
  29. public override Type[] InputTypes {
  30. get {
  31. if (input == null) {
  32. lock (this) {
  33. // this way the result is cached if called multiple time
  34. input = new Type [3];
  35. input[0] = typeof (System.IO.Stream);
  36. input[1] = typeof (System.Xml.XmlDocument);
  37. input[2] = typeof (System.Xml.XmlNodeList);
  38. }
  39. }
  40. return input;
  41. }
  42. }
  43. public override Type[] OutputTypes {
  44. get {
  45. if (output == null) {
  46. lock (this) {
  47. // this way the result is cached if called multiple time
  48. output = new Type [1];
  49. output[0] = typeof (System.IO.Stream);
  50. }
  51. }
  52. return output;
  53. }
  54. }
  55. protected override XmlNodeList GetInnerXml ()
  56. {
  57. return null; // THIS IS DOCUMENTED AS SUCH
  58. }
  59. public override object GetOutput ()
  60. {
  61. return (object) s;
  62. }
  63. public override object GetOutput (Type type)
  64. {
  65. if (type == Type.GetType ("Stream"))
  66. return GetOutput ();
  67. throw new ArgumentException ("type");
  68. }
  69. public override void LoadInnerXml (XmlNodeList nodeList)
  70. {
  71. // documented as not changing the state of the transform
  72. }
  73. public override void LoadInput (object obj)
  74. {
  75. XmlNodeList xnl = null;
  76. if (obj is Stream)
  77. s = (obj as Stream);
  78. else if (obj is XmlDocument)
  79. xnl = (obj as XmlDocument).ChildNodes;
  80. else if (obj is XmlNodeList)
  81. xnl = (XmlNodeList) obj;
  82. if (xnl != null) {
  83. StringBuilder sb = new StringBuilder ();
  84. foreach (XmlNode xn in xnl)
  85. sb.Append (xn.InnerText);
  86. UTF8Encoding utf8 = new UTF8Encoding ();
  87. byte[] data = utf8.GetBytes (sb.ToString ());
  88. s = new MemoryStream (data);
  89. }
  90. // note: there is no default are other types won't throw an exception
  91. }
  92. }
  93. }