Merge pull request #1109 from adbre/iss358
[mono.git] / mcs / class / corlib / System.Security.Policy / PermissionRequestEvidence.cs
1 //\r
2 // System.Security.Policy.PermissionRequestEvidence.cs\r
3 //\r
4 // Authors:\r
5 //      Nick Drochak (ndrochak@gol.com)\r
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //\r
8 // (C) 2003 Nick Drochak\r
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 //
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.
29 //
30
31 using System.Runtime.InteropServices;
32 \r
33 namespace System.Security.Policy {
34 \r
35         [Serializable]\r
36         [ComVisible (true)]
37         public sealed class PermissionRequestEvidence :\r
38 #if NET_4_0\r
39                 EvidenceBase,\r
40 #endif\r
41                 IBuiltInEvidence {
42 \r
43                 private PermissionSet requested, optional, denied;\r
44 \r
45                 public PermissionRequestEvidence (PermissionSet request, PermissionSet optional, PermissionSet denied) 
46                 {
47                         if (request != null)\r
48                                 this.requested = new PermissionSet (request);
49                         if (optional != null)\r
50                                 this.optional = new PermissionSet (optional);
51                         if (denied != null)\r
52                                 this.denied = new PermissionSet (denied);\r
53                 }\r
54 \r
55                 public PermissionSet DeniedPermissions {\r
56                         get { return denied; }\r
57                 }\r
58 \r
59                 public PermissionSet OptionalPermissions {\r
60                         get { return optional; }\r
61                 }\r
62 \r
63                 public PermissionSet RequestedPermissions {\r
64                         get { return requested; }\r
65                 }\r
66 \r
67                 public PermissionRequestEvidence Copy ()\r
68                 {\r
69                         return new PermissionRequestEvidence (requested, optional, denied);\r
70                 }\r
71 \r
72                 public override string ToString () \r
73                 {\r
74                         SecurityElement se = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence");\r
75                         se.AddAttribute ("version", "1");\r
76 \r
77                         if (requested != null) {\r
78                                 SecurityElement requestElement = new SecurityElement ("Request");\r
79                                 requestElement.AddChild (requested.ToXml ());\r
80                                 se.AddChild (requestElement);\r
81                         }\r
82                         if (optional != null) {\r
83                                 SecurityElement optionalElement = new SecurityElement ("Optional");\r
84                                 optionalElement.AddChild (optional.ToXml ());\r
85                                 se.AddChild (optionalElement);\r
86                         }\r
87                         if (denied != null) {\r
88                                 SecurityElement deniedElement = new SecurityElement ("Denied");\r
89                                 deniedElement.AddChild (denied.ToXml ());\r
90                                 se.AddChild (deniedElement);\r
91                         }\r
92                         return se.ToString ();\r
93                 }\r
94 \r
95                 // interface IBuiltInEvidence\r
96 \r
97                 int IBuiltInEvidence.GetRequiredSize (bool verbose) \r
98                 {
99                         int size = verbose ? 3 : 1;
100                         if (requested != null) {
101                                 int r = requested.ToXml ().ToString ().Length + (verbose ? 5 : 0);
102                                 size += r;
103                         }\r
104                         if (optional != null) {
105                                 int o = optional.ToXml ().ToString ().Length + (verbose ? 5 : 0);
106                                 size += o;
107                         }\r
108                         if (denied != null) {
109                                 int d = denied.ToXml ().ToString ().Length + (verbose ? 5 : 0);
110                                 size += d;
111                         }\r
112                         return size;\r
113                 }\r
114 \r
115                 [MonoTODO ("IBuiltInEvidence")]\r
116                 int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position) \r
117                 {\r
118                         return 0;\r
119                 }\r
120 \r
121                 [MonoTODO ("IBuiltInEvidence")]\r
122                 int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose) \r
123                 {\r
124                         return 0;\r
125                 }\r
126         }\r
127 }