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