2004-08-18 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Wed, 18 Aug 2004 14:54:31 +0000 (14:54 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Wed, 18 Aug 2004 14:54:31 +0000 (14:54 -0000)
* IsolatedStorageContainment.cs: Added new enums values for NET_2_0.
* IsolatedStorageFilePermissionAttribute.cs: Removed unrequired using
clause.
* IsolatedStorageFilePermission.cs: Updated to use the common template.
Completed TODOs and now pass all unit tests.
* IsolatedStoragePermission.cs: Updated to use the common template.
Completed TODOs and now pass all unit tests.

svn path=/trunk/mcs/; revision=32490

mcs/class/corlib/System.Security.Permissions/ChangeLog
mcs/class/corlib/System.Security.Permissions/IsolatedStorageContainment.cs
mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermission.cs
mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermissionAttribute.cs
mcs/class/corlib/System.Security.Permissions/IsolatedStoragePermission.cs

index 353dfacd2042c1027cce89ecbc1b96144be28e3e..be0f63655df76862a6383afb26462c9484d4470d 100644 (file)
@@ -1,5 +1,12 @@
 2004-08-18  Sebastien Pouliot  <sebastien@ximian.com>
 
+       * IsolatedStorageContainment.cs: Added new enums values for NET_2_0.
+       * IsolatedStorageFilePermissionAttribute.cs: Removed unrequired using
+       clause.
+       * IsolatedStorageFilePermission.cs: Updated to use the common template.
+       Completed TODOs and now pass all unit tests.
+       * IsolatedStoragePermission.cs: Updated to use the common template.
+       Completed TODOs and now pass all unit tests.
        * GacIdentityPermission.cs: Update to use the common template. Now 
        pass all unit tests.
        * GacIdentityPermissionAttribute.cs: Added FIXME comment.
index de2e91f0d4e02c9b7453c7d32cc1d321e42b0913..e31bbe6dfc4e098b734781738f3ac437fecfd06d 100755 (executable)
@@ -1,3 +1,4 @@
+//
 // IsolatedStorageContainment.cs
 //
 // This code was automatically generated from
@@ -8,8 +9,6 @@
 // URL: http://devresource.hp.com/devresource/Docs/TechPapers/CSharp/all.xml
 //
 // (C) 2001 Ximian, Inc.  http://www.ximian.com
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -32,7 +31,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-
 namespace System.Security.Permissions {
 
        [Serializable]
@@ -45,6 +43,12 @@ namespace System.Security.Permissions {
                AssemblyIsolationByRoamingUser = 0x60,
                AdministerIsolatedStorageByUser = 0x70,
                UnrestrictedIsolatedStorage = 0xF0,
-       };
-
-} // System.Security.Permissions
+#if NET_2_0
+               ApplicationIsolationByUser = 0x25,
+               DomainIsolationByMachine = 0x30,
+               AssemblyIsolationByMachine = 0x40,
+               ApplicationIsolationByMachine = 0x45,
+               ApplicationIsolationByRoamingUser = 0x65,
+#endif
+       }
+}
index e7e59db6080d9b78a3796f49f4f5717e89cb345a..39bf4dca0e2fbd2f7560f2a4add700209888dbe4 100644 (file)
@@ -2,12 +2,9 @@
 // System.Security.Permissions.IsolatedStorageFilePermission.cs
 //
 // Author
