/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <param name="other">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Union(IPermission other)
        {
            RegistryPermission registryPermission = this.Cast(other);

            if (registryPermission == null)
            {
                return(this.Copy());
            }
            if (this.IsUnrestricted() || registryPermission.IsUnrestricted())
            {
                return(new RegistryPermission(PermissionState.Unrestricted));
            }
            if (this.IsEmpty() && registryPermission.IsEmpty())
            {
                return(null);
            }
            RegistryPermission registryPermission2 = (RegistryPermission)this.Copy();
            string             pathList            = registryPermission.GetPathList(RegistryPermissionAccess.Create);

            if (pathList != null)
            {
                registryPermission2.AddPathList(RegistryPermissionAccess.Create, pathList);
            }
            pathList = registryPermission.GetPathList(RegistryPermissionAccess.Read);
            if (pathList != null)
            {
                registryPermission2.AddPathList(RegistryPermissionAccess.Read, pathList);
            }
            pathList = registryPermission.GetPathList(RegistryPermissionAccess.Write);
            if (pathList != null)
            {
                registryPermission2.AddPathList(RegistryPermissionAccess.Write, pathList);
            }
            return(registryPermission2);
        }
示例#2
0
        public override IPermission Intersect(IPermission target)
        {
            RegistryPermission rp = Cast(target);

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

            if (IsUnrestricted())
            {
                return(rp.Copy());
            }
            if (rp.IsUnrestricted())
            {
                return(Copy());
            }

            RegistryPermission result = new RegistryPermission(PermissionState.None);

            IntersectKeys(createList, rp.createList, result.createList);
            IntersectKeys(readList, rp.readList, result.readList);
            IntersectKeys(writeList, rp.writeList, result.writeList);

            return(result.IsEmpty() ? null : result);
        }
        /// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
        /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
        /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override bool IsSubsetOf(IPermission target)
        {
            RegistryPermission registryPermission = this.Cast(target);

            if (registryPermission == null)
            {
                return(false);
            }
            if (registryPermission.IsEmpty())
            {
                return(this.IsEmpty());
            }
            if (this.IsUnrestricted())
            {
                return(registryPermission.IsUnrestricted());
            }
            return(registryPermission.IsUnrestricted() || (this.KeyIsSubsetOf(this.createList, registryPermission.createList) && this.KeyIsSubsetOf(this.readList, registryPermission.readList) && this.KeyIsSubsetOf(this.writeList, registryPermission.writeList)));
        }
示例#4
0
        public override IPermission Union(IPermission other)
        {
            RegistryPermission rp = Cast(other);

            if (rp == null)
            {
                return(Copy());
            }

            if (IsUnrestricted() || rp.IsUnrestricted())
            {
                return(new RegistryPermission(PermissionState.Unrestricted));
            }

            if (IsEmpty() && rp.IsEmpty())
            {
                return(null);
            }

            RegistryPermission result = (RegistryPermission)Copy();
            string             path   = rp.GetPathList(RegistryPermissionAccess.Create);

            if (path != null)
            {
                result.AddPathList(RegistryPermissionAccess.Create, path);
            }
            path = rp.GetPathList(RegistryPermissionAccess.Read);
            if (path != null)
            {
                result.AddPathList(RegistryPermissionAccess.Read, path);
            }
            path = rp.GetPathList(RegistryPermissionAccess.Write);
            if (path != null)
            {
                result.AddPathList(RegistryPermissionAccess.Write, path);
            }
            return(result);
        }
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Intersect(IPermission target)
        {
            RegistryPermission registryPermission = this.Cast(target);

            if (registryPermission == null)
            {
                return(null);
            }
            if (this.IsUnrestricted())
            {
                return(registryPermission.Copy());
            }
            if (registryPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            RegistryPermission registryPermission2 = new RegistryPermission(PermissionState.None);

            this.IntersectKeys(this.createList, registryPermission.createList, registryPermission2.createList);
            this.IntersectKeys(this.readList, registryPermission.readList, registryPermission2.readList);
            this.IntersectKeys(this.writeList, registryPermission.writeList, registryPermission2.writeList);
            return((!registryPermission2.IsEmpty()) ? registryPermission2 : null);
        }
示例#6
0
        public override bool IsSubsetOf(IPermission target)
        {
            RegistryPermission rp = Cast(target);

            if (rp == null)
            {
                return(false);
            }
            if (rp.IsEmpty())
            {
                return(IsEmpty());
            }

            if (IsUnrestricted())
            {
                return(rp.IsUnrestricted());
            }
            else if (rp.IsUnrestricted())
            {
                return(true);
            }

            if (!KeyIsSubsetOf(createList, rp.createList))
            {
                return(false);
            }
            if (!KeyIsSubsetOf(readList, rp.readList))
            {
                return(false);
            }
            if (!KeyIsSubsetOf(writeList, rp.writeList))
            {
                return(false);
            }

            return(true);
        }
示例#7
0
		public override IPermission Intersect (IPermission target) 
		{
			RegistryPermission rp = Cast (target);
			if (rp == null)
				return null;

			if (IsUnrestricted ())
				return rp.Copy ();
			if (rp.IsUnrestricted ())
				return Copy ();

			RegistryPermission result = new RegistryPermission (PermissionState.None);

			IntersectKeys (createList, rp.createList, result.createList);
			IntersectKeys (readList, rp.readList, result.readList);
			IntersectKeys (writeList, rp.writeList, result.writeList);

			return (result.IsEmpty () ? null : result);
		}