XmlDsigC14NTransform.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // Aleksey Sanin ([email protected])
  8. //
  9. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  10. // (C) 2003 Aleksey Sanin ([email protected])
  11. //
  12. using System.Collections;
  13. using System.IO;
  14. using System.Text;
  15. using System.Xml;
  16. using Mono.Xml;
  17. namespace System.Security.Cryptography.Xml {
  18. public class XmlDsigC14NTransform : Transform {
  19. private Type[] input;
  20. private Type[] output;
  21. private XmlCanonicalizer canonicalizer;
  22. private Stream s;
  23. public XmlDsigC14NTransform ()
  24. {
  25. Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
  26. canonicalizer = new XmlCanonicalizer(false, false);
  27. }
  28. public XmlDsigC14NTransform (bool includeComments)
  29. {
  30. canonicalizer = new XmlCanonicalizer(includeComments, false);
  31. }
  32. public override Type[] InputTypes {
  33. get {
  34. if (input == null) {
  35. lock (this) {
  36. // this way the result is cached if called multiple time
  37. input = new Type [3];
  38. input[0] = typeof (System.IO.Stream);
  39. input[1] = typeof (System.Xml.XmlDocument);
  40. input[2] = typeof (System.Xml.XmlNodeList);
  41. }
  42. }
  43. return input;
  44. }
  45. }
  46. public override Type[] OutputTypes {
  47. get {
  48. if (output == null) {
  49. lock (this) {
  50. // this way the result is cached if called multiple time
  51. output = new Type [1];
  52. output[0] = typeof (System.IO.Stream);
  53. }
  54. }
  55. return output;
  56. }
  57. }
  58. protected override XmlNodeList GetInnerXml ()
  59. {
  60. return null; // THIS IS DOCUMENTED AS SUCH
  61. }
  62. public override object GetOutput ()
  63. {
  64. return (object) s;
  65. }
  66. public override object GetOutput (Type type)
  67. {
  68. if (type == Type.GetType ("Stream"))
  69. return GetOutput ();
  70. throw new ArgumentException ("type");
  71. }
  72. public override void LoadInnerXml (XmlNodeList nodeList)
  73. {
  74. // documented as not changing the state of the transform
  75. }
  76. [MonoTODO]
  77. public override void LoadInput (object obj)
  78. {
  79. if (obj is Stream) {
  80. s = (obj as Stream);
  81. // todo: parse doc from stream?
  82. } else if (obj is XmlDocument)
  83. s = canonicalizer.Canonicalize((obj as XmlDocument));
  84. else if (obj is XmlNodeList)
  85. s = canonicalizer.Canonicalize((obj as XmlNodeList));
  86. // note: there is no default are other types won't throw an exception
  87. }
  88. }
  89. }