Fix null sessions in HttpContextWrapper.Session
[mono.git] / mcs / class / corlib / System.Security.Policy / Hash.cs
index 57943a24044e9fbf3d021b20770bb80cf0c73d88..b135cca778d547cdda0cc65bf86a59ff2ba072fe 100644 (file)
@@ -7,7 +7,7 @@
 //
 // (C) 2002 Jackson Harper, All rights reserved.
 // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#if !MOONLIGHT
+
 using System.IO;
-using System.Text;
 using System.Reflection;
+using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
 using System.Security.Cryptography;
+using System.Security.Permissions;
+using System.Text;
 
 namespace System.Security.Policy {
 
-#if !NET_2_0
-[MonoTODO("This doesn't match the MS version perfectly.")]
-// but it does seems to works exactly like Fx 2.0 beta 1 !?!?!
-#endif
-
 [Serializable]
-public sealed class Hash : ISerializable, IBuiltInEvidence {
+[ComVisible (true)]
+public sealed class Hash :
+#if NET_4_0
+               EvidenceBase,
+#endif
+               ISerializable, IBuiltInEvidence {
 
        private Assembly assembly;
        private byte[] data;
@@ -80,12 +84,10 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
                        // Case 2: we don't have a MD5 value precalculated so we either
                        // (a): have an assembly reference - and can calculate the hash; or
                        // (b): have been initialized with a static MD5 value (FX 2.0)
-#if NET_2_0
                        if ((assembly == null) && (_sha1 != null)) {
                                string msg = Locale.GetText ("No assembly data. This instance was initialized with an MSHA1 digest value.");
                                throw new SecurityException (msg);
                        }
-#endif
                        // fully named to avoid conflit between MD5 property and class name
                        HashAlgorithm hash = System.Security.Cryptography.MD5.Create ();
                        _md5 = GenerateHash (hash);
@@ -102,12 +104,10 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
                        // Case 2: we don't have a SHA1 value precalculated so we either
                        // (a): have an assembly reference - and can calculate the hash; or
                        // (b): have been initialized with a static MD5 value (FX 2.0)
-#if NET_2_0
                        if ((assembly == null) && (_md5 != null)) {
                                string msg = Locale.GetText ("No assembly data. This instance was initialized with an MD5 digest value.");
                                throw new SecurityException (msg);
                        }
-#endif
                        // fully named to avoid conflit between SHA1 property and class name
                        HashAlgorithm hash = System.Security.Cryptography.SHA1.Create ();
                        _sha1 = GenerateHash (hash);
@@ -151,8 +151,14 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
        // Private Methods
        //
 
+       // FIXME: be more restrictive when imperative security is implemented
+       [FileIOPermission (SecurityAction.Assert, Unrestricted = true)]
        private byte[] GetData () 
        {
+               if ((assembly == null) && (data == null)) {
+                       string msg = Locale.GetText ("No assembly data.");
+                       throw new SecurityException (msg);
+               }
                if (null == data) {
                        // TODO (Pre-Fx-2.0) we mustn't hash the complete assembly!
                        // ---- Look at ToString (MS version) for what to hash (and what not to)
@@ -173,19 +179,18 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
                return (verbose ? 5 : 0);       // as documented
        }
 
-       [MonoTODO]
+       [MonoTODO ("IBuiltInEvidence")]
        int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position) 
        {
                return 0;
        }
 
-       [MonoTODO]
+       [MonoTODO ("IBuiltInEvidence")]
        int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose) 
        {
                return 0;
        }
 
-#if NET_2_0
        static public Hash CreateMD5 (byte[] md5)
        {
                if (md5 == null)
@@ -203,7 +208,9 @@ public sealed class Hash : ISerializable, IBuiltInEvidence {
                h._sha1 = sha1;
                return h;
        }
-#endif
 }
 
 }
+
+#endif
+