StrongName.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // StrongName.cs: Strong Name
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using System;
  10. using System.Security.Permissions;
  11. using System.Text;
  12. namespace System.Security.Policy {
  13. [Serializable]
  14. public sealed class StrongName : IIdentityPermissionFactory {
  15. private StrongNamePublicKeyBlob publickey;
  16. private string name;
  17. private Version version;
  18. public StrongName (StrongNamePublicKeyBlob blob, string name, Version version)
  19. {
  20. if (blob == null)
  21. throw new ArgumentNullException ("blob");
  22. if (name == null)
  23. throw new ArgumentNullException ("name");
  24. if (version == null)
  25. throw new ArgumentNullException ("version");
  26. publickey = blob;
  27. this.name = name;
  28. this.version = version;
  29. }
  30. public string Name {
  31. get { return name; }
  32. }
  33. public StrongNamePublicKeyBlob PublicKey {
  34. get { return publickey; }
  35. }
  36. public Version Version {
  37. get { return version; }
  38. }
  39. public object Copy ()
  40. {
  41. return (object) new StrongName (publickey, name, version);
  42. }
  43. [MonoTODO("What should we do with the evidence ? nothing?")]
  44. public IPermission CreateIdentityPermission (Evidence evidence)
  45. {
  46. return new StrongNameIdentityPermission (publickey, name, version);
  47. }
  48. public override bool Equals (object o)
  49. {
  50. if (!(o is StrongName))
  51. return false;
  52. StrongName sn = (o as StrongName);
  53. if (name != sn.Name)
  54. return false;
  55. if (!Version.Equals (sn.Version))
  56. return false;
  57. return PublicKey.Equals (sn.PublicKey);
  58. }
  59. public override int GetHashCode ()
  60. {
  61. return publickey.GetHashCode ();
  62. }
  63. public override string ToString ()
  64. {
  65. StringBuilder sb = new StringBuilder ();
  66. sb.Append ("<StrongName version=\"1\"\r\n Key=\"");
  67. sb.Append (publickey.ToString ());
  68. sb.Append ("\"\r\n Name=\"");
  69. sb.Append (name);
  70. sb.Append ("\"\r\n Version=\"");
  71. sb.Append (version.ToString ());
  72. sb.Append ("\"/>\r\n");
  73. return sb.ToString ();
  74. }
  75. }
  76. }