Merge pull request #408 from strawd/master
[mono.git] / mcs / class / corlib / System.Security.Permissions / StrongNameIdentityPermission.cs
index f8f31b3c99b7dc4de796a5c8370ba8e595d78ad2..7b1f4bd7bb593ae4e9189d1d067c0f1976551d8f 100644 (file)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2002, 2003 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
 
 using System.Collections;
 using System.Globalization;
+using System.Runtime.InteropServices;
 
 namespace System.Security.Permissions {
 
+       [ComVisible (true)]
        [Serializable]
        public sealed class StrongNameIdentityPermission : CodeAccessPermission, IBuiltInPermission {
        
@@ -87,7 +89,6 @@ namespace System.Security.Permissions {
                        }
                }
 
-#if NET_2_0
                private PermissionState _state;
                private ArrayList _list;
 
@@ -120,34 +121,9 @@ namespace System.Security.Permissions {
                                _list.Add (new SNIP (e.PublicKey, e.Name, e.AssemblyVersion));
                        }
                }
-#else
-               private SNIP _single;
-
-               public StrongNameIdentityPermission (PermissionState state) 
-               {
-                       // false == do not allow Unrestricted for Identity Permissions
-                       CheckPermissionState (state, false);
-                       // default values
-                       _single = SNIP.CreateDefault ();
-               }
-
-               public StrongNameIdentityPermission (StrongNamePublicKeyBlob blob, string name, Version version) 
-               {
-                       if (blob == null)
-                               throw new ArgumentNullException ("blob");
-
-                       _single = new SNIP (blob, name, version);
-               }
-
-               internal StrongNameIdentityPermission (StrongNameIdentityPermission snip) 
-                       : this (snip.PublicKey, snip.Name, snip.Version)
-               {
-               }
-#endif
 
                // Properties
 
-#if NET_2_0
                public string Name { 
                        get {
                                if (_list.Count > 1)
@@ -202,26 +178,6 @@ namespace System.Security.Permissions {
                        _list.Clear ();
                        _list.Add (SNIP.CreateDefault ());
                }
-#else
-               public string Name { 
-                       get { return _single.Name; }
-                       set { _single.Name = value; }
-               }
-
-               public StrongNamePublicKeyBlob PublicKey { 
-                       get { return _single.PublicKey; }
-                       set {
-                               if (value == null)
-                                       throw new ArgumentNullException ("value");
-                               _single.PublicKey = value;
-                       }
-               }
-       
-               public Version Version { 
-                       get { return _single.AssemblyVersion; }
-                       set { _single.AssemblyVersion = value; }
-               }
-#endif
 
                // Methods
        
@@ -239,7 +195,6 @@ namespace System.Security.Permissions {
                        CheckSecurityElement (e, "e", version, version);
                        // Note: we do not (yet) care about the return value 
                        // as we only accept version 1 (min/max values)
-#if NET_2_0
                        _list.Clear ();
                        if ((e.Children != null) && (e.Children.Count > 0)) {
                                foreach (SecurityElement se in e.Children) {
@@ -248,9 +203,6 @@ namespace System.Security.Permissions {
                        } else {
                                _list.Add (FromSecurityElement (e));
                        }
-#else
-                       _single = FromSecurityElement (e);
-#endif
                }
 
                private SNIP FromSecurityElement (SecurityElement se)
@@ -262,7 +214,6 @@ namespace System.Security.Permissions {
 
                        return new SNIP (publickey, name, assemblyVersion);
                }
-#if NET_2_0
                public override IPermission Intersect (IPermission target) 
                {
                        if (target == null)
@@ -305,42 +256,10 @@ namespace System.Security.Permissions {
                        }
                        return true;
                }
-#else
-               public override IPermission Intersect (IPermission target) 
-               {
-                       StrongNameIdentityPermission snip = (target as StrongNameIdentityPermission);
-                       if ((snip == null) || IsEmpty ())
-                               return null;
-                       if (snip.IsEmpty ())
-                               return new StrongNameIdentityPermission (PermissionState.None);
-                       if (!Match (snip.Name))
-                               return null;
-
-                       string n = ((Name.Length < snip.Name.Length) ? Name : snip.Name);
-                       if (!Version.Equals (snip.Version))
-                               return null;
-                       if (!PublicKey.Equals (snip.PublicKey))
-                               return null;
-
-                       return new StrongNameIdentityPermission (this.PublicKey, n, this.Version);
-               }
-
-               public override bool IsSubsetOf (IPermission target) 
-               {
-                       StrongNameIdentityPermission snip = Cast (target);
-                       if (snip == null)
-                               return IsEmpty ();
-                       if (IsEmpty ())
-                               return true;
-
-                       return _single.IsSubsetOf (snip._single);
-               }
-#endif
        
                public override SecurityElement ToXml () 
                {
                        SecurityElement se = Element (version);
-#if NET_2_0
                        if (_list.Count > 1) {
                                foreach (SNIP snip in _list) {
                                        SecurityElement child = new SecurityElement ("StrongName");
@@ -352,9 +271,6 @@ namespace System.Security.Permissions {
                                if (!IsEmpty (snip))
                                        ToSecurityElement (se, snip);
                        }
-#else
-                       ToSecurityElement (se, _single);
-#endif
                        return se;
                }
 
@@ -368,7 +284,6 @@ namespace System.Security.Permissions {
                                se.AddAttribute ("AssemblyVersion", snip.AssemblyVersion.ToString ());
                }
 
-#if NET_2_0
                public override IPermission Union (IPermission target) 
                {
                        StrongNameIdentityPermission snip = Cast (target);
@@ -386,42 +301,6 @@ namespace System.Security.Permissions {
                        }
                        return union;
                }
-#else
-               public override IPermission Union (IPermission target) 
-               {
-                       StrongNameIdentityPermission snip = Cast (target);
-                       if ((snip == null) || snip.IsEmpty ())
-                               return Copy ();
-
-                       if (IsEmpty ())
-                               return snip.Copy ();
-
-                       if (!PublicKey.Equals (snip.PublicKey)) {
-                               return null;
-                       }
-
-                       string n = Name;
-                       if ((n == null) || (n.Length == 0)) {
-                               n = snip.Name;
-                       }
-                       else if (Match (snip.Name)) {
-                               n = ((Name.Length > snip.Name.Length) ? Name : snip.Name);
-                       }
-                       else if ((snip.Name != null) && (snip.Name.Length > 0) && (n != snip.Name)) {
-                               return null;
-                       }
-
-                       Version v = Version;
-                       if (v == null) {
-                               v = snip.Version;
-                       }
-                       else if ((snip.Version != null) && (v != snip.Version)) {
-                               return null;
-                       }
-
-                       return new StrongNameIdentityPermission (PublicKey, n, v);
-               }
-#endif
        
                // IBuiltInPermission
                int IBuiltInPermission.GetTokenIndex ()
@@ -431,7 +310,6 @@ namespace System.Security.Permissions {
 
                // helpers
 
-#if NET_2_0
                private bool IsUnrestricted ()
                {
                        return (_state == PermissionState.Unrestricted);
@@ -461,13 +339,10 @@ namespace System.Security.Permissions {
                        return ((Version == null) || defaultVersion.Equals (Version));
                }
 
-#endif
                private bool IsEmpty ()
                {
-#if NET_2_0
                        if (IsUnrestricted () || (_list.Count > 1))
                                return false;
-#endif
                        if (PublicKey != null)
                                return false;
                        if ((Name != null) && (Name.Length > 0))