Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
2008-10-12 Sebastien Pouliot <sebastien@ximian.com>
* DataProtectionPermissionAttribute.cs, DataProtectionPermission.cs:
Remove unneeded field initialization to their default values.
[Found using Gendarme AvoidUnneededFieldInitializationRule]
2005-10-20 Sebastien Pouliot <sebastien@ximian.com>
* DataProtectionPermission.cs: Fixed Flags property to allow multiple
values.
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* Store*.cs: Moved in System.dll
2005-05-18 Jordi Mas i Hernandez <jordi@ximian.com>
* DataProtectionPermissionAttribute.cs: fixes flag cleaning logical operation
2005-01-05 Sebastien Pouliot <sebastien@ximian.com>
* DataProtectionPermission.cs: Removed IBuiltInPermission (it's not in
corlib so it's no more built-in). Updated to use PermissionHelper.
* PermissionHelper.cs: New. Common helpers for permissions classes.
2005-01-05 Sebastien Pouliot <sebastien@ximian.com>
* DataProtectionPermission.cs: Moved from corlib.
* DataProtectionPermissionAttribute.cs: Moved from corlib.
* DataProtectionPermissionFlags.cs: Moved from corlib.

View File

@@ -0,0 +1,153 @@
//
// System.Security.Permissions.DataProtectionPermission class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.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
// "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 DataProtectionPermission : CodeAccessPermission, IUnrestrictedPermission {
private const int version = 1;
private DataProtectionPermissionFlags _flags;
public DataProtectionPermission (PermissionState state)
{
if (PermissionHelper.CheckPermissionState (state, true) == PermissionState.Unrestricted)
_flags = DataProtectionPermissionFlags.AllFlags;
}
public DataProtectionPermission (DataProtectionPermissionFlags flags)
{
// reuse validation by the Flags property
Flags = flags;
}
public DataProtectionPermissionFlags Flags {
get { return _flags; }
set {
if ((value & ~DataProtectionPermissionFlags.AllFlags) != 0) {
string msg = String.Format (Locale.GetText ("Invalid enum {0}"), value);
throw new ArgumentException (msg, "DataProtectionPermissionFlags");
}
_flags = value;
}
}
public bool IsUnrestricted ()
{
return (_flags == DataProtectionPermissionFlags.AllFlags);
}
public override IPermission Copy ()
{
return new DataProtectionPermission (_flags);
}
public override IPermission Intersect (IPermission target)
{
DataProtectionPermission dp = Cast (target);
if (dp == null)
return null;
if (this.IsUnrestricted () && dp.IsUnrestricted ())
return new DataProtectionPermission (PermissionState.Unrestricted);
if (this.IsUnrestricted ())
return dp.Copy ();
if (dp.IsUnrestricted ())
return this.Copy ();
return new DataProtectionPermission (_flags & dp._flags);
}
public override IPermission Union (IPermission target)
{
DataProtectionPermission dp = Cast (target);
if (dp == null)
return this.Copy ();
if (this.IsUnrestricted () || dp.IsUnrestricted ())
return new SecurityPermission (PermissionState.Unrestricted);
return new DataProtectionPermission (_flags | dp._flags);
}
public override bool IsSubsetOf (IPermission target)
{
DataProtectionPermission dp = Cast (target);
if (dp == null)
return (_flags == DataProtectionPermissionFlags.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 = (DataProtectionPermissionFlags) Enum.Parse (
typeof (DataProtectionPermissionFlags), e.Attribute ("Flags"));
}
public override SecurityElement ToXml ()
{
SecurityElement e = PermissionHelper.Element (typeof (DataProtectionPermission), version);
e.AddAttribute ("Flags", _flags.ToString ());
return e;
}
// helpers
private DataProtectionPermission Cast (IPermission target)
{
if (target == null)
return null;
DataProtectionPermission dp = (target as DataProtectionPermission);
if (dp == null) {
PermissionHelper.ThrowInvalidPermission (target, typeof (DataProtectionPermission));
}
return dp;
}
}
}
#endif

View File

