X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Security.Policy%2FEvidence.cs;h=f8653aad20aa9dbc99d80f3d206c214bd6f889f3;hb=98740abe892f5699cfae720f96a258286d46d9cd;hp=0fb40c23457e4634adf4711de11750fd88c20946;hpb=c4a3b30460c7ea1a1fb3c97cfc8478555714af2f;p=mono.git diff --git a/mcs/class/corlib/System.Security.Policy/Evidence.cs b/mcs/class/corlib/System.Security.Policy/Evidence.cs index 0fb40c23457..f8653aad20a 100644 --- a/mcs/class/corlib/System.Security.Policy/Evidence.cs +++ b/mcs/class/corlib/System.Security.Policy/Evidence.cs @@ -38,22 +38,18 @@ using System.Runtime.CompilerServices; 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 () { @@ -65,6 +61,7 @@ namespace System.Security.Policy { Merge (evidence); } + [Obsolete] public Evidence (object[] hostEvidence, object[] assemblyEvidence) { if (null != hostEvidence) @@ -77,6 +74,7 @@ namespace System.Security.Policy { // Public Properties // + [Obsolete] public int Count { get { int count = 0; @@ -93,12 +91,7 @@ namespace System.Security.Policy { } public bool IsSynchronized { -#if NET_2_0 get { return false; } -#else - // LAMESPEC: Always TRUE (not FALSE) - get { return true; } -#endif } public bool Locked { @@ -133,22 +126,21 @@ namespace System.Security.Policy { // 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 () { @@ -156,10 +148,15 @@ namespace System.Security.Policy { 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; @@ -172,48 +169,8 @@ namespace System.Security.Policy { 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; @@ -221,7 +178,7 @@ namespace System.Security.Policy { he = hostEvidenceList.GetEnumerator (); IEnumerator ae = null; if (assemblyEvidenceList != null) - assemblyEvidenceList.GetEnumerator (); + ae = assemblyEvidenceList.GetEnumerator (); return new EvidenceEnumerator (he, ae); } @@ -230,25 +187,6 @@ namespace System.Security.Policy { 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 (); @@ -265,34 +203,34 @@ namespace System.Security.Policy { 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 @@ -332,7 +270,6 @@ namespace System.Security.Policy { } } } -#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 ()); @@ -346,10 +283,12 @@ namespace System.Security.Policy { e = dommgr.HostSecurityManager.ProvideAssemblyEvidence (a, e); } } -#endif + return e; } - + +#endif // NET_2_1 + private class EvidenceEnumerator : IEnumerator { private IEnumerator currentEnum, hostEnum, assemblyEnum;