24d1a6e9f55336d7a77b8407af747f06645397e2
[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 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 \r
31 namespace System.Security.Policy {
32 \r
33         [Serializable]\r
34         public sealed class PermissionRequestEvidence : IBuiltInEvidence {
35 \r
36                 private PermissionSet requested, optional, denied;\r
37 \r
38                 public PermissionRequestEvidence (PermissionSet requested, PermissionSet optional, PermissionSet denied) 
39                 {
40                         if (requested != null)\r
41                                 this.requested = new PermissionSet (requested);
42                         if (optional != null)\r
43                                 this.optional = new PermissionSet (optional);
44                         if (denied != null)\r
45                                 this.denied = new PermissionSet (denied);\r
46                 }\r
47 \r
48                 public PermissionSet DeniedPermissions {\r
49                         get { return denied; }\r
50                 }\r
51 \r
52                 public PermissionSet OptionalPermissions {\r
53                         get { return optional; }\r
54                 }\r
55 \r
56                 public PermissionSet RequestedPermissions {\r
57                         get { return requested; }\r
58                 }\r
59 \r
60                 public PermissionRequestEvidence Copy ()\r
61                 {\r
62                         return new PermissionRequestEvidence (requested, optional, denied);\r
63                 }\r
64 \r
65                 public override string ToString () \r
66                 {\r
67                         SecurityElement se = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence");\r
68                         se.AddAttribute ("version", "1");\r
69 \r
70                         if (requested != null) {\r
71                                 SecurityElement requestElement = new SecurityElement ("Request");\r
72                                 requestElement.AddChild (requested.ToXml ());\r
73                                 se.AddChild (requestElement);\r
74                         }\r
75                         if (optional != null) {\r
76                                 SecurityElement optionalElement = new SecurityElement ("Optional");\r
77                                 optionalElement.AddChild (optional.ToXml ());\r
78                                 se.AddChild (optionalElement);\r
79                         }\r
80                         if (denied != null) {\r
81                                 SecurityElement deniedElement = new SecurityElement ("Denied");\r
82                                 deniedElement.AddChild (denied.ToXml ());\r
83                                 se.AddChild (deniedElement);\r
84                         }\r
85                         return se.ToString ();\r
86                 }\r
87 \r
88                 // interface IBuiltInEvidence\r
89 \r
90                 [MonoTODO]\r
91                 int IBuiltInEvidence.GetRequiredSize (bool verbose) \r
92                 {
93                         int size = verbose ? 3 : 1;
94                         if (requested != null) {
95                                 int r = requested.ToXml ().ToString ().Length + (verbose ? 5 : 0);
96                                 size += r;
97                         }\r
98                         if (optional != null) {
99                                 int o = optional.ToXml ().ToString ().Length + (verbose ? 5 : 0);
100                                 size += o;
101                         }\r
102                         if (denied != null) {
103                                 int d = denied.ToXml ().ToString ().Length + (verbose ? 5 : 0);
104                                 size += d;
105                         }\r
106                         return size;\r
107                 }\r
108 \r
109                 [MonoTODO]\r
110                 int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position) \r
111                 {\r
112                         return 0;\r
113                 }\r
114 \r
115                 [MonoTODO]\r
116                 int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose) \r
117                 {\r
118                         return 0;\r
119                 }\r
120         }\r
121 }