Files
2026-06-04 11:42:34 +02:00

266 lines
12 KiB
C#

using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
namespace System.Security.Policy
{
/// <summary>Determines whether an assembly belongs to a code group by testing its strong name. This class cannot be inherited.</summary>
// Token: 0x020005A1 RID: 1441
[ComVisible(true)]
[Serializable]
public sealed class StrongNameMembershipCondition : IConstantMembershipCondition, IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
{
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.StrongNameMembershipCondition" /> class with the strong name public key blob, name, and version number that determine membership.</summary>
/// <param name="blob">The strong name public key blob of the software publisher. </param>
/// <param name="name">The simple name section of the strong name. </param>
/// <param name="version">The version number of the strong name. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="blob" /> parameter is null. </exception>
/// <exception cref="T:System.ArgumentException">The <paramref name="name" /> parameter is null.-or-The <paramref name="name" /> parameter is an empty string ("").</exception>
// Token: 0x060034BC RID: 13500 RVA: 0x000B5DD0 File Offset: 0x000B3FD0
public StrongNameMembershipCondition(StrongNamePublicKeyBlob blob, string name, Version version)
{
if (blob == null)
{
throw new ArgumentNullException("blob");
}
this.blob = blob;
this.name = name;
if (version != null)
{
this.assemblyVersion = (Version)version.Clone();
}
}
// Token: 0x060034BD RID: 13501 RVA: 0x000B5E28 File Offset: 0x000B4028
internal StrongNameMembershipCondition(SecurityElement e)
{
this.FromXml(e);
}
// Token: 0x060034BE RID: 13502 RVA: 0x000B5E40 File Offset: 0x000B4040
internal StrongNameMembershipCondition()
{
}
/// <summary>Gets or sets the simple name of the <see cref="T:System.Security.Policy.StrongName" /> for which the membership condition tests.</summary>
/// <returns>The simple name of the <see cref="T:System.Security.Policy.StrongName" /> for which the membership condition tests.</returns>
/// <exception cref="T:System.ArgumentException">The value is null.-or-The value is an empty string ("").</exception>
// Token: 0x17000A58 RID: 2648
// (get) Token: 0x060034BF RID: 13503 RVA: 0x000B5E50 File Offset: 0x000B4050
// (set) Token: 0x060034C0 RID: 13504 RVA: 0x000B5E58 File Offset: 0x000B4058
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
/// <summary>Gets or sets the <see cref="T:System.Version" /> of the <see cref="T:System.Security.Policy.StrongName" /> for which the membership condition tests.</summary>
/// <returns>The <see cref="T:System.Version" /> of the <see cref="T:System.Security.Policy.StrongName" /> for which the membership condition tests.</returns>
// Token: 0x17000A59 RID: 2649
// (get) Token: 0x060034C1 RID: 13505 RVA: 0x000B5E64 File Offset: 0x000B4064
// (set) Token: 0x060034C2 RID: 13506 RVA: 0x000B5E6C File Offset: 0x000B406C
public Version Version
{
get
{
return this.assemblyVersion;
}
set
{
this.assemblyVersion = value;
}
}
/// <summary>Gets or sets the <see cref="T:System.Security.Permissions.StrongNamePublicKeyBlob" /> of the <see cref="T:System.Security.Policy.StrongName" /> for which the membership condition tests.</summary>
/// <returns>The <see cref="T:System.Security.Permissions.StrongNamePublicKeyBlob" /> of the <see cref="T:System.Security.Policy.StrongName" /> for which the membership condition tests.</returns>
/// <exception cref="T:System.ArgumentNullException">An attempt is made to set the <see cref="P:System.Security.Policy.StrongNameMembershipCondition.PublicKey" /> to null. </exception>
// Token: 0x17000A5A RID: 2650
// (get) Token: 0x060034C3 RID: 13507 RVA: 0x000B5E78 File Offset: 0x000B4078
// (set) Token: 0x060034C4 RID: 13508 RVA: 0x000B5E80 File Offset: 0x000B4080
public StrongNamePublicKeyBlob PublicKey
{
get
{
return this.blob;
}
set
{
if (value == null)
{
throw new ArgumentNullException("PublicKey");
}
this.blob = 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>
// Token: 0x060034C5 RID: 13509 RVA: 0x000B5E9C File Offset: 0x000B409C
public bool Check(Evidence evidence)
{
if (evidence == null)
{
return false;
}
IEnumerator hostEnumerator = evidence.GetHostEnumerator();
while (hostEnumerator.MoveNext())
{
object obj = hostEnumerator.Current;
StrongName strongName = obj as StrongName;
if (strongName != null)
{
return strongName.PublicKey.Equals(this.blob) && (this.name == null || !(this.name != strongName.Name)) && (!(this.assemblyVersion != null) || this.assemblyVersion.Equals(strongName.Version));
}
}
return false;
}
/// <summary>Creates an equivalent copy of the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />.</summary>
/// <returns>A new, identical copy of the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" /></returns>
// Token: 0x060034C6 RID: 13510 RVA: 0x000B5F44 File Offset: 0x000B4144
public IMembershipCondition Copy()
{
return new StrongNameMembershipCondition(this.blob, this.name, this.assemblyVersion);
}
/// <summary>Determines whether the <see cref="T:System.Security.Policy.StrongName" /> from the specified object is equivalent to the <see cref="T:System.Security.Policy.StrongName" /> contained in the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />.</summary>
/// <returns>true if the <see cref="T:System.Security.Policy.StrongName" /> from the specified object is equivalent to the <see cref="T:System.Security.Policy.StrongName" /> contained in the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />; otherwise, false.</returns>
/// <param name="o">The object to compare to the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />. </param>
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.StrongNameMembershipCondition.PublicKey" /> property of the current object or the specified object is null. </exception>
// Token: 0x060034C7 RID: 13511 RVA: 0x000B5F60 File Offset: 0x000B4160
public override bool Equals(object o)
{
StrongNameMembershipCondition strongNameMembershipCondition = o as StrongNameMembershipCondition;
if (strongNameMembershipCondition == null)
{
return false;
}
if (!strongNameMembershipCondition.PublicKey.Equals(this.PublicKey))
{
return false;
}
if (this.name != strongNameMembershipCondition.Name)
{
return false;
}
if (this.assemblyVersion != null)
{
return this.assemblyVersion.Equals(strongNameMembershipCondition.Version);
}
return strongNameMembershipCondition.Version == null;
}
/// <summary>Returns the hash code for the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />.</summary>
/// <returns>The hash code for the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />.</returns>
/// <exception cref="T:System.ArgumentException">The <see cref="P:System.Security.Policy.StrongNameMembershipCondition.PublicKey" /> property is null. </exception>
// Token: 0x060034C8 RID: 13512 RVA: 0x000B5FDC File Offset: 0x000B41DC
public override int GetHashCode()
{
return this.blob.GetHashCode();
}
/// <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>
// Token: 0x060034C9 RID: 13513 RVA: 0x000B5FEC File Offset: 0x000B41EC
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: 0x060034CA RID: 13514 RVA: 0x000B5FF8 File Offset: 0x000B41F8
public void FromXml(SecurityElement e, PolicyLevel level)
{
MembershipConditionHelper.CheckSecurityElement(e, "e", this.version, this.version);
this.blob = StrongNamePublicKeyBlob.FromString(e.Attribute("PublicKeyBlob"));
this.name = e.Attribute("Name");
string text = e.Attribute("AssemblyVersion");
if (text == null)
{
this.assemblyVersion = null;
}
else
{
this.assemblyVersion = new Version(text);
}
}
/// <summary>Creates and returns a string representation of the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />.</summary>
/// <returns>A representation of the current <see cref="T:System.Security.Policy.StrongNameMembershipCondition" />.</returns>
// Token: 0x060034CB RID: 13515 RVA: 0x000B6070 File Offset: 0x000B4270
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder("StrongName - ");
stringBuilder.Append(this.blob);
if (this.name != null)
{
stringBuilder.AppendFormat(" name = {0}", this.name);
}
if (this.assemblyVersion != null)
{
stringBuilder.AppendFormat(" version = {0}", this.assemblyVersion);
}
return stringBuilder.ToString();
}
/// <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>
// Token: 0x060034CC RID: 13516 RVA: 0x000B60DC File Offset: 0x000B42DC
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, which is used to resolve <see cref="T:System.Security.NamedPermissionSet" /> references. </param>
// Token: 0x060034CD RID: 13517 RVA: 0x000B60E8 File Offset: 0x000B42E8
public SecurityElement ToXml(PolicyLevel level)
{
SecurityElement securityElement = MembershipConditionHelper.Element(typeof(StrongNameMembershipCondition), this.version);
if (this.blob != null)
{
securityElement.AddAttribute("PublicKeyBlob", this.blob.ToString());
}
if (this.name != null)
{
securityElement.AddAttribute("Name", this.name);
}
if (this.assemblyVersion != null)
{
string text = this.assemblyVersion.ToString();
if (text != "0.0")
{
securityElement.AddAttribute("AssemblyVersion", text);
}
}
return securityElement;
}
// Token: 0x04001579 RID: 5497
private readonly int version = 1;
// Token: 0x0400157A RID: 5498
private StrongNamePublicKeyBlob blob;
// Token: 0x0400157B RID: 5499
private string name;
// Token: 0x0400157C RID: 5500
private Version assemblyVersion;
}
}