@@ -0,0 +1,122 @@
//
// System.Security.Permissions.DataProtectionPermissionAttribute class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 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 DataProtectionPermissionAttribute : CodeAccessSecurityAttribute {
private DataProtectionPermissionFlags _flags;
public DataProtectionPermissionAttribute (SecurityAction action)
: base (action)
{
}
public DataProtectionPermissionFlags Flags {
get { return _flags; }
set {
if ((value & DataProtectionPermissionFlags.AllFlags) != value) {
string msg = String.Format (Locale.GetText ("Invalid flags {0}"), value);
throw new ArgumentException (msg, "DataProtectionPermissionFlags");
}
_flags = value;
}
}
public bool ProtectData {
get { return ((_flags & DataProtectionPermissionFlags.ProtectData) != 0); }
set {
if (value) {
_flags |= DataProtectionPermissionFlags.ProtectData;
}
else {
_flags &= ~DataProtectionPermissionFlags.ProtectData;
}
}
}
public bool UnprotectData {
get { return ((_flags & DataProtectionPermissionFlags.UnprotectData) != 0); }
set {
if (value) {
_flags |= DataProtectionPermissionFlags.UnprotectData;
}
else {
_flags &= ~DataProtectionPermissionFlags.UnprotectData;
}
}
}
public bool ProtectMemory {
get { return ((_flags & DataProtectionPermissionFlags.ProtectMemory) != 0); }
set {
if (value) {
_flags |= DataProtectionPermissionFlags.ProtectMemory;
}
else {
_flags &= ~DataProtectionPermissionFlags.ProtectMemory;
}
}
}
public bool UnprotectMemory {
get { return ((_flags & DataProtectionPermissionFlags.UnprotectMemory) != 0); }
set {
if (value) {
_flags |= DataProtectionPermissionFlags.UnprotectMemory;
}
else {
_flags &= ~DataProtectionPermissionFlags.UnprotectMemory;
}
}
}
public override IPermission CreatePermission ()
{
DataProtectionPermission perm = null;
if (this.Unrestricted)
perm = new DataProtectionPermission (PermissionState.Unrestricted);
else
perm = new DataProtectionPermission (_flags);
return perm;
}
}
}
#endif

View File

@@ -0,0 +1,45 @@
//
// System.Security.Permissions.DataProtectionPermissionFlags flags
//
// Author
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 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
namespace System.Security.Permissions {
[Flags]
[Serializable]
public enum DataProtectionPermissionFlags {
NoFlags = 0,
ProtectData = 1,
UnprotectData = 2,
ProtectMemory = 4,
UnprotectMemory = 8,
AllFlags = ProtectData | UnprotectData | ProtectMemory | UnprotectMemory
}
}
#endif

View File

@@ -0,0 +1,111 @@
//
// System.Security.Permissions.PermissionHelper.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 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.
//
using System.Globalization;
namespace System.Security.Permissions {
internal sealed class PermissionHelper {
// snippet moved from FileIOPermission (nickd) to be reused in all derived classes
internal static SecurityElement Element (Type type, int version)
{
SecurityElement se = new SecurityElement ("IPermission");
se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\''));
se.AddAttribute ("version", version.ToString ());
return se;
}
internal static PermissionState CheckPermissionState (PermissionState state, bool allowUnrestricted)
{
string msg;
switch (state) {
case PermissionState.None:
break;
case PermissionState.Unrestricted:
if (!allowUnrestricted) {
msg = Locale.GetText ("Unrestricted isn't not allowed for identity permissions.");
throw new ArgumentException (msg, "state");
}
break;
default:
msg = String.Format (Locale.GetText ("Invalid enum {0}"), state);
throw new ArgumentException (msg, "state");
}
return state;
}
internal static int CheckSecurityElement (SecurityElement se, string parameterName, int minimumVersion, int maximumVersion)
{
if (se == null)
throw new ArgumentNullException (parameterName);
if (se.Attribute ("class") == null) {
string msg = Locale.GetText ("Missing 'class' attribute.");
throw new ArgumentException (msg, parameterName);
}
// we assume minimum version if no version number is supplied
int version = minimumVersion;
string v = se.Attribute ("version");
if (v != null) {
try {
version = Int32.Parse (v);
}
catch (Exception e) {
string msg = Locale.GetText ("Couldn't parse version from '{0}'.");
msg = String.Format (msg, v);
throw new ArgumentException (msg, parameterName, e);
}
}
if ((version < minimumVersion) || (version > maximumVersion)) {
string msg = Locale.GetText ("Unknown version '{0}', expected versions between ['{1}','{2}'].");
msg = String.Format (msg, version, minimumVersion, maximumVersion);
throw new ArgumentException (msg, parameterName);
}
return version;
}
// must be called after CheckSecurityElement (i.e. se != null)
internal static bool IsUnrestricted (SecurityElement se)
{
string value = se.Attribute ("Unrestricted");
if (value == null)
return false;
return (String.Compare (value, Boolean.TrueString, true, CultureInfo.InvariantCulture) == 0);
}
internal static void ThrowInvalidPermission (IPermission target, Type expected)
{
string msg = Locale.GetText ("Invalid permission type '{0}', expected type '{1}'.");
msg = String.Format (msg, target.GetType (), expected);
throw new ArgumentException (msg, "target");
}
}
}