194 lines
9.5 KiB
C#
194 lines
9.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Globalization;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Security.Policy
|
|
{
|
|
/// <summary>Determines whether an assembly belongs to a code group by testing the site from which it originated. This class cannot be inherited.</summary>
|
|
// Token: 0x0200059F RID: 1439
|
|
[ComVisible(true)]
|
|
[Serializable]
|
|
public sealed class SiteMembershipCondition : IConstantMembershipCondition, IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
|
|
{
|
|
// Token: 0x060034A3 RID: 13475 RVA: 0x000B59C0 File Offset: 0x000B3BC0
|
|
internal SiteMembershipCondition()
|
|
{
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.SiteMembershipCondition" /> class with name of the site that determines membership.</summary>
|
|
/// <param name="site">The site name or wildcard expression. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="site" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="site" /> parameter is not a valid <see cref="T:System.Security.Policy.Site" />. </exception>
|
|
// Token: 0x060034A4 RID: 13476 RVA: 0x000B59D0 File Offset: 0x000B3BD0
|
|
public SiteMembershipCondition(string site)
|
|
{
|
|
this.Site = site;
|
|
}
|
|
|
|
/// <summary>Gets or sets the site for which the membership condition tests.</summary>
|
|
/// <returns>The site for which the membership condition tests.</returns>
|
|
/// <exception cref="T:System.ArgumentNullException">An attempt is made to set <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> to null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">An attempt is made to set <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> to an invalid <see cref="T:System.Security.Policy.Site" />. </exception>
|
|
// Token: 0x17000A54 RID: 2644
|
|
// (get) Token: 0x060034A5 RID: 13477 RVA: 0x000B59E8 File Offset: 0x000B3BE8
|
|
// (set) Token: 0x060034A6 RID: 13478 RVA: 0x000B59F0 File Offset: 0x000B3BF0
|
|
public string Site
|
|
{
|
|
get
|
|
{
|
|
return this._site;
|
|
}
|
|
set
|
|
{
|
|
if (value == null)
|
|
{
|
|
throw new ArgumentNullException("site");
|
|
}
|
|
if (!global::System.Security.Policy.Site.IsValid(value))
|
|
{
|
|
throw new ArgumentException("invalid site");
|
|
}
|
|
this._site = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Determines whether the specified evidence satisfies the membership condition.</summary>
|
|
/// <returns>true if the specified evidence satisfies the membership condition; otherwise, false.</returns>
|
|
/// <param name="evidence">The <see cref="T:System.Security.Policy.Evidence" /> against which to make the test. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> property is null. </exception>
|
|
// Token: 0x060034A7 RID: 13479 RVA: 0x000B5A2C File Offset: 0x000B3C2C
|
|
public bool Check(Evidence evidence)
|
|
{
|
|
if (evidence == null)
|
|
{
|
|
return false;
|
|
}
|
|
IEnumerator hostEnumerator = evidence.GetHostEnumerator();
|
|
while (hostEnumerator.MoveNext())
|
|
{
|
|
if (hostEnumerator.Current is Site)
|
|
{
|
|
string[] array = this._site.Split(new char[] { '.' });
|
|
string[] array2 = (hostEnumerator.Current as Site).origin_site.Split(new char[] { '.' });
|
|
int i = array.Length - 1;
|
|
int num = array2.Length - 1;
|
|
while (i >= 0)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
return string.Compare(array[0], "*", true, CultureInfo.InvariantCulture) == 0;
|
|
}
|
|
if (string.Compare(array[i], array2[num], true, CultureInfo.InvariantCulture) != 0)
|
|
{
|
|
return false;
|
|
}
|
|
i--;
|
|
num--;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Creates an equivalent copy of the membership condition.</summary>
|
|
/// <returns>A new, identical copy of the current membership condition.</returns>
|
|
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> property is null. </exception>
|
|
// Token: 0x060034A8 RID: 13480 RVA: 0x000B5AFC File Offset: 0x000B3CFC
|
|
public IMembershipCondition Copy()
|
|
{
|
|
return new SiteMembershipCondition(this._site);
|
|
}
|
|
|
|
/// <summary>Determines whether the site from the specified <see cref="T:System.Security.Policy.SiteMembershipCondition" /> object is equivalent to the site contained in the current <see cref="T:System.Security.Policy.SiteMembershipCondition" />.</summary>
|
|
/// <returns>true if the site from the specified <see cref="T:System.Security.Policy.SiteMembershipCondition" /> object is equivalent to the site contained in the current <see cref="T:System.Security.Policy.SiteMembershipCondition" />; otherwise, false.</returns>
|
|
/// <param name="o">The <see cref="T:System.Security.Policy.SiteMembershipCondition" /> object to compare to the current <see cref="T:System.Security.Policy.SiteMembershipCondition" />. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> property for the current object or the specified object is null. </exception>
|
|
// Token: 0x060034A9 RID: 13481 RVA: 0x000B5B0C File Offset: 0x000B3D0C
|
|
public override bool Equals(object o)
|
|
{
|
|
if (o == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (o is SiteMembershipCondition)
|
|
{
|
|
Site site = new Site((o as SiteMembershipCondition)._site);
|
|
return site.Equals(new Site(this._site));
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Reconstructs a security object with a specified state from an XML encoding.</summary>
|
|
/// <param name="e">The XML encoding to use to reconstruct the security object. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="e" /> parameter is not a valid membership condition element. </exception>
|
|
// Token: 0x060034AA RID: 13482 RVA: 0x000B5B50 File Offset: 0x000B3D50
|
|
public void FromXml(SecurityElement e)
|
|
{
|
|
this.FromXml(e, null);
|
|
}
|
|
|
|
/// <summary>Reconstructs a security object with a specified state from an XML encoding.</summary>
|
|
/// <param name="e">The XML encoding to use to reconstruct the security object. </param>
|
|
/// <param name="level">The <see cref="T:System.Security.Policy.PolicyLevel" /> context, used to resolve <see cref="T:System.Security.NamedPermissionSet" /> references. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="e" /> parameter is not a valid membership condition element. </exception>
|
|
// Token: 0x060034AB RID: 13483 RVA: 0x000B5B5C File Offset: 0x000B3D5C
|
|
public void FromXml(SecurityElement e, PolicyLevel level)
|
|
{
|
|
MembershipConditionHelper.CheckSecurityElement(e, "e", this.version, this.version);
|
|
this._site = e.Attribute("Site");
|
|
}
|
|
|
|
/// <summary>Gets the hash code for the current membership condition.</summary>
|
|
/// <returns>The hash code for the current membership condition.</returns>
|
|
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> property is null. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
|
/// </PermissionSet>
|
|
// Token: 0x060034AC RID: 13484 RVA: 0x000B5B88 File Offset: 0x000B3D88
|
|
public override int GetHashCode()
|
|
{
|
|
return this._site.GetHashCode();
|
|
}
|
|
|
|
/// <summary>Creates and returns a string representation of the membership condition.</summary>
|
|
/// <returns>A string representation of the membership condition.</returns>
|
|
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> property is null. </exception>
|
|
// Token: 0x060034AD RID: 13485 RVA: 0x000B5B98 File Offset: 0x000B3D98
|
|
public override string ToString()
|
|
{
|
|
return "Site - " + this._site;
|
|
}
|
|
|
|
/// <summary>Creates an XML encoding of the security object and its current state.</summary>
|
|
/// <returns>An XML encoding of the security object, including any state information.</returns>
|
|
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> property is null. </exception>
|
|
// Token: 0x060034AE RID: 13486 RVA: 0x000B5BAC File Offset: 0x000B3DAC
|
|
public SecurityElement ToXml()
|
|
{
|
|
return this.ToXml(null);
|
|
}
|
|
|
|
/// <summary>Creates an XML encoding of the security object and its current state with the specified <see cref="T:System.Security.Policy.PolicyLevel" />.</summary>
|
|
/// <returns>An XML encoding of the security object, including any state information.</returns>
|
|
/// <param name="level">The <see cref="T:System.Security.Policy.PolicyLevel" /> context, used to resolve <see cref="T:System.Security.NamedPermissionSet" /> references. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.SiteMembershipCondition.Site" /> property is null. </exception>
|
|
// Token: 0x060034AF RID: 13487 RVA: 0x000B5BB8 File Offset: 0x000B3DB8
|
|
public SecurityElement ToXml(PolicyLevel level)
|
|
{
|
|
SecurityElement securityElement = MembershipConditionHelper.Element(typeof(SiteMembershipCondition), this.version);
|
|
securityElement.AddAttribute("Site", this._site);
|
|
return securityElement;
|
|
}
|
|
|
|
// Token: 0x04001574 RID: 5492
|
|
private readonly int version = 1;
|
|
|
|
// Token: 0x04001575 RID: 5493
|
|
private string _site;
|
|
}
|
|
}
|