Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2005-04-23 17:07:31 +0400
committerSebastien Pouliot <sebastien@ximian.com>2005-04-23 17:07:31 +0400
commit21ff62929023752314661aefb6af01c3538a52bf (patch)
tree5e3422e9c82337926cac642bc7f5c3b243fe82c1 /mcs/class/System.Security/System.Security.Permissions
parentf440852c728c50c0ad77ebd205dc238247db40de (diff)
2005-04-23 Sebastien Pouliot <sebastien@ximian.com>
* StorePermission.cs: New. CAS permission to access certificate stores. * StorePermissionAttribute.cs: New. CAS permission attribute for StorePermission. svn path=/trunk/mcs/; revision=43476
Diffstat (limited to 'mcs/class/System.Security/System.Security.Permissions')
-rw-r--r--mcs/class/System.Security/System.Security.Permissions/ChangeLog6
-rw-r--r--mcs/class/System.Security/System.Security.Permissions/StorePermission.cs155
-rw-r--r--mcs/class/System.Security/System.Security.Permissions/StorePermissionAttribute.cs159
3 files changed, 320 insertions, 0 deletions
diff --git a/mcs/class/System.Security/System.Security.Permissions/ChangeLog b/mcs/class/System.Security/System.Security.Permissions/ChangeLog
index fc9851f0ef3..8576bcd800b 100644
--- a/mcs/class/System.Security/System.Security.Permissions/ChangeLog
+++ b/mcs/class/System.Security/System.Security.Permissions/ChangeLog
@@ -1,3 +1,9 @@
+2005-04-23 Sebastien Pouliot <sebastien@ximian.com>
+
+ * StorePermission.cs: New. CAS permission to access certificate stores.
+ * StorePermissionAttribute.cs: New. CAS permission attribute for
+ StorePermission.
+
2005-01-05 Sebastien Pouliot <sebastien@ximian.com>
* DataProtectionPermission.cs: Removed IBuiltInPermission (it's not in
diff --git a/mcs/class/System.Security/System.Security.Permissions/StorePermission.cs b/mcs/class/System.Security/System.Security.Permissions/StorePermission.cs
new file mode 100644
index 00000000000..676606b3db2
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Permissions/StorePermission.cs
@@ -0,0 +1,155 @@
+//
+// System.Security.Permissions.StorePermission class
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 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
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.Globalization;
+
+namespace System.Security.Permissions {
+
+ [Serializable]
+ public sealed class StorePermission : CodeAccessPermission, IUnrestrictedPermission {
+
+ private const int version = 1;
+
+ private StorePermissionFlags _flags;
+
+
+ public StorePermission (PermissionState state)
+ {
+ if (PermissionHelper.CheckPermissionState (state, true) == PermissionState.Unrestricted)
+ _flags = StorePermissionFlags.AllFlags;
+ else
+ _flags = StorePermissionFlags.NoFlags;
+ }
+
+ public StorePermission (StorePermissionFlags flags)
+ {
+ // reuse validation by the Flags property
+ Flags = flags;
+ }
+
+
+ public StorePermissionFlags Flags {
+ get { return _flags; }
+ set {
+ if (!Enum.IsDefined (typeof (StorePermissionFlags), value)) {
+ string msg = String.Format (Locale.GetText ("Invalid enum {0}"), value);
+ throw new ArgumentException (msg, "StorePermissionFlags");
+ }
+ _flags = value;
+ }
+ }
+
+ public bool IsUnrestricted ()
+ {
+ return (_flags == StorePermissionFlags.AllFlags);
+ }
+
+ public override IPermission Copy ()
+ {
+ return new StorePermission (_flags);
+ }
+
+ public override IPermission Intersect (IPermission target)
+ {
+ StorePermission dp = Cast (target);
+ if (dp == null)
+ return null;
+
+ if (this.IsUnrestricted () && dp.IsUnrestricted ())
+ return new StorePermission (PermissionState.Unrestricted);
+ if (this.IsUnrestricted ())
+ return dp.Copy ();
+ if (dp.IsUnrestricted ())
+ return this.Copy ();
+ return new StorePermission (_flags & dp._flags);
+ }
+
+ public override IPermission Union (IPermission target)
+ {
+ StorePermission dp = Cast (target);
+ if (dp == null)
+ return this.Copy ();
+
+ if (this.IsUnrestricted () || dp.IsUnrestricted ())
+ return new SecurityPermission (PermissionState.Unrestricted);
+
+ return new StorePermission (_flags | dp._flags);
+ }
+
+ public override bool IsSubsetOf (IPermission target)
+ {
+ StorePermission dp = Cast (target);
+ if (dp == null)
+ return (_flags == StorePermissionFlags.NoFlags);
+
+ if (dp.IsUnrestricted ())
+ return true;
+ if (this.IsUnrestricted ())
+ return false;
+
+ return ((_flags & ~dp._flags) == 0);
+ }
+
+ public override void FromXml (SecurityElement e)
+ {
+ // General validation in CodeAccessPermission
+ PermissionHelper.CheckSecurityElement (e, "e", version, version);
+ // Note: we do not (yet) care about the return value
+ // as we only accept version 1 (min/max values)
+
+ _flags = (StorePermissionFlags) Enum.Parse (
+ typeof (StorePermissionFlags), e.Attribute ("Flags"));
+ }
+
+ public override SecurityElement ToXml ()
+ {
+ SecurityElement e = PermissionHelper.Element (typeof (StorePermission), version);
+ e.AddAttribute ("Flags", _flags.ToString ());
+ return e;
+ }
+
+ // helpers
+
+ private StorePermission Cast (IPermission target)
+ {
+ if (target == null)
+ return null;
+
+ StorePermission dp = (target as StorePermission);
+ if (dp == null) {
+ PermissionHelper.ThrowInvalidPermission (target, typeof (StorePermission));
+ }
+
+ return dp;
+ }
+ }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Permissions/StorePermissionAttribute.cs b/mcs/class/System.Security/System.Security.Permissions/StorePermissionAttribute.cs
new file mode 100644
index 00000000000..dc5945c2b99
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Permissions/StorePermissionAttribute.cs
@@ -0,0 +1,159 @@
+//
+// System.Security.Permissions.StorePermissionAttribute class
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 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
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.Globalization;
+
+namespace System.Security.Permissions {
+
+ [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class |
+ AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method,
+ AllowMultiple = true, Inherited = false)]
+ [Serializable]
+ public sealed class StorePermissionAttribute : CodeAccessSecurityAttribute {
+
+ private StorePermissionFlags _flags;
+
+ public StorePermissionAttribute (SecurityAction action)
+ : base (action)
+ {
+ _flags = StorePermissionFlags.NoFlags;
+ }
+
+
+ public StorePermissionFlags Flags {
+ get { return _flags; }
+ set {
+ if ((value & StorePermissionFlags.AllFlags) != value) {
+ string msg = String.Format (Locale.GetText ("Invalid flags {0}"), value);
+ throw new ArgumentException (msg, "StorePermissionFlags");
+ }
+
+ _flags = value;
+ }
+ }
+
+ public bool AddToStore {
+ get { return ((_flags & StorePermissionFlags.AddToStore) != 0); }
+ set {
+ if (value) {
+ _flags |= StorePermissionFlags.AddToStore;
+ }
+ else {
+ _flags &= StorePermissionFlags.AddToStore;
+ }
+ }
+ }
+
+ public bool CreateStore {
+ get { return ((_flags & StorePermissionFlags.CreateStore) != 0); }
+ set {
+ if (value) {
+ _flags |= StorePermissionFlags.CreateStore;
+ }
+ else {
+ _flags &= StorePermissionFlags.CreateStore;
+ }
+ }
+ }
+
+ public bool DeleteStore {
+ get { return ((_flags & StorePermissionFlags.DeleteStore) != 0); }
+ set {
+ if (value) {
+ _flags |= StorePermissionFlags.DeleteStore;
+ }
+ else {
+ _flags &= StorePermissionFlags.DeleteStore;
+ }
+ }
+ }
+
+ public bool EnumerateCertificates {
+ get { return ((_flags & StorePermissionFlags.EnumerateCertificates) != 0); }
+ set {
+ if (value) {
+ _flags |= StorePermissionFlags.EnumerateCertificates;
+ }
+ else {
+ _flags &= StorePermissionFlags.EnumerateCertificates;
+ }
+ }
+ }
+
+ public bool EnumerateStores {
+ get { return ((_flags & StorePermissionFlags.EnumerateStores) != 0); }
+ set {
+ if (value) {
+ _flags |= StorePermissionFlags.EnumerateStores;
+ }
+ else {
+ _flags &= StorePermissionFlags.EnumerateStores;
+ }
+ }
+ }
+
+ public bool OpenStore {
+ get { return ((_flags & StorePermissionFlags.OpenStore) != 0); }
+ set {
+ if (value) {
+ _flags |= StorePermissionFlags.OpenStore;
+ }
+ else {
+ _flags &= StorePermissionFlags.OpenStore;
+ }
+ }
+ }
+
+ public bool RemoveFromStore {
+ get { return ((_flags & StorePermissionFlags.RemoveFromStore) != 0); }
+ set {
+ if (value) {
+ _flags |= StorePermissionFlags.RemoveFromStore;
+ }
+ else {
+ _flags &= StorePermissionFlags.RemoveFromStore;
+ }
+ }
+ }
+
+
+ public override IPermission CreatePermission ()
+ {
+ StorePermission perm = null;
+ if (this.Unrestricted)
+ perm = new StorePermission (PermissionState.Unrestricted);
+ else
+ perm = new StorePermission (_flags);
+ return perm;
+ }
+ }
+}
+
+#endif