This commit is contained in:
niko
2026-06-04 11:42:34 +02:00
parent f39ba70a9f
commit e720b98cd1
7488 changed files with 2493818 additions and 0 deletions
@@ -0,0 +1,274 @@
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using Mono.Security.Cryptography;
namespace System.Security.Policy
{
/// <summary>Determines whether an assembly belongs to a code group by testing its hash value. This class cannot be inherited.</summary>
// Token: 0x0200058E RID: 1422
[ComVisible(true)]
[Serializable]
public sealed class HashMembershipCondition : ISerializable, IDeserializationCallback, IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
{
// Token: 0x0600340E RID: 13326 RVA: 0x000B2FE8 File Offset: 0x000B11E8
internal HashMembershipCondition()
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.HashMembershipCondition" /> class with the hash algorithm and hash value that determine membership.</summary>
/// <param name="hashAlg">The hash algorithm to use to compute the hash value for the assembly. </param>
/// <param name="value">The hash value for which to test. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="hashAlg" /> parameter is null.-or- The <paramref name="value" /> parameter is null. </exception>
/// <exception cref="T:System.ArgumentException">The <paramref name="hashAlg" /> parameter is not a valid hash algorithm. </exception>
// Token: 0x0600340F RID: 13327 RVA: 0x000B2FF8 File Offset: 0x000B11F8
public HashMembershipCondition(HashAlgorithm hashAlg, byte[] value)
{
if (hashAlg == null)
{
throw new ArgumentNullException("hashAlg");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
this.hash_algorithm = hashAlg;
this.hash_value = (byte[])value.Clone();
}
/// <summary>Runs when the entire object graph has been deserialized.</summary>
/// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
// Token: 0x06003410 RID: 13328 RVA: 0x000B304C File Offset: 0x000B124C
[MonoTODO("fx 2.0")]
void IDeserializationCallback.OnDeserialization(object sender)
{
}
/// <summary>Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with the data needed to serialize the target object.</summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to populate with data. </param>
/// <param name="context">The destination <see cref="T:System.Runtime.Serialization.StreamingContext" /> for this serialization. </param>
// Token: 0x06003411 RID: 13329 RVA: 0x000B3050 File Offset: 0x000B1250
[MonoTODO("fx 2.0")]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
}
/// <summary>Gets or sets the hash algorithm to use for the membership condition.</summary>
/// <returns>The hash algorithm to use for the membership condition.</returns>
/// <exception cref="T:System.ArgumentNullException">An attempt is made to set <see cref="P:System.Security.Policy.HashMembershipCondition.HashAlgorithm" /> to 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: 0x17000A40 RID: 2624
// (get) Token: 0x06003412 RID: 13330 RVA: 0x000B3054 File Offset: 0x000B1254
// (set) Token: 0x06003413 RID: 13331 RVA: 0x000B3074 File Offset: 0x000B1274
public HashAlgorithm HashAlgorithm
{
get
{
if (this.hash_algorithm == null)
{
this.hash_algorithm = new SHA1Managed();
}
return this.hash_algorithm;
}
set
{
if (value == null)
{
throw new ArgumentNullException("HashAlgorithm");
}
this.hash_algorithm = value;
}
}
/// <summary>Gets or sets the hash value for which the membership condition tests.</summary>
/// <returns>The hash value for which the membership condition tests.</returns>
/// <exception cref="T:System.ArgumentNullException">An attempt is made to set <see cref="P:System.Security.Policy.HashMembershipCondition.HashValue" /> to null. </exception>
// Token: 0x17000A41 RID: 2625
// (get) Token: 0x06003414 RID: 13332 RVA: 0x000B3090 File Offset: 0x000B1290
// (set) Token: 0x06003415 RID: 13333 RVA: 0x000B30C0 File Offset: 0x000B12C0
public byte[] HashValue
{
get
{
if (this.hash_value == null)
{
throw new ArgumentException(Locale.GetText("No HashValue available."));
}
return (byte[])this.hash_value.Clone();
}
set
{
if (value == null)
{
throw new ArgumentNullException("HashValue");
}
this.hash_value = (byte[])value.Clone();
}
}
/// <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 evidence set against which to make the test. </param>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003416 RID: 13334 RVA: 0x000B30F0 File Offset: 0x000B12F0
public bool Check(Evidence evidence)
{
if (evidence == null)
{
return false;
}
IEnumerator hostEnumerator = evidence.GetHostEnumerator();
while (hostEnumerator.MoveNext())
{
object obj = hostEnumerator.Current;
Hash hash = obj as Hash;
if (hash != null)
{
if (this.Compare(this.hash_value, hash.GenerateHash(this.hash_algorithm)))
{
return true;
}
break;
}
}
return false;
}
/// <summary>Creates an equivalent copy of the membership condition.</summary>
/// <returns>A new, identical copy of the current membership condition.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003417 RID: 13335 RVA: 0x000B3158 File Offset: 0x000B1358
public IMembershipCondition Copy()
{
return new HashMembershipCondition(this.hash_algorithm, this.hash_value);
}
/// <summary>Determines whether the <see cref="P:System.Security.Policy.HashMembershipCondition.HashValue" /> and the <see cref="P:System.Security.Policy.HashMembershipCondition.HashAlgorithm" /> from the specified object are equivalent to the <see cref="P:System.Security.Policy.HashMembershipCondition.HashValue" /> and <see cref="P:System.Security.Policy.HashMembershipCondition.HashAlgorithm" /> contained in the current <see cref="T:System.Security.Policy.HashMembershipCondition" />.</summary>
/// <returns>true if the <see cref="P:System.Security.Policy.HashMembershipCondition.HashValue" /> and <see cref="P:System.Security.Policy.HashMembershipCondition.HashAlgorithm" /> from the specified object is equivalent to the <see cref="P:System.Security.Policy.HashMembershipCondition.HashValue" /> and <see cref="P:System.Security.Policy.HashMembershipCondition.HashAlgorithm" /> contained in the current <see cref="T:System.Security.Policy.HashMembershipCondition" />; otherwise, false.</returns>
/// <param name="o">The object to compare to the current <see cref="T:System.Security.Policy.HashMembershipCondition" />. </param>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003418 RID: 13336 RVA: 0x000B316C File Offset: 0x000B136C
public override bool Equals(object o)
{
HashMembershipCondition hashMembershipCondition = o as HashMembershipCondition;
return hashMembershipCondition != null && hashMembershipCondition.HashAlgorithm == this.hash_algorithm && this.Compare(this.hash_value, hashMembershipCondition.hash_value);
}
/// <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>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003419 RID: 13337 RVA: 0x000B31B0 File Offset: 0x000B13B0
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 policy level context for resolving named permission set references. </param>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x0600341A RID: 13338 RVA: 0x000B31BC File Offset: 0x000B13BC
public SecurityElement ToXml(PolicyLevel level)
{
SecurityElement securityElement = MembershipConditionHelper.Element(typeof(HashMembershipCondition), this.version);
securityElement.AddAttribute("HashValue", CryptoConvert.ToHex(this.HashValue));
securityElement.AddAttribute("HashAlgorithm", this.hash_algorithm.GetType().FullName);
return securityElement;
}
/// <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: 0x0600341B RID: 13339 RVA: 0x000B3214 File Offset: 0x000B1414
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 policy level context, used to resolve named permission set 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: 0x0600341C RID: 13340 RVA: 0x000B3220 File Offset: 0x000B1420
public void FromXml(SecurityElement e, PolicyLevel level)
{
MembershipConditionHelper.CheckSecurityElement(e, "e", this.version, this.version);
this.hash_value = CryptoConvert.FromHex(e.Attribute("HashValue"));
string text = e.Attribute("HashAlgorithm");
this.hash_algorithm = ((text != null) ? HashAlgorithm.Create(text) : null);
}
/// <summary>Gets the hash code for the current membership condition.</summary>
/// <returns>The hash code for the current membership condition.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x0600341D RID: 13341 RVA: 0x000B3280 File Offset: 0x000B1480
public override int GetHashCode()
{
int num = this.hash_algorithm.GetType().GetHashCode();
if (this.hash_value != null)
{
foreach (byte b in this.hash_value)
{
num ^= (int)b;
}
}
return num;
}
/// <summary>Creates and returns a string representation of the membership condition.</summary>
/// <returns>A string representation of the state of the membership condition.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x0600341E RID: 13342 RVA: 0x000B32D0 File Offset: 0x000B14D0
public override string ToString()
{
Type type = this.HashAlgorithm.GetType();
return string.Format("Hash - {0} {1} = {2}", type.FullName, type.Assembly, CryptoConvert.ToHex(this.HashValue));
}
// Token: 0x0600341F RID: 13343 RVA: 0x000B330C File Offset: 0x000B150C
private bool Compare(byte[] expected, byte[] actual)
{
if (expected.Length != actual.Length)
{
return false;
}
int num = expected.Length;
for (int i = 0; i < num; i++)
{
if (expected[i] != actual[i])
{
return false;
}
}
return true;
}
// Token: 0x04001555 RID: 5461
private readonly int version = 1;
// Token: 0x04001556 RID: 5462
private HashAlgorithm hash_algorithm;
// Token: 0x04001557 RID: 5463
private byte[] hash_value;
}
}