KeyInfoRetrievalMethod.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // KeyInfoRetrievalMethod.cs - KeyInfoRetrievalMethod implementation for XML Signature
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using System.Text;
  10. using System.Xml;
  11. namespace System.Security.Cryptography.Xml {
  12. public class KeyInfoRetrievalMethod : KeyInfoClause {
  13. static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
  14. private string URI;
  15. public KeyInfoRetrievalMethod () {}
  16. public KeyInfoRetrievalMethod (string strUri)
  17. {
  18. URI = strUri;
  19. }
  20. public string Uri {
  21. get { return URI; }
  22. set { URI = value; }
  23. }
  24. public override XmlElement GetXml ()
  25. {
  26. StringBuilder sb = new StringBuilder ();
  27. sb.Append ("<RetrievalElement ");
  28. if (URI != null) {
  29. sb.Append ("URI=\"");
  30. sb.Append (URI);
  31. sb.Append ("\" ");
  32. }
  33. sb.Append ("xmlns=\"");
  34. sb.Append (xmldsig);
  35. sb.Append ("\" />");
  36. XmlDocument doc = new XmlDocument ();
  37. doc.LoadXml(sb.ToString ());
  38. return doc.DocumentElement;
  39. }
  40. public override void LoadXml (XmlElement value)
  41. {
  42. if (value == null)
  43. throw new ArgumentNullException ();
  44. if ((value.LocalName == "RetrievalElement") && (value.NamespaceURI == xmldsig)) {
  45. URI = value.Attributes["URI"].Value;
  46. }
  47. else
  48. URI = ""; // not null - so we return URI="" as attribute !!!
  49. }
  50. }
  51. }