update MEF to preview 9
[mcs.git] / class / corlib / System.Security.Policy / PermissionRequestEvidence.cs
blob3c61240fc306809c6cb81f584787c3cd8b56365a
1 //
2 // System.Security.Policy.PermissionRequestEvidence.cs
3 //
4 // Authors:
5 // Nick Drochak (ndrochak@gol.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
7 //
8 // (C) 2003 Nick Drochak
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Runtime.InteropServices;
33 namespace System.Security.Policy {
35 [Serializable]
36 [ComVisible (true)]
37 public sealed class PermissionRequestEvidence : IBuiltInEvidence {
39 private PermissionSet requested, optional, denied;
41 public PermissionRequestEvidence (PermissionSet request, PermissionSet optional, PermissionSet denied)
43 if (request != null)
44 this.requested = new PermissionSet (request);
45 if (optional != null)
46 this.optional = new PermissionSet (optional);
47 if (denied != null)
48 this.denied = new PermissionSet (denied);
51 public PermissionSet DeniedPermissions {
52 get { return denied; }
55 public PermissionSet OptionalPermissions {
56 get { return optional; }
59 public PermissionSet RequestedPermissions {
60 get { return requested; }
63 public PermissionRequestEvidence Copy ()
65 return new PermissionRequestEvidence (requested, optional, denied);
68 public override string ToString ()
70 SecurityElement se = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence");
71 se.AddAttribute ("version", "1");
73 if (requested != null) {
74 SecurityElement requestElement = new SecurityElement ("Request");
75 requestElement.AddChild (requested.ToXml ());
76 se.AddChild (requestElement);
78 if (optional != null) {
79 SecurityElement optionalElement = new SecurityElement ("Optional");
80 optionalElement.AddChild (optional.ToXml ());
81 se.AddChild (optionalElement);
83 if (denied != null) {
84 SecurityElement deniedElement = new SecurityElement ("Denied");
85 deniedElement.AddChild (denied.ToXml ());
86 se.AddChild (deniedElement);
88 return se.ToString ();
91 // interface IBuiltInEvidence
93 int IBuiltInEvidence.GetRequiredSize (bool verbose)
95 int size = verbose ? 3 : 1;
96 if (requested != null) {
97 int r = requested.ToXml ().ToString ().Length + (verbose ? 5 : 0);
98 size += r;
100 if (optional != null) {
101 int o = optional.ToXml ().ToString ().Length + (verbose ? 5 : 0);
102 size += o;
104 if (denied != null) {
105 int d = denied.ToXml ().ToString ().Length + (verbose ? 5 : 0);
106 size += d;
108 return size;
111 [MonoTODO ("IBuiltInEvidence")]
112 int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position)
114 return 0;
117 [MonoTODO ("IBuiltInEvidence")]
118 int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose)
120 return 0;