Transform.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // Transform.cs - Transform implementation for XML Signature
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. // Atsushi Enomoto <[email protected]>
  7. // Tim Coleman <[email protected]>
  8. //
  9. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  10. // Copyright (C) Tim Coleman, 2004
  11. // (C) 2004 Novell (http://www.novell.com)
  12. //
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System.Collections;
  34. using System.Runtime.InteropServices;
  35. using System.Security.Policy;
  36. using System.Xml;
  37. namespace System.Security.Cryptography.Xml {
  38. public abstract class Transform {
  39. private string algo;
  40. private XmlResolver xmlResolver;
  41. public Transform ()
  42. {
  43. // FIXME: enable it after CAS implementation
  44. #if false // NET_1_1
  45. xmlResolver = new XmlSecureResolver (new XmlUrlResolver (), (Evidence) new Evidence ());
  46. #else
  47. xmlResolver = new XmlUrlResolver ();
  48. #endif
  49. }
  50. #region Properties
  51. public string Algorithm {
  52. get { return algo; }
  53. set { algo = value; }
  54. }
  55. public abstract Type[] InputTypes {
  56. get;
  57. }
  58. public abstract Type[] OutputTypes {
  59. get;
  60. }
  61. #if NET_1_1
  62. [ComVisible(false)]
  63. public XmlResolver Resolver {
  64. set { xmlResolver = value; }
  65. }
  66. #endif
  67. #if NET_2_0
  68. [MonoTODO]
  69. public XmlElement Context {
  70. get { throw new NotImplementedException (); }
  71. set { throw new NotImplementedException (); }
  72. }
  73. [MonoTODO]
  74. public Hashtable PropagatedNamespaces {
  75. get { throw new NotImplementedException (); }
  76. set { throw new NotImplementedException (); }
  77. }
  78. #endif
  79. #endregion // Properties
  80. #region Methods
  81. #if NET_2_0
  82. [MonoTODO]
  83. public virtual byte[] GetDigestedOutput (HashAlgorithm hash)
  84. {
  85. throw new NotImplementedException ();
  86. }
  87. #endif
  88. protected abstract XmlNodeList GetInnerXml ();
  89. public abstract object GetOutput ();
  90. public abstract object GetOutput (Type type);
  91. public XmlElement GetXml ()
  92. {
  93. XmlDocument document = new XmlDocument ();
  94. document.XmlResolver = GetResolver ();
  95. XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI);
  96. xel.SetAttribute (XmlSignature.AttributeNames.Algorithm, algo);
  97. XmlNodeList xnl = this.GetInnerXml ();
  98. if (xnl != null) {
  99. foreach (XmlNode xn in xnl) {
  100. XmlNode importedNode = document.ImportNode (xn, true);
  101. xel.AppendChild (importedNode);
  102. }
  103. }
  104. return xel;
  105. }
  106. public abstract void LoadInnerXml (XmlNodeList nodeList);
  107. public abstract void LoadInput (object obj);
  108. internal XmlResolver GetResolver ()
  109. {
  110. return xmlResolver;
  111. }
  112. #endregion // Methods
  113. }
  114. }