/// <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) { EnvironmentPermission environmentPermission = this.Cast(target); if (environmentPermission == null) { return(false); } if (this.IsUnrestricted()) { return(environmentPermission.IsUnrestricted()); } if (environmentPermission.IsUnrestricted()) { return(true); } foreach (object obj in this.readList) { string item = (string)obj; if (!environmentPermission.readList.Contains(item)) { return(false); } } foreach (object obj2 in this.writeList) { string item2 = (string)obj2; if (!environmentPermission.writeList.Contains(item2)) { return(false); } } return(true); }
public void PermissionStateUnrestricted () { EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted); AssertNotNull ("EnvironmentPermission(PermissionState.Unrestricted)", ep); Assert ("IsUnrestricted", ep.IsUnrestricted ()); EnvironmentPermission copy = (EnvironmentPermission) ep.Copy (); AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = ep.ToXml (); AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string)); }
public void PermissionStateUnrestricted () { EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted); Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.Unrestricted)"); Assert.IsTrue (ep.IsUnrestricted (), "IsUnrestricted"); EnvironmentPermission copy = (EnvironmentPermission) ep.Copy (); Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = ep.ToXml (); Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted"); }
public void PermissionStateNone () { EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None); AssertNotNull ("EnvironmentPermission(PermissionState.None)", ep); Assert ("IsUnrestricted", !ep.IsUnrestricted ()); EnvironmentPermission copy = (EnvironmentPermission) ep.Copy (); AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = ep.ToXml (); Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className)); AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string)); }
public void PermissionStateNone () { EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None); Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.None)"); Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted"); EnvironmentPermission copy = (EnvironmentPermission) ep.Copy (); Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = ep.ToXml (); Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class"); Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version"); }
public override IPermission Intersect(IPermission target) { if (target == null) { return((IPermission)null); } if (!this.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.IsUnrestricted()) { return(target.Copy()); } EnvironmentPermission environmentPermission = (EnvironmentPermission)target; if (environmentPermission.IsUnrestricted()) { return(this.Copy()); } StringExpressionSet stringExpressionSet1 = this.m_read == null ? (StringExpressionSet)null : this.m_read.Intersect(environmentPermission.m_read); StringExpressionSet stringExpressionSet2 = this.m_write == null ? (StringExpressionSet)null : this.m_write.Intersect(environmentPermission.m_write); if ((stringExpressionSet1 == null || stringExpressionSet1.IsEmpty()) && (stringExpressionSet2 == null || stringExpressionSet2.IsEmpty())) { return((IPermission)null); } return((IPermission) new EnvironmentPermission(PermissionState.None) { m_unrestricted = false, m_read = stringExpressionSet1, m_write = stringExpressionSet2 }); }
/// <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) { EnvironmentPermission environmentPermission = this.Cast(other); if (environmentPermission == null) { return(this.Copy()); } if (this.IsUnrestricted() || environmentPermission.IsUnrestricted()) { return(new EnvironmentPermission(PermissionState.Unrestricted)); } if (this.IsEmpty() && environmentPermission.IsEmpty()) { return(null); } EnvironmentPermission environmentPermission2 = (EnvironmentPermission)this.Copy(); string pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Read); if (pathList != null) { environmentPermission2.AddPathList(EnvironmentPermissionAccess.Read, pathList); } pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Write); if (pathList != null) { environmentPermission2.AddPathList(EnvironmentPermissionAccess.Write, pathList); } return(environmentPermission2); }
public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } if (!base.VerifyType(other)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } EnvironmentPermission permission = (EnvironmentPermission)other; if (this.IsUnrestricted() || permission.IsUnrestricted()) { return(new EnvironmentPermission(PermissionState.Unrestricted)); } StringExpressionSet set = (this.m_read == null) ? permission.m_read : this.m_read.Union(permission.m_read); StringExpressionSet set2 = (this.m_write == null) ? permission.m_write : this.m_write.Union(permission.m_write); if (((set == null) || set.IsEmpty()) && ((set2 == null) || set2.IsEmpty())) { return(null); } return(new EnvironmentPermission(PermissionState.None) { m_unrestricted = false, m_read = set, m_write = set2 }); }
public override bool IsSubsetOf(IPermission target) { bool flag; if (target == null) { return(this.IsEmpty()); } try { EnvironmentPermission permission = (EnvironmentPermission)target; if (permission.IsUnrestricted()) { return(true); } if (this.IsUnrestricted()) { return(false); } flag = ((this.m_read == null) || this.m_read.IsSubsetOf(permission.m_read)) && ((this.m_write == null) || this.m_write.IsSubsetOf(permission.m_write)); } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(flag); }
public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } if (!this.VerifyType(other)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } EnvironmentPermission environmentPermission = (EnvironmentPermission)other; if (this.IsUnrestricted() || environmentPermission.IsUnrestricted()) { return((IPermission) new EnvironmentPermission(PermissionState.Unrestricted)); } StringExpressionSet stringExpressionSet1 = this.m_read == null ? environmentPermission.m_read : this.m_read.Union(environmentPermission.m_read); StringExpressionSet stringExpressionSet2 = this.m_write == null ? environmentPermission.m_write : this.m_write.Union(environmentPermission.m_write); if ((stringExpressionSet1 == null || stringExpressionSet1.IsEmpty()) && (stringExpressionSet2 == null || stringExpressionSet2.IsEmpty())) { return((IPermission)null); } return((IPermission) new EnvironmentPermission(PermissionState.None) { m_unrestricted = false, m_read = stringExpressionSet1, m_write = stringExpressionSet2 }); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } bool result; try { EnvironmentPermission environmentPermission = (EnvironmentPermission)target; if (environmentPermission.IsUnrestricted()) { result = true; } else if (this.IsUnrestricted()) { result = false; } else { result = ((this.m_read == null || this.m_read.IsSubsetOf(environmentPermission.m_read)) && (this.m_write == null || this.m_write.IsSubsetOf(environmentPermission.m_write))); } } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(result); }
[System.Security.SecuritySafeCritical] // auto-generated public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } try { EnvironmentPermission operand = (EnvironmentPermission)target; if (operand.IsUnrestricted()) { return(true); } else if (this.IsUnrestricted()) { return(false); } else { return((this.m_read == null || this.m_read.IsSubsetOf(operand.m_read)) && (this.m_write == null || this.m_write.IsSubsetOf(operand.m_write))); } } catch (InvalidCastException) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } }
public override IPermission Union(IPermission other) { EnvironmentPermission ep = Cast(other); if (ep == null) { return(Copy()); } if (IsUnrestricted() || ep.IsUnrestricted()) { return(new EnvironmentPermission(PermissionState.Unrestricted)); } if (IsEmpty() && ep.IsEmpty()) { return(null); } EnvironmentPermission result = (EnvironmentPermission)Copy(); string path = ep.GetPathList(EnvironmentPermissionAccess.Read); if (path != null) { result.AddPathList(EnvironmentPermissionAccess.Read, path); } path = ep.GetPathList(EnvironmentPermissionAccess.Write); if (path != null) { result.AddPathList(EnvironmentPermissionAccess.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) { EnvironmentPermission environmentPermission = this.Cast(target); if (environmentPermission == null) { return(null); } if (this.IsUnrestricted()) { return(environmentPermission.Copy()); } if (environmentPermission.IsUnrestricted()) { return(this.Copy()); } int num = 0; EnvironmentPermission environmentPermission2 = new EnvironmentPermission(PermissionState.None); string pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Read); if (pathList != null) { string[] array = pathList.Split(new char[] { ';' }); foreach (string text in array) { if (this.readList.Contains(text)) { environmentPermission2.AddPathList(EnvironmentPermissionAccess.Read, text); num++; } } } string pathList2 = environmentPermission.GetPathList(EnvironmentPermissionAccess.Write); if (pathList2 != null) { string[] array3 = pathList2.Split(new char[] { ';' }); foreach (string text2 in array3) { if (this.writeList.Contains(text2)) { environmentPermission2.AddPathList(EnvironmentPermissionAccess.Write, text2); num++; } } } return((num <= 0) ? null : environmentPermission2); }
public override IPermission Intersect(IPermission target) { EnvironmentPermission ep = Cast(target); if (ep == null) { return(null); } if (IsUnrestricted()) { return(ep.Copy()); } if (ep.IsUnrestricted()) { return(Copy()); } int n = 0; EnvironmentPermission result = new EnvironmentPermission(PermissionState.None); string readTarget = ep.GetPathList(EnvironmentPermissionAccess.Read); if (readTarget != null) { string[] targets = readTarget.Split(';'); foreach (string t in targets) { if (readList.Contains(t)) { result.AddPathList(EnvironmentPermissionAccess.Read, t); n++; } } } string writeTarget = ep.GetPathList(EnvironmentPermissionAccess.Write); if (writeTarget != null) { string[] targets = writeTarget.Split(';'); foreach (string t in targets) { if (writeList.Contains(t)) { result.AddPathList(EnvironmentPermissionAccess.Write, t); n++; } } } return((n > 0) ? result : null); }
public override bool IsSubsetOf(IPermission target) { EnvironmentPermission ep = Cast(target); if (ep == null) { return(false); } if (IsUnrestricted()) { return(ep.IsUnrestricted()); } else if (ep.IsUnrestricted()) { return(true); } foreach (string s in readList) { if (!ep.readList.Contains(s)) { return(false); } } foreach (string s in writeList) { if (!ep.writeList.Contains(s)) { return(false); } } return(true); }
[System.Security.SecuritySafeCritical] // auto-generated public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } else if (!VerifyType(target)) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } else if (this.IsUnrestricted()) { return(target.Copy()); } EnvironmentPermission operand = (EnvironmentPermission)target; if (operand.IsUnrestricted()) { return(this.Copy()); } StringExpressionSet intersectRead = this.m_read == null ? null : this.m_read.Intersect(operand.m_read); StringExpressionSet intersectWrite = this.m_write == null ? null : this.m_write.Intersect(operand.m_write); if ((intersectRead == null || intersectRead.IsEmpty()) && (intersectWrite == null || intersectWrite.IsEmpty())) { return(null); } EnvironmentPermission intersectPermission = new EnvironmentPermission(PermissionState.None); intersectPermission.m_unrestricted = false; intersectPermission.m_read = intersectRead; intersectPermission.m_write = intersectWrite; return(intersectPermission); }
[System.Security.SecuritySafeCritical] // auto-generated public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } else if (!VerifyType(other)) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } EnvironmentPermission operand = (EnvironmentPermission)other; if (this.IsUnrestricted() || operand.IsUnrestricted()) { return(new EnvironmentPermission(PermissionState.Unrestricted)); } StringExpressionSet unionRead = this.m_read == null ? operand.m_read : this.m_read.Union(operand.m_read); StringExpressionSet unionWrite = this.m_write == null ? operand.m_write : this.m_write.Union(operand.m_write); if ((unionRead == null || unionRead.IsEmpty()) && (unionWrite == null || unionWrite.IsEmpty())) { return(null); } EnvironmentPermission unionPermission = new EnvironmentPermission(PermissionState.None); unionPermission.m_unrestricted = false; unionPermission.m_read = unionRead; unionPermission.m_write = unionWrite; return(unionPermission); }
public void WriteAccess () { EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.Write, envVariables); Assert ("IsUnrestricted", !ep.IsUnrestricted ()); }
public void ReadAccess () { EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables); Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted"); }
private static string GetEnvironmentPermission (EnvironmentPermission ep) { if (ep.IsUnrestricted ()) return " EnvironmentPermission - Unrestricted\\l"; StringBuilder sb = new StringBuilder (" EnvironmentPermission\\l"); string s = ep.GetPathList (EnvironmentPermissionAccess.Read); if ((s != null) && (s.Length > 0)) sb.AppendFormat (" Read: {0}\\l", s); s = ep.GetPathList (EnvironmentPermissionAccess.Write); if ((s != null) && (s.Length > 0)) sb.AppendFormat (" Write: {0}\\l", s); return sb.ToString (); }