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
{
/// Determines whether an assembly belongs to a code group by testing its hash value. This class cannot be inherited.
// 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()
{
}
/// Initializes a new instance of the class with the hash algorithm and hash value that determine membership.
/// The hash algorithm to use to compute the hash value for the assembly.
/// The hash value for which to test.
/// The parameter is null.-or- The parameter is null.
/// The parameter is not a valid hash algorithm.
// 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();
}
/// Runs when the entire object graph has been deserialized.
/// The object that initiated the callback. The functionality for this parameter is not currently implemented.
// Token: 0x06003410 RID: 13328 RVA: 0x000B304C File Offset: 0x000B124C
[MonoTODO("fx 2.0")]
void IDeserializationCallback.OnDeserialization(object sender)
{
}
/// Populates a with the data needed to serialize the target object.
/// The to populate with data.
/// The destination for this serialization.
// Token: 0x06003411 RID: 13329 RVA: 0x000B3050 File Offset: 0x000B1250
[MonoTODO("fx 2.0")]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
}
/// Gets or sets the hash algorithm to use for the membership condition.
/// The hash algorithm to use for the membership condition.
/// An attempt is made to set to null.
///
///
///
// 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;
}
}
/// Gets or sets the hash value for which the membership condition tests.
/// The hash value for which the membership condition tests.
/// An attempt is made to set to null.
// 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();
}
}
/// Determines whether the specified evidence satisfies the membership condition.
/// true if the specified evidence satisfies the membership condition; otherwise, false.
/// The evidence set against which to make the test.
///
///
///
///
// 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;
}
/// Creates an equivalent copy of the membership condition.
/// A new, identical copy of the current membership condition.
///
///
///
// Token: 0x06003417 RID: 13335 RVA: 0x000B3158 File Offset: 0x000B1358
public IMembershipCondition Copy()
{
return new HashMembershipCondition(this.hash_algorithm, this.hash_value);
}
/// Determines whether the and the from the specified object are equivalent to the and contained in the current .
/// true if the and from the specified object is equivalent to the and contained in the current ; otherwise, false.
/// The object to compare to the current .
///
///
///
// 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);
}
/// Creates an XML encoding of the security object and its current state.
/// An XML encoding of the security object, including any state information.
///
///
///
// Token: 0x06003419 RID: 13337 RVA: 0x000B31B0 File Offset: 0x000B13B0
public SecurityElement ToXml()
{
return this.ToXml(null);
}
/// Creates an XML encoding of the security object and its current state with the specified .
/// An XML encoding of the security object, including any state information.
/// The policy level context for resolving named permission set references.
///
///
///
// 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;
}
/// Reconstructs a security object with a specified state from an XML encoding.
/// The XML encoding to use to reconstruct the security object.
// Token: 0x0600341B RID: 13339 RVA: 0x000B3214 File Offset: 0x000B1414
public void FromXml(SecurityElement e)
{
this.FromXml(e, null);
}
/// Reconstructs a security object with a specified state from an XML encoding.
/// The XML encoding to use to reconstruct the security object.
/// The policy level context, used to resolve named permission set references.
/// The parameter is null.
/// The parameter is not a valid membership condition element.
// 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);
}
/// Gets the hash code for the current membership condition.
/// The hash code for the current membership condition.
///
///
///
// 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;
}
/// Creates and returns a string representation of the membership condition.
/// A string representation of the state of the membership condition.
///
///
///
// 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;
}
}