public override IPermission Union(IPermission target) { StrongNameIdentityPermission snip = Cast(target); if ((snip == null) || snip.IsEmpty()) { return(Copy()); } if (IsEmpty()) { return(snip.Copy()); } StrongNameIdentityPermission union = (StrongNameIdentityPermission)Copy(); foreach (SNIP e in snip._list) { if (!IsEmpty(e) && !Contains(e)) { union._list.Add(e); } } return(union); }
public override IPermission Intersect(IPermission target) { StrongNameIdentityPermission snip = (target as StrongNameIdentityPermission); if ((snip == null) || IsEmpty()) { return(null); } if (snip.IsEmpty()) { return(new StrongNameIdentityPermission(PermissionState.None)); } if (!Match(snip.Name)) { return(null); } string n = ((Name.Length < snip.Name.Length) ? Name : snip.Name); if (!Version.Equals(snip.Version)) { return(null); } if (!PublicKey.Equals(snip.PublicKey)) { return(null); } return(new StrongNameIdentityPermission(this.PublicKey, n, this.Version)); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } StrongNameIdentityPermission snip = (target as StrongNameIdentityPermission); if (snip == null) { throw new ArgumentException(Locale.GetText("Wrong permission type.")); } if (IsEmpty() || snip.IsEmpty()) { return(null); } if (!Match(snip.Name)) { return(null); } string n = ((Name.Length < snip.Name.Length) ? Name : snip.Name); if (!Version.Equals(snip.Version)) { return(null); } if (!PublicKey.Equals(snip.PublicKey)) { return(null); } return(new StrongNameIdentityPermission(this.PublicKey, n, this.Version)); }
/// <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) { StrongNameIdentityPermission strongNameIdentityPermission = this.Cast(target); if (strongNameIdentityPermission == null) { return(this.IsEmpty()); } if (this.IsEmpty()) { return(true); } if (this.IsUnrestricted()) { return(strongNameIdentityPermission.IsUnrestricted()); } if (strongNameIdentityPermission.IsUnrestricted()) { return(true); } foreach (object obj in this._list) { StrongNameIdentityPermission.SNIP snip = (StrongNameIdentityPermission.SNIP)obj; foreach (object obj2 in strongNameIdentityPermission._list) { StrongNameIdentityPermission.SNIP target2 = (StrongNameIdentityPermission.SNIP)obj2; if (!snip.IsSubsetOf(target2)) { return(false); } } } return(true); }
/// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.Union"]/*' /> public override IPermission Union(IPermission target) { if (target == null) { return(this.m_publicKeyBlob != null?this.Copy() : null); } else if (!VerifyType(target)) { throw new ArgumentException( String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName) ); } StrongNameIdentityPermission operand = (StrongNameIdentityPermission)target; // Union is only defined on permissions where one is a subset of the other. // For Union, simply return a copy of whichever contains the other. if (operand.IsSubsetOf(this)) { return(this.Copy()); } else if (this.IsSubsetOf(operand)) { return(operand.Copy()); } else { return(null); } }
/// <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, or 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) { if (target == null) { return(null); } StrongNameIdentityPermission strongNameIdentityPermission = target as StrongNameIdentityPermission; if (strongNameIdentityPermission == null) { throw new ArgumentException(Locale.GetText("Wrong permission type.")); } if (this.IsEmpty() || strongNameIdentityPermission.IsEmpty()) { return(null); } if (!this.Match(strongNameIdentityPermission.Name)) { return(null); } string name = (this.Name.Length >= strongNameIdentityPermission.Name.Length) ? strongNameIdentityPermission.Name : this.Name; if (!this.Version.Equals(strongNameIdentityPermission.Version)) { return(null); } if (!this.PublicKey.Equals(strongNameIdentityPermission.PublicKey)) { return(null); } return(new StrongNameIdentityPermission(this.PublicKey, name, this.Version)); }
public override bool IsSubsetOf(IPermission target) { StrongNameIdentityPermission snip = Cast(target); if (snip == null) { return(IsEmpty()); } if (IsEmpty()) { return(true); } if (IsUnrestricted()) { return(snip.IsUnrestricted()); } else if (snip.IsUnrestricted()) { return(true); } foreach (SNIP e in _list) { foreach (SNIP t in snip._list) { if (!e.IsSubsetOf(t)) { return(false); } } } return(true); }
public void PermissionStateNone () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); Assert.AreEqual (String.Empty, snip.Name, "Name"); Assert.IsNull (snip.PublicKey, "PublicKey"); Assert.AreEqual ("0.0", snip.Version.ToString (), "Version"); SecurityElement se = snip.ToXml (); #if NET_2_0 Assert.IsNull (se.Attribute ("Name"), "Xml-Name"); Assert.IsNull (se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion"); #else Assert.AreEqual (String.Empty, se.Attribute ("Name"), "Xml-Name"); Assert.AreEqual ("0.0", se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion"); #endif Assert.IsNull (se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob"); // because Name == String.Empty, which is illegal using the other constructor StrongNameIdentityPermission copy = (StrongNameIdentityPermission) snip.Copy (); Assert.AreEqual (String.Empty, copy.Name, "Copy-Name"); #if NET_2_0 // Strangely once copied the Name becomes equals to String.Empty in 2.0 [FDBK19351] Assert.IsNull (se.Attribute ("AssemblyVersion"), "Copy-Version"); #else Assert.AreEqual ("0.0", copy.Version.ToString (), "Copy-Version"); #endif Assert.IsNull (copy.PublicKey, "Copy-PublicKey"); }
private StrongNameIdentityPermission GetUnion () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); StrongNamePublicKeyBlob blob2 = new StrongNamePublicKeyBlob (new byte[16]); StrongNameIdentityPermission diffPk = new StrongNameIdentityPermission (blob2, "mono", new Version (1, 2, 3, 4)); return (StrongNameIdentityPermission)snip.Union (diffPk); }
internal StrongNameIdentityPermission(StrongNameIdentityPermission snip) { _state = snip._state; _list = new ArrayList(snip._list.Count); foreach (SNIP e in snip._list) { _list.Add(new SNIP(e.PublicKey, e.Name, e.AssemblyVersion)); } }
public override bool IsSubsetOf(IPermission target) { if (target == null) { if (m_unrestricted) { return(false); } if (m_strongNames == null) { return(true); } if (m_strongNames.Length == 0) { return(true); } return(false); } StrongNameIdentityPermission that = target as StrongNameIdentityPermission; if (that == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (that.m_unrestricted) { return(true); } if (m_unrestricted) { return(false); } if (this.m_strongNames != null) { foreach (StrongName2 snThis in m_strongNames) { bool bOK = false; if (that.m_strongNames != null) { foreach (StrongName2 snThat in that.m_strongNames) { if (snThis.IsSubsetOf(snThat)) { bOK = true; break; } } } if (!bOK) { return(false); } } } return(true); }
/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary> /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param> /// <returns>A new permission that represents the intersection of the current permission and the specified permission, or <see langword="null" /> if the intersection is empty.</returns> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception> // Token: 0x06002642 RID: 9794 RVA: 0x0008A500 File Offset: 0x00088700 public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } StrongNameIdentityPermission strongNameIdentityPermission = target as StrongNameIdentityPermission; if (strongNameIdentityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.m_unrestricted && strongNameIdentityPermission.m_unrestricted) { return(new StrongNameIdentityPermission(PermissionState.None) { m_unrestricted = true }); } if (this.m_unrestricted) { return(strongNameIdentityPermission.Copy()); } if (strongNameIdentityPermission.m_unrestricted) { return(this.Copy()); } if (this.m_strongNames == null || strongNameIdentityPermission.m_strongNames == null || this.m_strongNames.Length == 0 || strongNameIdentityPermission.m_strongNames.Length == 0) { return(null); } List <StrongName2> list = new List <StrongName2>(); foreach (StrongName2 strongName in this.m_strongNames) { foreach (StrongName2 target2 in strongNameIdentityPermission.m_strongNames) { StrongName2 strongName2 = strongName.Intersect(target2); if (strongName2 != null) { list.Add(strongName2); } } } if (list.Count == 0) { return(null); } return(new StrongNameIdentityPermission(PermissionState.None) { m_strongNames = list.ToArray() }); }
internal StrongNameIdentityPermission(StrongNameIdentityPermission snip) { this._state = snip._state; this._list = new ArrayList(snip._list.Count); foreach (object obj in snip._list) { StrongNameIdentityPermission.SNIP snip2 = (StrongNameIdentityPermission.SNIP)obj; this._list.Add(new StrongNameIdentityPermission.SNIP(snip2.PublicKey, snip2.Name, snip2.AssemblyVersion)); } }
/// <summary>创建并返回一个权限,该权限是当前权限和指定权限的交集。</summary> /// <returns>一个新的权限,表示当前权限与指定权限的交集,或为 null(如果交集为空)。</returns> /// <param name="target">要与当前权限相交的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override IPermission Intersect(IPermission target) { if (target == null) { return((IPermission)null); } StrongNameIdentityPermission identityPermission = target as StrongNameIdentityPermission; if (identityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.m_unrestricted && identityPermission.m_unrestricted) { return (IPermission) new StrongNameIdentityPermission(PermissionState.None) { m_unrestricted = true } } ; if (this.m_unrestricted) { return(identityPermission.Copy()); } if (identityPermission.m_unrestricted) { return(this.Copy()); } if (this.m_strongNames == null || identityPermission.m_strongNames == null || (this.m_strongNames.Length == 0 || identityPermission.m_strongNames.Length == 0)) { return((IPermission)null); } List <StrongName2> strongName2List = new List <StrongName2>(); foreach (StrongName2 mStrongName1 in this.m_strongNames) { foreach (StrongName2 mStrongName2 in identityPermission.m_strongNames) { StrongName2 strongName2 = mStrongName1.Intersect(mStrongName2); if (strongName2 != null) { strongName2List.Add(strongName2); } } } if (strongName2List.Count == 0) { return((IPermission)null); } return((IPermission) new StrongNameIdentityPermission(PermissionState.None) { m_strongNames = strongName2List.ToArray() }); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { if (!this.m_unrestricted) { if (this.m_strongNames == null) { return(true); } if (this.m_strongNames.Length == 0) { return(true); } } return(false); } StrongNameIdentityPermission permission = target as StrongNameIdentityPermission; if (permission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (!permission.m_unrestricted) { if (this.m_unrestricted) { return(false); } if (this.m_strongNames != null) { foreach (StrongName2 name in this.m_strongNames) { bool flag = false; if (permission.m_strongNames != null) { foreach (StrongName2 name2 in permission.m_strongNames) { if (name.IsSubsetOf(name2)) { flag = true; break; } } } if (!flag) { return(false); } } } } return(true); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } StrongNameIdentityPermission that = target as StrongNameIdentityPermission; if (that == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (this.m_unrestricted && that.m_unrestricted) { StrongNameIdentityPermission res = new StrongNameIdentityPermission(PermissionState.None); res.m_unrestricted = true; return(res); } if (this.m_unrestricted) { return(that.Copy()); } if (that.m_unrestricted) { return(this.Copy()); } if (this.m_strongNames == null || that.m_strongNames == null || this.m_strongNames.Length == 0 || that.m_strongNames.Length == 0) { return(null); } List <StrongName2> alStrongNames = new List <StrongName2>(); foreach (StrongName2 snThis in this.m_strongNames) { foreach (StrongName2 snThat in that.m_strongNames) { StrongName2 snInt = (StrongName2)snThis.Intersect(snThat); if (snInt != null) { alStrongNames.Add(snInt); } } } if (alStrongNames.Count == 0) { return(null); } StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None); result.m_strongNames = alStrongNames.ToArray(); return(result); }
private StrongNameIdentityPermission Cast(IPermission target) { if (target == null) { return(null); } StrongNameIdentityPermission strongNameIdentityPermission = target as StrongNameIdentityPermission; if (strongNameIdentityPermission == null) { CodeAccessPermission.ThrowInvalidPermission(target, typeof(StrongNameIdentityPermission)); } return(strongNameIdentityPermission); }
public override IPermission Copy() { StrongNameIdentityPermission permission = new StrongNameIdentityPermission(PermissionState.None) { m_unrestricted = this.m_unrestricted }; if (this.m_strongNames != null) { permission.m_strongNames = new StrongName2[this.m_strongNames.Length]; for (int i = 0; i < this.m_strongNames.Length; i++) { permission.m_strongNames[i] = this.m_strongNames[i].Copy(); } } return permission; }
/// <summary>Creates and returns an identical copy of the current permission.</summary> /// <returns>A copy of the current permission.</returns> // Token: 0x06002640 RID: 9792 RVA: 0x0008A3C4 File Offset: 0x000885C4 public override IPermission Copy() { StrongNameIdentityPermission strongNameIdentityPermission = new StrongNameIdentityPermission(PermissionState.None); strongNameIdentityPermission.m_unrestricted = this.m_unrestricted; if (this.m_strongNames != null) { strongNameIdentityPermission.m_strongNames = new StrongName2[this.m_strongNames.Length]; for (int i = 0; i < this.m_strongNames.Length; i++) { strongNameIdentityPermission.m_strongNames[i] = this.m_strongNames[i].Copy(); } } return(strongNameIdentityPermission); }
/// <summary>创建并返回当前权限的相同副本。</summary> /// <returns>当前权限的副本。</returns> public override IPermission Copy() { StrongNameIdentityPermission identityPermission = new StrongNameIdentityPermission(PermissionState.None); identityPermission.m_unrestricted = this.m_unrestricted; if (this.m_strongNames != null) { identityPermission.m_strongNames = new StrongName2[this.m_strongNames.Length]; for (int index = 0; index < this.m_strongNames.Length; ++index) { identityPermission.m_strongNames[index] = this.m_strongNames[index].Copy(); } } return((IPermission)identityPermission); }
public override bool IsSubsetOf(IPermission target) { StrongNameIdentityPermission snip = Cast(target); if (snip == null) { return(IsEmpty()); } if (IsEmpty()) { return(true); } return(_single.IsSubsetOf(snip._single)); }
private StrongNameIdentityPermission Cast(IPermission target) { if (target == null) { return(null); } StrongNameIdentityPermission snip = (target as StrongNameIdentityPermission); if (snip == null) { ThrowInvalidPermission(target, typeof(StrongNameIdentityPermission)); } return(snip); }
//------------------------------------------------------ // // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS // //------------------------------------------------------ //------------------------------------------------------ // // CODEACCESSPERMISSION IMPLEMENTATION // //------------------------------------------------------ //------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override IPermission Copy() { StrongNameIdentityPermission perm = new StrongNameIdentityPermission(PermissionState.None); perm.m_unrestricted = this.m_unrestricted; if (this.m_strongNames != null) { perm.m_strongNames = new StrongName2[this.m_strongNames.Length]; int n; for (n = 0; n < this.m_strongNames.Length; n++) { perm.m_strongNames[n] = this.m_strongNames[n].Copy(); } } return(perm); }
public override IPermission Union(IPermission target) { StrongNameIdentityPermission snip = Cast(target); if ((snip == null) || snip.IsEmpty()) { return(Copy()); } if (IsEmpty()) { return(snip.Copy()); } if (!PublicKey.Equals(snip.PublicKey)) { return(null); } string n = Name; if ((n == null) || (n.Length == 0)) { n = snip.Name; } else if (Match(snip.Name)) { n = ((Name.Length > snip.Name.Length) ? Name : snip.Name); } else if ((snip.Name != null) && (snip.Name.Length > 0) && (n != snip.Name)) { return(null); } Version v = Version; if (v == null) { v = snip.Version; } else if ((snip.Version != null) && (v != snip.Version)) { return(null); } return(new StrongNameIdentityPermission(PublicKey, n, v)); }
public void PermissionStateUnrestricted () { // In 2.0 Unrestricted are permitted for identity permissions StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.Unrestricted); Assert.AreEqual (String.Empty, snip.Name, "Name"); Assert.IsNull (snip.PublicKey, "PublicKey"); Assert.AreEqual ("0.0", snip.Version.ToString (), "Version"); SecurityElement se = snip.ToXml (); Assert.IsNull (se.Attribute ("Name"), "Xml-Name"); Assert.IsNull (se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob"); Assert.IsNull (se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion"); StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy (); Assert.IsTrue (snip.Equals (copy), "snip Equals copy"); Assert.IsTrue (copy.Equals (snip), "copy Equals snip"); // and they aren't equals to None Assert.IsFalse (snip.Equals (new StrongNameIdentityPermission (PermissionState.None)), "Not Equals None"); }
/// <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="target">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="target" /> parameter is not null and is not of the same type as the current permission. -or-The two permissions are not equal and one is a subset of the other.</exception> public override IPermission Union(IPermission target) { StrongNameIdentityPermission strongNameIdentityPermission = this.Cast(target); if (strongNameIdentityPermission == null || strongNameIdentityPermission.IsEmpty()) { return(this.Copy()); } if (this.IsEmpty()) { return(strongNameIdentityPermission.Copy()); } StrongNameIdentityPermission strongNameIdentityPermission2 = (StrongNameIdentityPermission)this.Copy(); foreach (object obj in strongNameIdentityPermission._list) { StrongNameIdentityPermission.SNIP snip = (StrongNameIdentityPermission.SNIP)obj; if (!this.IsEmpty(snip) && !this.Contains(snip)) { strongNameIdentityPermission2._list.Add(snip); } } return(strongNameIdentityPermission2); }
internal StrongNameIdentityPermission(StrongNameIdentityPermission snip) : this(snip.PublicKey, snip.Name, snip.Version) { }
public void IsSubsetOf_DifferentPermissions () { StrongNameIdentityPermission a = new StrongNameIdentityPermission (PermissionState.None); SecurityPermission b = new SecurityPermission (PermissionState.None); a.IsSubsetOf (b); }
public void PublicKey_Null () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); snip.PublicKey = null; }
public void Union () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); StrongNameIdentityPermission union = (StrongNameIdentityPermission)snip.Union (null); Compare (snip, union, "snip U null"); StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None); union = (StrongNameIdentityPermission)snip.Union (empty); Compare (snip, union, "snip U empty"); union = (StrongNameIdentityPermission)snip.Union (snip); Compare (snip, union, "snip U snip"); // note: can't be tested with PermissionState.Unrestricted StrongNameIdentityPermission samePk = new StrongNameIdentityPermission (blob, null, null); union = (StrongNameIdentityPermission)snip.Union (samePk); #if !NET_2_0 // can't compare the properties with multiple entries Compare (snip, union, "snip U samePk"); #endif Assert.IsTrue (snip.IsSubsetOf (union), "snip.IsSubsetOf (union)"); union = (StrongNameIdentityPermission)samePk.Union (snip); #if !NET_2_0 // can't compare the properties with multiple entries Compare (snip, union, "samePk U snip"); #endif Assert.IsTrue (samePk.IsSubsetOf (union), "snip.IsSubsetOf (union)"); }
public void FromXml_WrongTag () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); SecurityElement se = snip.ToXml (); se.Tag = "IMono"; snip.FromXml (se); }
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary> /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param> /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. -or-The two permissions are not equal and one is a subset of the other.</exception> // Token: 0x06002643 RID: 9795 RVA: 0x0008A624 File Offset: 0x00088824 public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted) { return(null); } return(this.Copy()); } else { StrongNameIdentityPermission strongNameIdentityPermission = target as StrongNameIdentityPermission; if (strongNameIdentityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.m_unrestricted || strongNameIdentityPermission.m_unrestricted) { return(new StrongNameIdentityPermission(PermissionState.None) { m_unrestricted = true }); } if (this.m_strongNames == null || this.m_strongNames.Length == 0) { if (strongNameIdentityPermission.m_strongNames == null || strongNameIdentityPermission.m_strongNames.Length == 0) { return(null); } return(strongNameIdentityPermission.Copy()); } else { if (strongNameIdentityPermission.m_strongNames == null || strongNameIdentityPermission.m_strongNames.Length == 0) { return(this.Copy()); } List <StrongName2> list = new List <StrongName2>(); foreach (StrongName2 item in this.m_strongNames) { list.Add(item); } foreach (StrongName2 strongName in strongNameIdentityPermission.m_strongNames) { bool flag = false; foreach (StrongName2 target2 in list) { if (strongName.Equals(target2)) { flag = true; break; } } if (!flag) { list.Add(strongName); } } return(new StrongNameIdentityPermission(PermissionState.None) { m_strongNames = list.ToArray() }); } } }
public void Union_SamePublicKey_DifferentVersion () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); StrongNameIdentityPermission diffVersion = new StrongNameIdentityPermission (blob, null, new Version (1, 2)); StrongNameIdentityPermission result = (StrongNameIdentityPermission) snip.Union (diffVersion); #if NET_2_0 Assert.IsNotNull (result, "DifferentVersion"); // new XML format is used to contain more than one site SecurityElement se = result.ToXml (); Assert.AreEqual (2, se.Children.Count, "Childs"); Assert.AreEqual ("1.2.3.4", (se.Children [0] as SecurityElement).Attribute ("AssemblyVersion"), "AssemblyVersion#1"); Assert.AreEqual ("1.2", (se.Children [1] as SecurityElement).Attribute ("AssemblyVersion"), "AssemblyVersion#2"); // strangely it is still versioned as 'version="1"'. Assert.AreEqual ("1", se.Attribute ("version"), "Version"); #else Assert.IsNull (result, "DifferentVersion"); #endif }
public void FromXml_NoVersion () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); SecurityElement se = snip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", se.Attribute ("class")); snip.FromXml (w); }
public void FromXml_NameEmpty () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); SecurityElement se = snip.ToXml (); snip.FromXml (se); snip.PublicKey = new StrongNamePublicKeyBlob (ecma); snip.Version = new Version ("1.2.3.4"); se = snip.ToXml (); snip.FromXml (se); }
public void FromXml_NoClass () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); SecurityElement se = snip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("version", se.Attribute ("version")); snip.FromXml (w); // doesn't even care of the class attribute presence }
public void FromXml_WrongVersion () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); SecurityElement se = snip.ToXml (); se.Attributes.Remove ("version"); se.Attributes.Add ("version", "2"); snip.FromXml (se); }
public void FromXml_WrongClass () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); SecurityElement se = snip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", "Wrong" + se.Attribute ("class")); w.AddAttribute ("version", se.Attribute ("version")); snip.FromXml (w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
public void Intersect_DifferentPermissions () { StrongNameIdentityPermission a = new StrongNameIdentityPermission (PermissionState.None); SecurityPermission b = new SecurityPermission (PermissionState.None); Assert.IsNull (a.Intersect (b)); }
public void FromXml_WrongTagCase () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); SecurityElement se = snip.ToXml (); se.Tag = "IPERMISSION"; // instead of IPermission snip.FromXml (se); }
public void Name_Empty () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); snip.Name = String.Empty; #if !NET_2_0 Assert.AreEqual (String.Empty, snip.Name, "Name"); #endif }
/// <include file='doc\StrongNameIdentityPermission.uex' path='docs/doc[@for="StrongNameIdentityPermission.IsSubsetOf"]/*' /> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(m_publicKeyBlob == null); } try { StrongNameIdentityPermission operand = (StrongNameIdentityPermission)target; // This blob is a subset of the target is it's public key blob is null no matter what if (this.m_publicKeyBlob == null) { return(true); } // Subsets are always false is the public key blobs do not match if (this.m_publicKeyBlob.Equals(operand.m_publicKeyBlob)) { // We use null in strings to represent the "Anything" state. // Therefore, the logic to detect an individual subset is: // // 1. If the this string is null ("Anything" is a subset of any other). // 2. If the this string and operand string are the same (equality is sufficient for a subset). // // The logic is reversed here to discover things that are not subsets. if (this.m_name != null) { if (operand.m_name == null || !System.Security.Policy.StrongName.CompareNames(operand.m_name, this.m_name)) { return(false); } } if ((Object)this.m_version != null) { if ((Object)operand.m_version == null || operand.m_version.CompareTo(this.m_version) != 0) { return(false); } } return(true); } else { return(false); } } catch (InvalidCastException) { throw new ArgumentException( String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName) ); } }
public void Name () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); Assert.AreEqual ("mono", snip.Name, "Name-1"); snip.Name = null; Assert.IsNull (snip.Name, "Name-2"); snip.Name = "mono"; Assert.AreEqual ("mono", snip.Name, "Name-3"); }
public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted) { return(null); } return(this.Copy()); } StrongNameIdentityPermission that = target as StrongNameIdentityPermission; if (that == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (this.m_unrestricted || that.m_unrestricted) { StrongNameIdentityPermission res = new StrongNameIdentityPermission(PermissionState.None); res.m_unrestricted = true; return(res); } if (this.m_strongNames == null || this.m_strongNames.Length == 0) { if (that.m_strongNames == null || that.m_strongNames.Length == 0) { return(null); } return(that.Copy()); } if (that.m_strongNames == null || that.m_strongNames.Length == 0) { return(this.Copy()); } List <StrongName2> alStrongNames = new List <StrongName2>(); foreach (StrongName2 snThis in this.m_strongNames) { alStrongNames.Add(snThis); } foreach (StrongName2 snThat in that.m_strongNames) { bool bDupe = false; foreach (StrongName2 sn in alStrongNames) { if (snThat.Equals(sn)) { bDupe = true; break; } } if (!bDupe) { alStrongNames.Add(snThat); } } StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None); result.m_strongNames = alStrongNames.ToArray(); return(result); }
public void Union_DifferentPermissions () { StrongNameIdentityPermission a = new StrongNameIdentityPermission (PermissionState.None); SecurityPermission b = new SecurityPermission (PermissionState.None); a.Union (b); }
//------------------------------------------------------ // // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS // //------------------------------------------------------ //------------------------------------------------------ // // CODEACCESSPERMISSION IMPLEMENTATION // //------------------------------------------------------ //------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override IPermission Copy() { StrongNameIdentityPermission perm = new StrongNameIdentityPermission(PermissionState.None); perm.m_unrestricted = this.m_unrestricted; if(this.m_strongNames != null) { perm.m_strongNames = new StrongName2[this.m_strongNames.Length]; int n; for(n = 0; n < this.m_strongNames.Length; n++) perm.m_strongNames[n] = this.m_strongNames[n].Copy(); } return perm; }
public void IsSubsetOf () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); Assert.IsFalse (snip.IsSubsetOf (null), "snip.IsSubsetOf (null)"); StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None); Assert.IsTrue (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)"); }
public override IPermission Union(IPermission target) { if (target == null) { if((this.m_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted) return null; return this.Copy(); } StrongNameIdentityPermission that = target as StrongNameIdentityPermission; if(that == null) throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); if(this.m_unrestricted || that.m_unrestricted) { StrongNameIdentityPermission res = new StrongNameIdentityPermission(PermissionState.None); res.m_unrestricted = true; return res; } if (this.m_strongNames == null || this.m_strongNames.Length == 0) { if(that.m_strongNames == null || that.m_strongNames.Length == 0) return null; return that.Copy(); } if(that.m_strongNames == null || that.m_strongNames.Length == 0) return this.Copy(); ArrayList alStrongNames = new ArrayList(); foreach(StrongName2 snThis in this.m_strongNames) alStrongNames.Add(snThis); foreach(StrongName2 snThat in that.m_strongNames) { bool bDupe = false; foreach(StrongName2 sn in alStrongNames) { if(snThat.Equals(sn)) { bDupe = true; break; } } if(!bDupe) alStrongNames.Add(snThat); } StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None); result.m_strongNames = (StrongName2[])alStrongNames.ToArray(typeof(StrongName2)); return result; }
public void Intersect () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); StrongNameIdentityPermission intersect = (StrongNameIdentityPermission)snip.Intersect (null); Assert.IsNull (intersect, "snip N null"); StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None); intersect = (StrongNameIdentityPermission)snip.Intersect (empty); #if NET_2_0 Assert.IsNull (intersect, "snip N empty"); #else Compare (empty, intersect, "snip U empty"); #endif intersect = (StrongNameIdentityPermission)snip.Intersect (snip); Compare (snip, intersect, "snip U snip"); StrongNameIdentityPermission samePk = new StrongNameIdentityPermission (blob, "novell", new Version (1, 2)); intersect = (StrongNameIdentityPermission)snip.Intersect (samePk); Assert.IsNull (intersect, "(snip N samePk)"); // strange, I would have expected a SNIP with the same public key... }
public void FromXml_Null () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); snip.FromXml (null); }
/// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns> /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -这两个权限不相等,而且其中一个是另一个的子集。</exception> public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted) { return((IPermission)null); } return(this.Copy()); } StrongNameIdentityPermission identityPermission = target as StrongNameIdentityPermission; if (identityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.m_unrestricted || identityPermission.m_unrestricted) { return (IPermission) new StrongNameIdentityPermission(PermissionState.None) { m_unrestricted = true } } ; if (this.m_strongNames == null || this.m_strongNames.Length == 0) { if (identityPermission.m_strongNames == null || identityPermission.m_strongNames.Length == 0) { return((IPermission)null); } return(identityPermission.Copy()); } if (identityPermission.m_strongNames == null || identityPermission.m_strongNames.Length == 0) { return(this.Copy()); } List <StrongName2> strongName2List = new List <StrongName2>(); foreach (StrongName2 mStrongName in this.m_strongNames) { strongName2List.Add(mStrongName); } foreach (StrongName2 mStrongName in identityPermission.m_strongNames) { bool flag = false; foreach (StrongName2 target1 in strongName2List) { if (mStrongName.Equals(target1)) { flag = true; break; } } if (!flag) { strongName2List.Add(mStrongName); } } return((IPermission) new StrongNameIdentityPermission(PermissionState.None) { m_strongNames = strongName2List.ToArray() }); }
private void Compare (StrongNameIdentityPermission p1, StrongNameIdentityPermission p2, string prefix) { Assert.AreEqual (p1.Name, p2.Name, prefix + ".Name"); Assert.AreEqual (p1.PublicKey, p2.PublicKey, prefix + ".PublicKey"); Assert.AreEqual (p1.Version, p2.Version, prefix + ".Version"); Assert.IsFalse (Object.ReferenceEquals (p1, p2), "ReferenceEquals"); }
/// <internalonly/> int IBuiltInPermission.GetTokenIndex() { return(StrongNameIdentityPermission.GetTokenIndex()); }
public void Copy_NameEmpty () { StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None); snip.PublicKey = new StrongNamePublicKeyBlob (ecma); snip.Version = new Version ("1.2.3.4"); // because Name == String.Empty, which is illegal using the other constructor // but (somewhat) required to copy the teo other informations StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy (); #if NET_2_0 Assert.IsTrue (copy.Equals (snip), "Equals"); #else Assert.AreEqual (copy.ToXml ().ToString (), snip.ToXml ().ToString (), "Equals-XML"); #endif }
public override IPermission Intersect(IPermission target) { if (target == null) return null; StrongNameIdentityPermission that = target as StrongNameIdentityPermission; if(that == null) throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); if(this.m_unrestricted && that.m_unrestricted) { StrongNameIdentityPermission res = new StrongNameIdentityPermission(PermissionState.None); res.m_unrestricted = true; return res; } if(this.m_unrestricted) return that.Copy(); if(that.m_unrestricted) return this.Copy(); if(this.m_strongNames == null || that.m_strongNames == null || this.m_strongNames.Length == 0 || that.m_strongNames.Length == 0) return null; ArrayList alStrongNames = new ArrayList(); foreach(StrongName2 snThis in this.m_strongNames) { foreach(StrongName2 snThat in that.m_strongNames) { StrongName2 snInt = (StrongName2)snThis.Intersect(snThat); if(snInt != null) alStrongNames.Add(snInt); } } if(alStrongNames.Count == 0) return null; StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None); result.m_strongNames = (StrongName2[])alStrongNames.ToArray(typeof(StrongName2)); return result; }
public void Version () { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4)); Assert.AreEqual ("1.2.3.4", snip.Version.ToString (), "Version-1"); snip.Version = null; Assert.IsNull (snip.Version, "Version-2"); snip.Version = new Version (1, 2, 3); Assert.AreEqual ("1.2.3", snip.Version.ToString (), "Version-3"); }
internal StrongNameIdentityPermission (StrongNameIdentityPermission snip) { _state = snip._state; _list = new ArrayList (snip._list.Count); foreach (SNIP e in snip._list) { _list.Add (new SNIP (e.PublicKey, e.Name, e.AssemblyVersion)); } }
public void IsSubsetOf_Corlib () { Version fx11 = new Version (1, 0, 5000, 0); StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma); StrongNameIdentityPermission granted = new StrongNameIdentityPermission (blob, "mscorlib", fx11); StrongNameIdentityPermission demanded = new StrongNameIdentityPermission (blob, null, null); Assert.IsTrue (demanded.IsSubsetOf (granted), "pk"); demanded = new StrongNameIdentityPermission (blob, "mscorlib", null); Assert.IsTrue (demanded.IsSubsetOf (granted), "pk+name"); demanded = new StrongNameIdentityPermission (blob, null, fx11); Assert.IsTrue (demanded.IsSubsetOf (granted), "pk+v"); demanded = new StrongNameIdentityPermission (blob, "mscorlib", fx11); Assert.IsTrue (demanded.IsSubsetOf (granted), "pk+name+v"); }