using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Security.Cryptography.X509Certificates;
-
using Mono.Security.Authenticode;
namespace System.Security.Policy {
[Serializable]
- [MonoTODO ("Fix serialization compatibility with MS.NET")]
-#if NET_2_0
+ [MonoTODO ("Serialization format not compatible with .NET")]
[ComVisible (true)]
-#endif
public sealed class Evidence : ICollection, IEnumerable {
private bool _locked;
private ArrayList hostEvidenceList;
private ArrayList assemblyEvidenceList;
- private int _hashCode;
public Evidence ()
{
Merge (evidence);
}
+ [Obsolete]
public Evidence (object[] hostEvidence, object[] assemblyEvidence)
{
if (null != hostEvidence)
// Public Properties
//
+ [Obsolete]
public int Count {
get {
int count = 0;
}
public bool IsSynchronized {
-#if NET_2_0
get { return false; }
-#else
- // LAMESPEC: Always TRUE (not FALSE)
- get { return true; }
-#endif
}
public bool Locked {
// Public Methods
//
+ [Obsolete]
public void AddAssembly (object id)
{
AssemblyEvidenceList.Add (id);
- _hashCode = 0;
}
+ [Obsolete]
public void AddHost (object id)
{
if (_locked && SecurityManager.SecurityEnabled) {
new SecurityPermission (SecurityPermissionFlag.ControlEvidence).Demand ();
}
HostEvidenceList.Add (id);
- _hashCode = 0;
}
-#if NET_2_0
[ComVisible (false)]
public void Clear ()
{
hostEvidenceList.Clear ();
if (assemblyEvidenceList != null)
assemblyEvidenceList.Clear ();
- _hashCode = 0;
}
-#endif
+ [ComVisible(false)]
+ public Evidence Clone ()
+ {
+ return new Evidence(this);
+ }
+
+ [Obsolete]
public void CopyTo (Array array, int index)
{
int hc = 0;
assemblyEvidenceList.CopyTo (array, index + hc);
}
-#if NET_2_0
- [ComVisible (false)]
- public override bool Equals (object obj)
- {
- if (obj == null)
- return false;
- Evidence e = (obj as Evidence);
- if (e == null)
- return false;
-
- if (HostEvidenceList.Count != e.HostEvidenceList.Count)
- return false;
- if (AssemblyEvidenceList.Count != e.AssemblyEvidenceList.Count)
- return false;
-
- for (int i = 0; i < hostEvidenceList.Count; i++) {
- bool found = false;
- for (int j = 0; j < e.hostEvidenceList.Count; i++) {
- if (hostEvidenceList [i].Equals (e.hostEvidenceList [j])) {
- found = true;
- break;
- }
- }
- if (!found)
- return false;
- }
- for (int i = 0; i < assemblyEvidenceList.Count; i++) {
- bool found = false;
- for (int j = 0; j < e.assemblyEvidenceList.Count; i++) {
- if (assemblyEvidenceList [i].Equals (e.assemblyEvidenceList [j])) {
- found = true;
- break;
- }
- }
- if (!found)
- return false;
- }
-
- return true;
- }
-#endif
+ [Obsolete]
public IEnumerator GetEnumerator ()
{
IEnumerator he = null;
he = hostEvidenceList.GetEnumerator ();
IEnumerator ae = null;
if (assemblyEvidenceList != null)
- assemblyEvidenceList.GetEnumerator ();
+ ae = assemblyEvidenceList.GetEnumerator ();
return new EvidenceEnumerator (he, ae);
}
return AssemblyEvidenceList.GetEnumerator ();
}
-#if NET_2_0
- [ComVisible (false)]
- public override int GetHashCode ()
- {
- // kind of long so we cache it
- if (_hashCode == 0) {
- if (hostEvidenceList != null) {
- for (int i = 0; i < hostEvidenceList.Count; i++)
- _hashCode ^= hostEvidenceList [i].GetHashCode ();
- }
- if (assemblyEvidenceList != null) {
- for (int i = 0; i < assemblyEvidenceList.Count; i++)
- _hashCode ^= assemblyEvidenceList [i].GetHashCode ();
- }
- }
- return _hashCode;
- }
-#endif
-
public IEnumerator GetHostEnumerator ()
{
return HostEvidenceList.GetEnumerator ();
foreach (object o in evidence.assemblyEvidenceList)
AddAssembly (o);
}
- _hashCode = 0;
}
}
-#if NET_2_0
[ComVisible (false)]
public void RemoveType (Type t)
{
for (int i = hostEvidenceList.Count; i >= 0; i--) {
if (hostEvidenceList.GetType () == t) {
hostEvidenceList.RemoveAt (i);
- _hashCode = 0;
}
}
for (int i = assemblyEvidenceList.Count; i >= 0; i--) {
if (assemblyEvidenceList.GetType () == t) {
assemblyEvidenceList.RemoveAt (i);
- _hashCode = 0;
}
}
}
-#endif
// Use an icall to avoid multiple file i/o to detect the
// "possible" presence of an Authenticode signature
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern bool IsAuthenticodePresent (Assembly a);
-
+#if NET_2_1
+ static internal Evidence GetDefaultHostEvidence (Assembly a)
+ {
+ return new Evidence ();
+ }
+#else
// this avoid us to build all evidences from the runtime
// (i.e. multiple unmanaged->managed calls) and also allows
// to delay their creation until (if) needed
}
}
}
-#if NET_2_0
// assemblies loaded from the GAC also get a Gac evidence (new in Fx 2.0)
if (a.GlobalAssemblyCache) {
e.AddHost (new GacInstalled ());
e = dommgr.HostSecurityManager.ProvideAssemblyEvidence (a, e);
}
}
-#endif
+
return e;
}
-
+
+#endif // NET_2_1
+
private class EvidenceEnumerator : IEnumerator {
private IEnumerator currentEnum, hostEnum, assemblyEnum;