public override IPermission Intersect(IPermission target) { if (target != null) { if (!base.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } KeyContainerPermission permission = (KeyContainerPermission)target; if (this.IsEmpty() || permission.IsEmpty()) { return(null); } KeyContainerPermissionFlags flags = permission.m_flags & this.m_flags; KeyContainerPermission permission2 = new KeyContainerPermission(flags); KeyContainerPermissionAccessEntryEnumerator enumerator = this.AccessEntries.GetEnumerator(); while (enumerator.MoveNext()) { KeyContainerPermissionAccessEntry current = enumerator.Current; permission2.AddAccessEntryAndIntersect(current, permission); } KeyContainerPermissionAccessEntryEnumerator enumerator2 = permission.AccessEntries.GetEnumerator(); while (enumerator2.MoveNext()) { KeyContainerPermissionAccessEntry accessEntry = enumerator2.Current; permission2.AddAccessEntryAndIntersect(accessEntry, this); } if (!permission2.IsEmpty()) { return(permission2); } } return(null); }
public override SecurityElement ToXml() { SecurityElement element = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.KeyContainerPermission"); if (!this.IsUnrestricted()) { element.AddAttribute("Flags", this.m_flags.ToString()); if (this.AccessEntries.Count > 0) { SecurityElement child = new SecurityElement("AccessList"); KeyContainerPermissionAccessEntryEnumerator enumerator = this.AccessEntries.GetEnumerator(); while (enumerator.MoveNext()) { KeyContainerPermissionAccessEntry current = enumerator.Current; SecurityElement element3 = new SecurityElement("AccessEntry"); element3.AddAttribute("KeyStore", current.KeyStore); element3.AddAttribute("ProviderName", current.ProviderName); element3.AddAttribute("ProviderType", current.ProviderType.ToString(null, null)); element3.AddAttribute("KeyContainerName", current.KeyContainerName); element3.AddAttribute("KeySpec", current.KeySpec.ToString(null, null)); element3.AddAttribute("Flags", current.Flags.ToString()); child.AddChild(element3); } element.AddChild(child); } return(element); } element.AddAttribute("Unrestricted", "true"); return(element); }
private static KeyContainerPermissionFlags GetApplicableFlags(KeyContainerPermissionAccessEntry accessEntry, KeyContainerPermission target) { KeyContainerPermissionFlags noFlags = KeyContainerPermissionFlags.NoFlags; bool flag = true; int index = target.AccessEntries.IndexOf(accessEntry); if (index != -1) { return(target.AccessEntries[index].Flags); } KeyContainerPermissionAccessEntryEnumerator enumerator = target.AccessEntries.GetEnumerator(); while (enumerator.MoveNext()) { KeyContainerPermissionAccessEntry current = enumerator.Current; if (accessEntry.IsSubsetOf(current)) { if (!flag) { noFlags &= current.Flags; } else { noFlags = current.Flags; flag = false; } } } if (flag) { noFlags = target.Flags; } return(noFlags); }
public override IPermission Copy() { if (this.IsEmpty()) { return(null); } KeyContainerPermission permission = new KeyContainerPermission(this.m_flags); KeyContainerPermissionAccessEntryEnumerator enumerator = this.AccessEntries.GetEnumerator(); while (enumerator.MoveNext()) { KeyContainerPermissionAccessEntry current = enumerator.Current; permission.AccessEntries.Add(current); } return(permission); }
public bool IsUnrestricted() { if (this.m_flags != KeyContainerPermissionFlags.AllFlags) { return(false); } KeyContainerPermissionAccessEntryEnumerator enumerator = this.AccessEntries.GetEnumerator(); while (enumerator.MoveNext()) { if ((enumerator.Current.Flags & KeyContainerPermissionFlags.AllFlags) != KeyContainerPermissionFlags.AllFlags) { return(false); } } return(true); }
private bool IsEmpty() { if (this.Flags != KeyContainerPermissionFlags.NoFlags) { return(false); } KeyContainerPermissionAccessEntryEnumerator enumerator = this.AccessEntries.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current.Flags != KeyContainerPermissionFlags.NoFlags) { return(false); } } return(true); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } if (!base.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } KeyContainerPermission permission = (KeyContainerPermission)target; if ((this.m_flags & permission.m_flags) != this.m_flags) { return(false); } KeyContainerPermissionAccessEntryEnumerator enumerator = this.AccessEntries.GetEnumerator(); while (enumerator.MoveNext()) { KeyContainerPermissionAccessEntry current = enumerator.Current; KeyContainerPermissionFlags applicableFlags = GetApplicableFlags(current, permission); if ((current.Flags & applicableFlags) != current.Flags) { return(false); } } KeyContainerPermissionAccessEntryEnumerator enumerator2 = permission.AccessEntries.GetEnumerator(); while (enumerator2.MoveNext()) { KeyContainerPermissionAccessEntry accessEntry = enumerator2.Current; KeyContainerPermissionFlags flags2 = GetApplicableFlags(accessEntry, this); if ((flags2 & accessEntry.Flags) != flags2) { return(false); } } return(true); }