public override IPermission Intersect(IPermission target)
        {
            StorePermission dp = Cast(target);

            if (dp == null)
            {
                return(null);
            }

            if (this.IsUnrestricted() && dp.IsUnrestricted())
            {
                return(new StorePermission(PermissionState.Unrestricted));
            }
            if (this.IsUnrestricted())
            {
                return(dp.Copy());
            }
            if (dp.IsUnrestricted())
            {
                return(this.Copy());
            }

            StorePermissionFlags spf = _flags & dp._flags;

            if (spf == StorePermissionFlags.NoFlags)
            {
                return(null);
            }

            return(new StorePermission(spf));
        }
Exemplo n.º 2
0
		public void PermissionState_None_Copy ()
		{
			// both will return null under 2.0 final
			// StorePermission sp1 = new StorePermission (PermissionState.None).Copy();
			// StorePermission sp2 = new StorePermission (StorePermissionFlags.NoFlags).Copy ();
			StorePermission sp = new StorePermission (PermissionState.None);

			StorePermission copy = (StorePermission) sp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
			Assert.AreEqual (sp.Flags, copy.Flags, "Copy Flags");
			Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
		}
Exemplo n.º 3
0
		public void ConstructorLevel_Deny_Unrestricted ()
		{
			StorePermission p = new StorePermission (StorePermissionFlags.AllFlags);
			Assert.AreEqual (StorePermissionFlags.AllFlags, p.Flags, "Flags");
			Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
			Assert.IsNotNull (p.Copy (), "Copy");
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml");
			p.FromXml (se);
			Assert.IsNotNull (p.Intersect (p), "Intersect");
			Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
			Assert.IsNotNull (p.Union (p), "Union");
		}
Exemplo n.º 4
0
		public void ConstructorState_Deny_Unrestricted ()
		{
			StorePermission p = new StorePermission (PermissionState.None);
			Assert.AreEqual (StorePermissionFlags.NoFlags, p.Flags, "Flags");
			Assert.IsFalse (p.IsUnrestricted (), "IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml");
			p.FromXml (se);
			Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
			// strange behaviour of Copy under MS fx 2.0 (returns null for NoFlags)
			p.Copy ();
			p.Intersect (p);
			p.Union (p);
		}
Exemplo n.º 5
0
		public void PermissionState_None ()
		{
			PermissionState ps = PermissionState.None;
			StorePermission sp = new StorePermission (ps);
			Assert.AreEqual (StorePermissionFlags.NoFlags, sp.Flags, "Flags");
			Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");

			SecurityElement se = sp.ToXml ();
			// only class and version are present
			Assert.AreEqual ("NoFlags", se.Attribute ("Flags"), "Xml-Flags");
			Assert.IsNull (se.Children, "Xml-Children");

			StorePermission copy = (StorePermission) sp.Copy ();
			Assert.IsNull (copy, "Copy");
		}
Exemplo n.º 6
0
		public void PermissionState_Unrestricted ()
		{
			PermissionState ps = PermissionState.Unrestricted;
			StorePermission sp = new StorePermission (ps);
			Assert.AreEqual (StorePermissionFlags.AllFlags, sp.Flags, "Flags");
			Assert.IsTrue (sp.IsUnrestricted (), "IsUnrestricted");

			SecurityElement se = sp.ToXml ();
			Assert.IsNotNull (se.Attribute ("Unrestricted"), "Xml-Unrestricted");
			Assert.IsNull (se.Attribute ("Level"), "Xml-Flags");
			Assert.IsNull (se.Children, "Xml-Children");

			StorePermission copy = (StorePermission) sp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
			Assert.AreEqual (sp.Flags, copy.Flags, "Copy Flags");
			Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
		}
        public override bool IsSubsetOf(IPermission target)
        {
            StorePermission dp = Cast(target);

            if (dp == null)
            {
                return(_flags == StorePermissionFlags.NoFlags);
            }

            if (dp.IsUnrestricted())
            {
                return(true);
            }
            if (this.IsUnrestricted())
            {
                return(false);
            }

            return((_flags & ~dp._flags) == 0);
        }
        public override IPermission Union(IPermission target)
        {
            StorePermission dp = Cast(target);

            if (dp == null)
            {
                return(this.Copy()); // will return null for NoFlags
            }
            if (this.IsUnrestricted() || dp.IsUnrestricted())
            {
                return(new StorePermission(PermissionState.Unrestricted));
            }

            StorePermissionFlags spf = _flags | dp._flags;

            if (spf == StorePermissionFlags.NoFlags)
            {
                return(null);
            }

            return(new StorePermission(spf));
        }