2002-08-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sat, 3 Aug 2002 02:31:02 +0000 (02:31 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sat, 3 Aug 2002 02:31:02 +0000 (02:31 -0000)
* ZoneIdentityPermission.cs: New file. Implemented.

svn path=/trunk/mcs/; revision=6377

mcs/class/corlib/System.Security.Permissions/ChangeLog
mcs/class/corlib/System.Security.Permissions/ZoneIdentityPermission.cs [new file with mode: 0644]

index 4e5a1d03768e745e2ebb0430df4ffa4ba340d099..d5e5fc8f88acfb82c6e19a208b89056aa876c255 100644 (file)
@@ -1,3 +1,7 @@
+2002-08-03  Gonzalo Paniagua Javier <gonzalo@ximian.com>\r
+\r
+       * ZoneIdentityPermission.cs: New file. Implemented.\r
+\r
 2002-07-22  Tim Coleman <tim@timcoleman.com>\r
        * ReflectionPermission.cs:\r
        * EnvironmentPermission.cs:\r
diff --git a/mcs/class/corlib/System.Security.Permissions/ZoneIdentityPermission.cs b/mcs/class/corlib/System.Security.Permissions/ZoneIdentityPermission.cs
new file mode 100644 (file)
index 0000000..d92409f
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// System.Security.Permissions.ZoneIdentityPermission
+//
+// Authors:
+//     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2002 Ximian, Inc (http://www.ximian.com)
+//
+using System;
+using System.Security;
+
+namespace System.Security.Permissions
+{
+       public sealed class ZoneIdentityPermission : CodeAccessPermission
+       {
+               SecurityZone zone;
+
+               public ZoneIdentityPermission (PermissionState state)
+               {
+                       if (state == PermissionState.Unrestricted)
+                               throw new ArgumentException ("unrestricted not allowed");
+
+                       if (state != PermissionState.None)
+                               throw new ArgumentException ("invalid state");
+
+                       zone = SecurityZone.NoZone;
+               }
+
+               public ZoneIdentityPermission (SecurityZone zone)
+               {
+                       this.zone = zone;
+               }
+
+               public override IPermission Copy ()
+               {
+                       return new ZoneIdentityPermission (zone);
+               }
+
+               public override bool IsSubsetOf (IPermission target)
+               {
+                       if (target == null)
+                               return zone == SecurityZone.NoZone;
+
+                       if (!(target is ZoneIdentityPermission))
+                               throw new ArgumentException ();
+
+                       return zone != ((ZoneIdentityPermission) target).zone;
+               }
+
+               public override IPermission Union (IPermission target)
+               {
+                       if (target == null)
+                               return (zone == SecurityZone.NoZone) ? null : Copy ();
+
+                       if (!(target is ZoneIdentityPermission))
+                               throw new ArgumentException ();
+
+                       ZoneIdentityPermission se = (ZoneIdentityPermission) target;
+                       if (zone == se.zone || se.zone == SecurityZone.NoZone)
+                               return Copy ();
+
+                       if (zone == SecurityZone.NoZone)
+                               return se.Copy ();
+
+                       return null;
+               }
+
+               public override IPermission Intersect (IPermission target)
+               {
+                       if (target == null || zone == SecurityZone.NoZone)
+                               return null;
+
+                       if (!(target is ZoneIdentityPermission))
+                               throw new ArgumentException ();
+
+                       if (zone == ((ZoneIdentityPermission) target).zone)
+                               return Copy ();
+
+                       return null;
+               }
+
+               public override void FromXml (SecurityElement esd)
+               {
+                       if (esd == null)
+                               throw new ArgumentException ("esd is null");
+
+                       if (esd.Attribute ("version") != "1")
+                               throw new ArgumentException ("version attributte is wrong");
+                               
+                       string zoneName = esd.Attribute ("Zone");
+                       zone = (SecurityZone) Enum.Parse (typeof (SecurityZone), zoneName);
+               }
+
+               public override SecurityElement ToXml ()
+               {
+                       SecurityElement se = new SecurityElement ("IPermission");
+                       se.AddAttribute ("version", "1");
+                       Type t = GetType ();
+                       se.AddAttribute("class", t.FullName + ", " + t.Module.Assembly.FullName);
+
+                       return se;
+               }
+
+               public SecurityZone SecurityZone
+               {
+                       get {
+                               return zone;
+                       }
+
+                       set {
+                               if (!Enum.IsDefined (typeof (SecurityZone), value))
+                                       throw new ArgumentException ("invalid zone");
+                               zone = value;
+                       }
+               }
+       }
+
+}
+