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

486 lines
16 KiB
C#

using System;
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace System.Security.Policy
{
/// <summary>Defines the set of information that constitutes input to security policy decisions. This class cannot be inherited.</summary>
// Token: 0x02000587 RID: 1415
[ComVisible(true)]
[MonoTODO("Serialization format not compatible with .NET")]
[Serializable]
public sealed class Evidence : IEnumerable, ICollection
{
/// <summary>Initializes a new empty instance of the <see cref="T:System.Security.Policy.Evidence" /> class.</summary>
// Token: 0x060033BE RID: 13246 RVA: 0x000B1F40 File Offset: 0x000B0140
public Evidence()
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.Evidence" /> class from a shallow copy of an existing one.</summary>
/// <param name="evidence">The <see cref="T:System.Security.Policy.Evidence" /> instance from which to create the new instance. This instance is not deep copied. </param>
/// <exception cref="T:System.ArgumentException">The <paramref name="evidence" /> parameter is not a valid instance of <see cref="T:System.Security.Policy.Evidence" />. </exception>
// Token: 0x060033BF RID: 13247 RVA: 0x000B1F48 File Offset: 0x000B0148
public Evidence(Evidence evidence)
{
if (evidence != null)
{
this.Merge(evidence);
}
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.Evidence" /> class from multiple sets of host and assembly evidence.</summary>
/// <param name="hostEvidence">The host evidence from which to create the new instance. </param>
/// <param name="assemblyEvidence">The assembly evidence from which to create the new instance. </param>
// Token: 0x060033C0 RID: 13248 RVA: 0x000B1F60 File Offset: 0x000B0160
public Evidence(object[] hostEvidence, object[] assemblyEvidence)
{
if (hostEvidence != null)
{
this.HostEvidenceList.AddRange(hostEvidence);
}
if (assemblyEvidence != null)
{
this.AssemblyEvidenceList.AddRange(assemblyEvidence);
}
}
/// <summary>Gets the number of evidence objects in the evidence set.</summary>
/// <returns>The number of evidence objects in the evidence set.</returns>
// Token: 0x17000A32 RID: 2610
// (get) Token: 0x060033C1 RID: 13249 RVA: 0x000B1F98 File Offset: 0x000B0198
public int Count
{
get
{
int num = 0;
if (this.hostEvidenceList != null)
{
num += this.hostEvidenceList.Count;
}
if (this.assemblyEvidenceList != null)
{
num += this.assemblyEvidenceList.Count;
}
return num;
}
}
/// <summary>Gets a value indicating whether the evidence set is read-only.</summary>
/// <returns>Always false because read-only evidence sets are not supported.</returns>
// Token: 0x17000A33 RID: 2611
// (get) Token: 0x060033C2 RID: 13250 RVA: 0x000B1FDC File Offset: 0x000B01DC
public bool IsReadOnly
{
get
{
return false;
}
}
/// <summary>Gets a value indicating whether the evidence set is thread-safe.</summary>
/// <returns>Always false because thread-safe evidence sets are not supported.</returns>
// Token: 0x17000A34 RID: 2612
// (get) Token: 0x060033C3 RID: 13251 RVA: 0x000B1FE0 File Offset: 0x000B01E0
public bool IsSynchronized
{
get
{
return false;
}
}
/// <summary>Gets or sets a value indicating whether the evidence is locked.</summary>
/// <returns>true if the evidence is locked; otherwise, false. The default is false.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
/// </PermissionSet>
// Token: 0x17000A35 RID: 2613
// (get) Token: 0x060033C4 RID: 13252 RVA: 0x000B1FE4 File Offset: 0x000B01E4
// (set) Token: 0x060033C5 RID: 13253 RVA: 0x000B1FEC File Offset: 0x000B01EC
public bool Locked
{
get
{
return this._locked;
}
set
{
this._locked = value;
}
}
/// <summary>Gets the synchronization root.</summary>
/// <returns>Always this (Me in Visual Basic) because synchronization of evidence sets is not supported.</returns>
// Token: 0x17000A36 RID: 2614
// (get) Token: 0x060033C6 RID: 13254 RVA: 0x000B1FF8 File Offset: 0x000B01F8
public object SyncRoot
{
get
{
return this;
}
}
// Token: 0x17000A37 RID: 2615
// (get) Token: 0x060033C7 RID: 13255 RVA: 0x000B1FFC File Offset: 0x000B01FC
internal ArrayList HostEvidenceList
{
get
{
if (this.hostEvidenceList == null)
{
this.hostEvidenceList = ArrayList.Synchronized(new ArrayList());
}
return this.hostEvidenceList;
}
}
// Token: 0x17000A38 RID: 2616
// (get) Token: 0x060033C8 RID: 13256 RVA: 0x000B2020 File Offset: 0x000B0220
internal ArrayList AssemblyEvidenceList
{
get
{
if (this.assemblyEvidenceList == null)
{
this.assemblyEvidenceList = ArrayList.Synchronized(new ArrayList());
}
return this.assemblyEvidenceList;
}
}
/// <summary>Adds the specified assembly evidence to the evidence set.</summary>
/// <param name="id">Any evidence object. </param>
// Token: 0x060033C9 RID: 13257 RVA: 0x000B2044 File Offset: 0x000B0244
public void AddAssembly(object id)
{
this.AssemblyEvidenceList.Add(id);
this._hashCode = 0;
}
/// <summary>Adds the specified evidence supplied by the host to the evidence set.</summary>
/// <param name="id">Any evidence object. </param>
/// <exception cref="T:System.Security.SecurityException">
/// <see cref="P:System.Security.Policy.Evidence.Locked" /> is true and the code that calls this method does not have <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlEvidence" />. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
/// </PermissionSet>
// Token: 0x060033CA RID: 13258 RVA: 0x000B205C File Offset: 0x000B025C
public void AddHost(object id)
{
if (this._locked && SecurityManager.SecurityEnabled)
{
new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
}
this.HostEvidenceList.Add(id);
this._hashCode = 0;
}
/// <summary>Removes the host and assembly evidence from the evidence set.</summary>
// Token: 0x060033CB RID: 13259 RVA: 0x000B20A0 File Offset: 0x000B02A0
[ComVisible(false)]
public void Clear()
{
if (this.hostEvidenceList != null)
{
this.hostEvidenceList.Clear();
}
if (this.assemblyEvidenceList != null)
{
this.assemblyEvidenceList.Clear();
}
this._hashCode = 0;
}
/// <summary>Copies evidence objects to an <see cref="T:System.Array" />.</summary>
/// <param name="array">The target array to which to copy evidence objects. </param>
/// <param name="index">The zero-based position in the array to which to begin copying evidence objects. </param>
// Token: 0x060033CC RID: 13260 RVA: 0x000B20D8 File Offset: 0x000B02D8
public void CopyTo(Array array, int index)
{
int num = 0;
if (this.hostEvidenceList != null)
{
num = this.hostEvidenceList.Count;
if (num > 0)
{
this.hostEvidenceList.CopyTo(array, index);
}
}
if (this.assemblyEvidenceList != null && this.assemblyEvidenceList.Count > 0)
{
this.assemblyEvidenceList.CopyTo(array, index + num);
}
}
/// <summary>Determines whether the specified <see cref="T:System.Security.Policy.Evidence" /> object is equal to the current <see cref="T:System.Security.Policy.Evidence" />.</summary>
/// <returns>true if the specified <see cref="T:System.Security.Policy.Evidence" /> object is equal to the current <see cref="T:System.Security.Policy.Evidence" />; otherwise, false.</returns>
/// <param name="obj">The <see cref="T:System.Security.Policy.Evidence" /> object to compare with the current <see cref="T:System.Security.Policy.Evidence" />. </param>
// Token: 0x060033CD RID: 13261 RVA: 0x000B2140 File Offset: 0x000B0340
[ComVisible(false)]
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
Evidence evidence = obj as Evidence;
if (evidence == null)
{
return false;
}
if (this.HostEvidenceList.Count != evidence.HostEvidenceList.Count)
{
return false;
}
if (this.AssemblyEvidenceList.Count != evidence.AssemblyEvidenceList.Count)
{
return false;
}
for (int i = 0; i < this.hostEvidenceList.Count; i++)
{
bool flag = false;
int j = 0;
while (j < evidence.hostEvidenceList.Count)
{
if (this.hostEvidenceList[i].Equals(evidence.hostEvidenceList[j]))
{
flag = true;
break;
}
i++;
}
if (!flag)
{
return false;
}
}
for (int k = 0; k < this.assemblyEvidenceList.Count; k++)
{
bool flag2 = false;
int l = 0;
while (l < evidence.assemblyEvidenceList.Count)
{
if (this.assemblyEvidenceList[k].Equals(evidence.assemblyEvidenceList[l]))
{
flag2 = true;
break;
}
k++;
}
if (!flag2)
{
return false;
}
}
return true;
}
/// <summary>Enumerates all evidence in the set, both that provided by the host and that provided by the assembly.</summary>
/// <returns>An enumerator for evidence added by both the <see cref="M:System.Security.Policy.Evidence.AddHost(System.Object)" /> method and the <see cref="M:System.Security.Policy.Evidence.AddAssembly(System.Object)" /> method.</returns>
// Token: 0x060033CE RID: 13262 RVA: 0x000B2284 File Offset: 0x000B0484
public IEnumerator GetEnumerator()
{
IEnumerator enumerator = null;
if (this.hostEvidenceList != null)
{
enumerator = this.hostEvidenceList.GetEnumerator();
}
IEnumerator enumerator2 = null;
if (this.assemblyEvidenceList != null)
{
enumerator2 = this.assemblyEvidenceList.GetEnumerator();
}
return new Evidence.EvidenceEnumerator(enumerator, enumerator2);
}
/// <summary>Enumerates evidence provided by the assembly.</summary>
/// <returns>An enumerator for evidence added by the <see cref="M:System.Security.Policy.Evidence.AddAssembly(System.Object)" /> method.</returns>
// Token: 0x060033CF RID: 13263 RVA: 0x000B22CC File Offset: 0x000B04CC
public IEnumerator GetAssemblyEnumerator()
{
return this.AssemblyEvidenceList.GetEnumerator();
}
/// <summary>Gets a hash code for the <see cref="T:System.Security.Policy.Evidence" /> object that is suitable for use in hashing algorithms and data structures such as a hash table.</summary>
/// <returns>A hash code for the current <see cref="T:System.Security.Policy.Evidence" /> object.</returns>
// Token: 0x060033D0 RID: 13264 RVA: 0x000B22DC File Offset: 0x000B04DC
[ComVisible(false)]
public override int GetHashCode()
{
if (this._hashCode == 0)
{
if (this.hostEvidenceList != null)
{
for (int i = 0; i < this.hostEvidenceList.Count; i++)
{
this._hashCode ^= this.hostEvidenceList[i].GetHashCode();
}
}
if (this.assemblyEvidenceList != null)
{
for (int j = 0; j < this.assemblyEvidenceList.Count; j++)
{
this._hashCode ^= this.assemblyEvidenceList[j].GetHashCode();
}
}
}
return this._hashCode;
}
/// <summary>Enumerates evidence supplied by the host.</summary>
/// <returns>An enumerator for evidence added by the <see cref="M:System.Security.Policy.Evidence.AddHost(System.Object)" /> method.</returns>
// Token: 0x060033D1 RID: 13265 RVA: 0x000B2384 File Offset: 0x000B0584
public IEnumerator GetHostEnumerator()
{
return this.HostEvidenceList.GetEnumerator();
}
/// <summary>Merges the specified evidence set into the current evidence set.</summary>
/// <param name="evidence">The evidence set to be merged into the current evidence set. </param>
/// <exception cref="T:System.ArgumentException">The <paramref name="evidence" /> parameter is not a valid instance of <see cref="T:System.Security.Policy.Evidence" />. </exception>
/// <exception cref="T:System.Security.SecurityException">
/// <see cref="P:System.Security.Policy.Evidence.Locked" /> is true, the code that calls this method does not have <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlEvidence" />, and the <paramref name="evidence" /> parameter has a host list that is not empty. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
/// </PermissionSet>
// Token: 0x060033D2 RID: 13266 RVA: 0x000B2394 File Offset: 0x000B0594
public void Merge(Evidence evidence)
{
if (evidence != null && evidence.Count > 0)
{
if (evidence.hostEvidenceList != null)
{
foreach (object obj in evidence.hostEvidenceList)
{
this.AddHost(obj);
}
}
if (evidence.assemblyEvidenceList != null)
{
foreach (object obj2 in evidence.assemblyEvidenceList)
{
this.AddAssembly(obj2);
}
}
this._hashCode = 0;
}
}
/// <summary>Removes the evidence for a given type from the host and assembly enumerations.</summary>
/// <param name="t">The <see cref="T:System.Type" /> of the evidence to be removed. </param>
// Token: 0x060033D3 RID: 13267 RVA: 0x000B248C File Offset: 0x000B068C
[ComVisible(false)]
public void RemoveType(Type t)
{
for (int i = this.hostEvidenceList.Count; i >= 0; i--)
{
if (this.hostEvidenceList.GetType() == t)
{
this.hostEvidenceList.RemoveAt(i);
this._hashCode = 0;
}
}
for (int j = this.assemblyEvidenceList.Count; j >= 0; j--)
{
if (this.assemblyEvidenceList.GetType() == t)
{
this.assemblyEvidenceList.RemoveAt(j);
this._hashCode = 0;
}
}
}
// Token: 0x060033D4 RID: 13268
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool IsAuthenticodePresent(Assembly a);
// Token: 0x060033D5 RID: 13269 RVA: 0x000B251C File Offset: 0x000B071C
internal static Evidence GetDefaultHostEvidence(Assembly a)
{
return new Evidence();
}
// Token: 0x04001548 RID: 5448
private bool _locked;
// Token: 0x04001549 RID: 5449
private ArrayList hostEvidenceList;
// Token: 0x0400154A RID: 5450
private ArrayList assemblyEvidenceList;
// Token: 0x0400154B RID: 5451
private int _hashCode;
// Token: 0x02000588 RID: 1416
private class EvidenceEnumerator : IEnumerator
{
// Token: 0x060033D6 RID: 13270 RVA: 0x000B2524 File Offset: 0x000B0724
public EvidenceEnumerator(IEnumerator hostenum, IEnumerator assemblyenum)
{
this.hostEnum = hostenum;
this.assemblyEnum = assemblyenum;
this.currentEnum = this.hostEnum;
}
// Token: 0x060033D7 RID: 13271 RVA: 0x000B2554 File Offset: 0x000B0754
public bool MoveNext()
{
if (this.currentEnum == null)
{
return false;
}
bool flag = this.currentEnum.MoveNext();
if (!flag && this.hostEnum == this.currentEnum && this.assemblyEnum != null)
{
this.currentEnum = this.assemblyEnum;
flag = this.assemblyEnum.MoveNext();
}
return flag;
}
// Token: 0x060033D8 RID: 13272 RVA: 0x000B25B8 File Offset: 0x000B07B8
public void Reset()
{
if (this.hostEnum != null)
{
this.hostEnum.Reset();
this.currentEnum = this.hostEnum;
}
else
{
this.currentEnum = this.assemblyEnum;
}
if (this.assemblyEnum != null)
{
this.assemblyEnum.Reset();
}
}
// Token: 0x17000A39 RID: 2617
// (get) Token: 0x060033D9 RID: 13273 RVA: 0x000B2610 File Offset: 0x000B0810
public object Current
{
get
{
return this.currentEnum.Current;
}
}
// Token: 0x0400154C RID: 5452
private IEnumerator currentEnum;
// Token: 0x0400154D RID: 5453
private IEnumerator hostEnum;
// Token: 0x0400154E RID: 5454
private IEnumerator assemblyEnum;
}
}
}