//\r
// Authors:\r
// Nick Drochak (ndrochak@gol.com)\r
+// Sebastien Pouliot <sebastien@ximian.com>
//\r
// (C) 2003 Nick Drochak\r
-//\r
+// 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.
+//
+
+using System.Runtime.InteropServices;
\r
-using System.Text;\r
+namespace System.Security.Policy {
\r
-namespace System.Security.Policy\r
-{\r
[Serializable]\r
- public sealed class PermissionRequestEvidence {\r
- PermissionSet requested, optional, denied;\r
+#if NET_2_0
+ [ComVisible (true)]
+#endif
+ public sealed class PermissionRequestEvidence : IBuiltInEvidence {
+\r
+ private PermissionSet requested, optional, denied;\r
\r
- public PermissionRequestEvidence(PermissionSet requested, \r
- PermissionSet optional, PermissionSet denied) {\r
- this.requested = requested;\r
- this.optional = optional;\r
- this.denied = denied;\r
+ public PermissionRequestEvidence (PermissionSet requested, PermissionSet optional, PermissionSet denied)
+ {
+ if (requested != null)\r
+ this.requested = new PermissionSet (requested);
+ if (optional != null)\r
+ this.optional = new PermissionSet (optional);
+ if (denied != null)\r
+ this.denied = new PermissionSet (denied);\r
}\r
\r
public PermissionSet DeniedPermissions {\r
- get {return denied;}\r
+ get { return denied; }\r
}\r
\r
public PermissionSet OptionalPermissions {\r
- get {return optional;}\r
+ get { return optional; }\r
}\r
\r
public PermissionSet RequestedPermissions {\r
- get {return requested;}\r
+ get { return requested; }\r
}\r
\r
- public PermissionRequestEvidence Copy() {\r
+ public PermissionRequestEvidence Copy ()\r
+ {\r
return new PermissionRequestEvidence (requested, optional, denied);\r
}\r
\r
- public override string ToString() {\r
- // Cannot use XML classes in corlib, so do it by hand\r
- StringBuilder sb = new StringBuilder ();\r
-\r
- sb.Append ("<System.Security.Policy.PermissionRequestEvidence version=\"1\">");\r
- sb.Append ("<Request>");\r
- sb.Append ("<PermissionSet class=\"System.Security.PermissionSet\" version=\"1\"");\r
- if (requested.IsUnrestricted ())\r
- sb.Append (" Unrestricted=\"true\"");\r
- sb.Append (@"/>"); \r
- sb.Append (@"</Request>");\r
+ public override string ToString () \r
+ {\r
+ SecurityElement se = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence");\r
+ se.AddAttribute ("version", "1");\r
\r
- sb.Append ("<Optional>");\r
- sb.Append ("<PermissionSet class=\"System.Security.PermissionSet\" version=\"1\"");\r
- if (optional.IsUnrestricted ())\r
- sb.Append (" Unrestricted=\"true\"");\r
- sb.Append (@"/>"); \r
- sb.Append (@"</Optional>");\r
+ if (requested != null) {\r
+ SecurityElement requestElement = new SecurityElement ("Request");\r
+ requestElement.AddChild (requested.ToXml ());\r
+ se.AddChild (requestElement);\r
+ }\r
+ if (optional != null) {\r
+ SecurityElement optionalElement = new SecurityElement ("Optional");\r
+ optionalElement.AddChild (optional.ToXml ());\r
+ se.AddChild (optionalElement);\r
+ }\r
+ if (denied != null) {\r
+ SecurityElement deniedElement = new SecurityElement ("Denied");\r
+ deniedElement.AddChild (denied.ToXml ());\r
+ se.AddChild (deniedElement);\r
+ }\r
+ return se.ToString ();\r
+ }\r
\r
- sb.Append ("<Denied>");\r
- sb.Append ("<PermissionSet class=\"System.Security.PermissionSet\" version=\"1\"");\r
- if (denied.IsUnrestricted ())\r
- sb.Append (" Unrestricted=\"true\"");\r
- sb.Append (@"/>"); \r
- sb.Append (@"</Denied>");\r
+ // interface IBuiltInEvidence\r
\r
- sb.Append ("</System.Security.Policy.PermissionRequestEvidence>");\r
+ int IBuiltInEvidence.GetRequiredSize (bool verbose) \r
+ {
+ int size = verbose ? 3 : 1;
+ if (requested != null) {
+ int r = requested.ToXml ().ToString ().Length + (verbose ? 5 : 0);
+ size += r;
+ }\r
+ if (optional != null) {
+ int o = optional.ToXml ().ToString ().Length + (verbose ? 5 : 0);
+ size += o;
+ }\r
+ if (denied != null) {
+ int d = denied.ToXml ().ToString ().Length + (verbose ? 5 : 0);
+ size += d;
+ }\r
+ return size;\r
+ }\r
\r
- return sb.ToString ();\r
+ [MonoTODO ("IBuiltInEvidence")]\r
+ int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position) \r
+ {\r
+ return 0;\r
}\r
\r
+ [MonoTODO ("IBuiltInEvidence")]\r
+ int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose) \r
+ {\r
+ return 0;\r
+ }\r
}\r
-}
\ No newline at end of file
+}