Zone.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // System.Security.Policy.Zone
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.Security;
  11. using System.Security.Permissions;
  12. namespace System.Security.Policy
  13. {
  14. public sealed class Zone : IIdentityPermissionFactory, IBuiltInEvidence
  15. {
  16. SecurityZone zone;
  17. public Zone (SecurityZone zone)
  18. {
  19. if (!Enum.IsDefined (typeof (SecurityZone), zone))
  20. throw new ArgumentException ("invalid zone");
  21. this.zone = zone;
  22. }
  23. public object Copy ()
  24. {
  25. return new Zone (zone);
  26. }
  27. public IPermission CreateIdentityPermission (Evidence evidence)
  28. {
  29. return new ZoneIdentityPermission (zone);
  30. }
  31. [MonoTODO("This depends on zone configuration in IE")]
  32. public static Zone CreateFromUrl (string url)
  33. {
  34. throw new NotImplementedException ();
  35. }
  36. public override bool Equals (object o)
  37. {
  38. if (!(o is Zone))
  39. return false;
  40. return (((Zone) o).zone == zone);
  41. }
  42. public override int GetHashCode ()
  43. {
  44. return (int) zone;
  45. }
  46. public override string ToString ()
  47. {
  48. SecurityElement se = new SecurityElement (GetType ().FullName);
  49. se.AddAttribute ("version", "1");
  50. se.AddChild (new SecurityElement ("Zone", zone.ToString ()));
  51. return se.ToString ();
  52. }
  53. int IBuiltInEvidence.GetRequiredSize (bool verbose)
  54. {
  55. return 3;
  56. }
  57. int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position) {
  58. int new_zone = (int) buffer [position++];
  59. new_zone += buffer [position++];
  60. return position;
  61. }
  62. int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose)
  63. {
  64. buffer [position++] = '\x0003';
  65. buffer [position++] = (char) (((int) zone) >> 16);
  66. buffer [position++] = (char) (((int) zone) & 0x0FFFF);
  67. return position;
  68. }
  69. public SecurityZone SecurityZone
  70. {
  71. get { return zone; }
  72. }
  73. }
  74. }