KeyInfoRetrievalMethod.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // KeyInfoRetrievalMethod.cs - KeyInfoRetrievalMethod implementation for XML Signature
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  9. // Copyright (C) Tim Coleman, 2004
  10. //
  11. using System.Xml;
  12. namespace System.Security.Cryptography.Xml {
  13. public class KeyInfoRetrievalMethod : KeyInfoClause {
  14. private string URI;
  15. private XmlElement element;
  16. #if NET_2_0
  17. string type;
  18. #endif
  19. public KeyInfoRetrievalMethod () {}
  20. public KeyInfoRetrievalMethod (string strUri)
  21. {
  22. URI = strUri;
  23. }
  24. #if NET_2_0
  25. public KeyInfoRetrievalMethod (string strUri, string strType)
  26. : this (strUri)
  27. {
  28. Type = strType;
  29. }
  30. public string Type {
  31. get { return type; }
  32. set {
  33. element = null;
  34. type = value;
  35. }
  36. }
  37. #endif
  38. public string Uri {
  39. get { return URI; }
  40. set {
  41. element = null;
  42. URI = value;
  43. }
  44. }
  45. public override XmlElement GetXml ()
  46. {
  47. if (element != null)
  48. return element;
  49. XmlDocument document = new XmlDocument ();
  50. XmlElement xel = document.CreateElement (XmlSignature.ElementNames.RetrievalMethod, XmlSignature.NamespaceURI);
  51. if (URI != null)
  52. xel.SetAttribute (XmlSignature.AttributeNames.URI, URI);
  53. #if NET_2_0
  54. if (Type != null)
  55. xel.SetAttribute (XmlSignature.AttributeNames.Type, Type);
  56. #endif
  57. return xel;
  58. }
  59. public override void LoadXml (XmlElement value)
  60. {
  61. if (value == null)
  62. throw new ArgumentNullException ();
  63. if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI)) {
  64. URI = ""; // not null - so we return URI="" as attribute !!!
  65. } else {
  66. URI = value.Attributes [XmlSignature.AttributeNames.URI].Value;
  67. #if NET_2_0
  68. if (value.HasAttribute (XmlSignature.AttributeNames.Type))
  69. Type = value.Attributes [XmlSignature.AttributeNames.Type].Value;
  70. #endif
  71. element = value;
  72. }
  73. }
  74. }
  75. }