-//     Sebastien Pouliot  <spouliot@motus.com>
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // Copyright (C) 2003 Motus Technologies. http://www.motus.com
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
-
 namespace System.Security.Permissions {
 
        [Serializable]
        public sealed class IsolatedStorageFilePermission : IsolatedStoragePermission, IBuiltInPermission {
 
+               private const int version = 1;
+
                // Constructors
 
-               public IsolatedStorageFilePermission (PermissionState state) : base (state) {}
+               [MonoTODO ("usage/quota calculated from evidences/policy")]
+               public IsolatedStorageFilePermission (PermissionState state) : base (state)
+               {
+                       if (!IsUnrestricted ()) {
+                               // TODO
+                       }
+               }
 
                // Properties
 
                // Methods
 
-               [MonoTODO]
                public override IPermission Copy () 
                {
                        IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
-                       // TODO add stuff into p
+                       p.m_userQuota = m_userQuota;
+                       p.m_machineQuota = m_machineQuota;
+                       p.m_expirationDays = m_expirationDays;
+                       p.m_permanentData = m_permanentData;
+                       p.m_allowed = m_allowed;
                        return p;
                }
 
-               [MonoTODO]
                public override IPermission Intersect (IPermission target) 
                {
-                       return null;
+                       IsolatedStorageFilePermission isfp = Cast (target);
+                       if (isfp == null)
+                               return null;
+                       if (IsEmpty () && isfp.IsEmpty ())
+                               return null;
+
+                       IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
+                       p.m_userQuota = (m_userQuota < isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota;
+                       p.m_machineQuota = (m_machineQuota < isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota;
+                       p.m_expirationDays = (m_expirationDays < isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays;
+                       p.m_permanentData = (m_permanentData && isfp.m_permanentData);
+                       // UsageAllowed == Unrestricted is a special case handled by the property
+                       p.UsageAllowed = (m_allowed < isfp.m_allowed) ? m_allowed : isfp.m_allowed;
+                       return p;
                }
 
-               [MonoTODO]
                public override bool IsSubsetOf (IPermission target) 
                {
-                       return false;
+                       IsolatedStorageFilePermission isfp = Cast (target);
+                       if (isfp == null)
+                               return IsEmpty ();
+                       if (isfp.IsUnrestricted ())
+                               return true;
+
+                       if (m_userQuota > isfp.m_userQuota)
+                               return false;
+                       if (m_machineQuota > isfp.m_machineQuota)
+                               return false;
+                       if (m_expirationDays > isfp.m_expirationDays)
+                               return false;
+                       if (m_permanentData != isfp.m_permanentData)
+                               return false;
+                       if (m_allowed > isfp.m_allowed)
+                               return false;
+                       return true;
+               }
+
+               public override IPermission Union (IPermission target)
+               {
+                       IsolatedStorageFilePermission isfp = Cast (target);
+                       if (isfp == null)
+                               return Copy ();
+
+                       IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
+                       p.m_userQuota = (m_userQuota > isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota;
+                       p.m_machineQuota = (m_machineQuota > isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota;
+                       p.m_expirationDays = (m_expirationDays > isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays;
+                       p.m_permanentData = (m_permanentData || isfp.m_permanentData);
+                       // UsageAllowed == Unrestricted is a special case handled by the property
+                       p.UsageAllowed = (m_allowed > isfp.m_allowed) ? m_allowed : isfp.m_allowed;
+                       return p;
                }
 
+#if NET_2_0
                [MonoTODO]
-               public override IPermission Union (IPermission target)
+               public override SecurityElement ToXml ()
                {
-                       return null;
+                       SecurityElement se = base.ToXml ();
+                       // TODO - something must have been added ???
+                       return se;
                }
+#endif
 
                // IBuiltInPermission
                int IBuiltInPermission.GetTokenIndex ()
                {
-                       return 3;
+                       return (int) BuiltInToken.IsolatedStorageFile;
+               }
+
+               // helpers
+
+               private IsolatedStorageFilePermission Cast (IPermission target)
+               {
+                       if (target == null)
+                               return null;
+
+                       IsolatedStorageFilePermission isfp = (target as IsolatedStorageFilePermission);
+                       if (isfp == null) {
+                               ThrowInvalidPermission (target, typeof (IsolatedStorageFilePermission));
+                       }
+
+                       return isfp;
                }
        }
-}
\ No newline at end of file
+}
index a84ea4af2f6ec434ae583dc661f293109ca24dc8..f1a6c25a371379a9c7efb87469598ec8e82d2fc6 100644 (file)
@@ -3,13 +3,10 @@
 //
 // Authors
 //     Duncan Mak <duncan@ximian.com>
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2002 Ximian, Inc.                       http://www.ximian.com
 // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -32,8 +29,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
-
 namespace System.Security.Permissions {
 
        [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class |
index 87c676873da78e9a9d3f1a6c01604ac2c9f03673..351dd12e06ec8329c972b5ffe54dcd0091e3e979 100644 (file)
@@ -1,12 +1,11 @@
 //
 // System.Security.Permissions.IsolatedStoragePermission.cs
 //
-// Piers Haken <piersh@friskit.com>
+// Authors:
+//     Piers Haken <piersh@friskit.com>
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2002 Ximian, Inc.                       http://www.ximian.com
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Globalization;
-using System.Security.Permissions;
 
-namespace System.Security.Permissions
-{
+namespace System.Security.Permissions {
+
        [Serializable]
-       public abstract class IsolatedStoragePermission : CodeAccessPermission, IUnrestrictedPermission
-       {
+       public abstract class IsolatedStoragePermission : CodeAccessPermission, IUnrestrictedPermission {
+
+               private const int version = 1;
+
                internal long m_userQuota;
                internal long m_machineQuota;
                internal long m_expirationDays;
@@ -46,39 +45,31 @@ namespace System.Security.Permissions
 
                public IsolatedStoragePermission (PermissionState state)
                {
-                       if (state == PermissionState.None)
-                       {
-                               m_userQuota = 0;
-                               m_machineQuota = 0;
-                               m_expirationDays = 0;
-                               m_permanentData = false;
-                               m_allowed = IsolatedStorageContainment.None;
-                       }
-                       else if (state == PermissionState.Unrestricted)
-                       {
-                               m_userQuota = Int64.MaxValue;
-                               m_machineQuota = Int64.MaxValue;
-                               m_expirationDays = Int64.MaxValue ;
-                               m_permanentData = true;
-                               m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
-                       }
-                       else
-                       {
-                               throw new ArgumentException("Invalid Permission state");
+                       if (CheckPermissionState (state, true) == PermissionState.Unrestricted) {
+                               UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
                        }
                }
 
-               public long UserQuota
-               {
-                       set { m_userQuota = value; }
+               public long UserQuota {
                        get { return m_userQuota; }
+                       set { m_userQuota = value; }
                }
 
-
-               public IsolatedStorageContainment UsageAllowed
-               {
-                       set { m_allowed = value; }
+               public IsolatedStorageContainment UsageAllowed {
                        get { return m_allowed; }
+                       set {
+                               if (!Enum.IsDefined (typeof (IsolatedStorageContainment), value)) {
+                                       string msg = String.Format (Locale.GetText ("Invalid enum {0}"), value);
+                                       throw new ArgumentException (msg, "IsolatedStorageContainment");
+                               }
+                               m_allowed = value;
+                               if (m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage) {
+                                       m_userQuota = Int64.MaxValue;
+                                       m_machineQuota = Int64.MaxValue;
+                                       m_expirationDays = Int64.MaxValue ;
+                                       m_permanentData = true;
+                               }
+                       }
                }
 
 
@@ -89,39 +80,47 @@ namespace System.Security.Permissions
 
                public override SecurityElement ToXml ()
                {
-                       SecurityElement e = new SecurityElement ("IPermission");
-                       e.AddAttribute ("class", GetType ().AssemblyQualifiedName);
-                       e.AddAttribute ("version", "1");
+                       SecurityElement se = Element (version);
 
                        if (m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage)
-                               e.AddAttribute ("Unrestricted", "true");
-
-                       else if (m_allowed == IsolatedStorageContainment.None)
-                               e.AddAttribute ("Allowed", "None");
+                               se.AddAttribute ("Unrestricted", "true");
+                       else
+                               se.AddAttribute ("Allowed", m_allowed.ToString ());
                        
-                       return e;
+                       return se;
                }
 
-
                public override void FromXml (SecurityElement esd)
                {
-                       if (esd == null)
-                               throw new ArgumentNullException (
-                                       Locale.GetText ("The argument is null."));
-                       
-                       if (esd.Attribute ("class") != GetType ().AssemblyQualifiedName)
-                               throw new ArgumentException (
-                                       Locale.GetText ("The argument is not valid"));
+                       // General validation in CodeAccessPermission
+                       CheckSecurityElement (esd, "esd", version, version);
+                       // Note: we do not (yet) care about the return value 
+                       // as we only accept version 1 (min/max values)
+
+                       m_userQuota = 0;
+                       m_machineQuota = 0;
+                       m_expirationDays = 0;
+                       m_permanentData = false;
+                       m_allowed = IsolatedStorageContainment.None;
+
+                       if (IsUnrestricted (esd)) {
+                               UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
+                       }
+                       else {
+                               string a = esd.Attribute ("Allowed");
+                               if (a != null) {
+                                       UsageAllowed = (IsolatedStorageContainment) Enum.Parse (
+                                               typeof (IsolatedStorageContainment), a);
+                               }
+                       }
+               }
 
-                       if (esd.Attribute ("version") != "1")
-                               throw new ArgumentException (
-                                       Locale.GetText ("The argument is not valid"));
-                       
-                       if (esd.Attribute ("Unrestricted") == "true")
-                               m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
+               // helpers
 
-                       else if (esd.Attribute ("Allowed") == "None")
-                               m_allowed = IsolatedStorageContainment.None;
+               internal bool IsEmpty ()
+               {
+                       // should we include internals ? or just publics ?
+                       return ((m_userQuota == 0) && (m_allowed == IsolatedStorageContainment.None));
                }
        }
 }