mscorlib(4.0.0.0) API with additions
PermissionSetAttribute.cs
1 using System.IO;
4 using System.Security.Util;
5 using System.Text;
6 
8 {
10  [Serializable]
11  [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
12  [ComVisible(true)]
14  {
15  private string m_file;
16 
17  private string m_name;
18 
19  private bool m_unicode;
20 
21  private string m_xml;
22 
23  private string m_hex;
24 
27  public string File
28  {
29  get
30  {
31  return m_file;
32  }
33  set
34  {
35  m_file = value;
36  }
37  }
38 
42  public bool UnicodeEncoded
43  {
44  get
45  {
46  return m_unicode;
47  }
48  set
49  {
50  m_unicode = value;
51  }
52  }
53 
56  public string Name
57  {
58  get
59  {
60  return m_name;
61  }
62  set
63  {
64  m_name = value;
65  }
66  }
67 
70  public string XML
71  {
72  get
73  {
74  return m_xml;
75  }
76  set
77  {
78  m_xml = value;
79  }
80  }
81 
84  public string Hex
85  {
86  get
87  {
88  return m_hex;
89  }
90  set
91  {
92  m_hex = value;
93  }
94  }
95 
99  : base(action)
100  {
101  m_unicode = false;
102  }
103 
106  public override IPermission CreatePermission()
107  {
108  return null;
109  }
110 
111  private PermissionSet BruteForceParseStream(Stream stream)
112  {
113  Encoding[] array = new Encoding[3]
114  {
115  Encoding.UTF8,
116  Encoding.ASCII,
118  };
119  StreamReader streamReader = null;
120  Exception ex = null;
121  int num = 0;
122  while (streamReader == null && num < array.Length)
123  {
124  try
125  {
126  stream.Position = 0L;
127  streamReader = new StreamReader(stream, array[num]);
128  return ParsePermissionSet(new Parser(streamReader));
129  }
130  catch (Exception ex2)
131  {
132  if (ex == null)
133  {
134  ex = ex2;
135  }
136  }
137  num++;
138  }
139  throw ex;
140  }
141 
142  private PermissionSet ParsePermissionSet(Parser parser)
143  {
144  SecurityElement topElement = parser.GetTopElement();
145  PermissionSet permissionSet = new PermissionSet(PermissionState.None);
146  permissionSet.FromXml(topElement);
147  return permissionSet;
148  }
149 
152  [SecuritySafeCritical]
154  {
155  if (m_unrestricted)
156  {
157  return new PermissionSet(PermissionState.Unrestricted);
158  }
159  if (m_name != null)
160  {
161  return PolicyLevel.GetBuiltInSet(m_name);
162  }
163  if (m_xml != null)
164  {
165  return ParsePermissionSet(new Parser(m_xml.ToCharArray()));
166  }
167  if (m_hex != null)
168  {
169  return BruteForceParseStream(new MemoryStream(System.Security.Util.Hex.DecodeHexString(m_hex)));
170  }
171  if (m_file != null)
172  {
173  return BruteForceParseStream(new FileStream(m_file, FileMode.Open, FileAccess.Read));
174  }
175  return new PermissionSet(PermissionState.None);
176  }
177  }
178 }
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
PermissionSetAttribute(SecurityAction action)
Initializes a new instance of the T:System.Security.Permissions.PermissionSetAttribute class with the...
FileMode
Specifies how the operating system should open a file.
Definition: FileMode.cs:8
PermissionSet CreatePermissionSet()
Creates and returns a new permission set based on this permission set attribute object.
static Encoding Unicode
Gets an encoding for the UTF-16 format using the little endian byte order.
Definition: Encoding.cs:975
Represents the security policy levels for the common language runtime. This class cannot be inherited...
Definition: PolicyLevel.cs:15
Definition: __Canon.cs:3
Implements a T:System.IO.TextReader that reads characters from a byte stream in a particular encoding...
Definition: StreamReader.cs:13
string Name
Gets or sets the name of the permission set.
Allows security actions for a T:System.Security.PermissionSet to be applied to code using declarative...
static Encoding ASCII
Gets an encoding for the ASCII (7-bit) character set.
Definition: Encoding.cs:920
SecurityAction
Specifies the security actions that can be performed using declarative security.
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
Definition: MemoryStream.cs:13
Represents a collection that can contain many different types of permissions.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
Definition: FileStream.cs:15
override IPermission CreatePermission()
This method is not used.
Defines methods implemented by permission types.
Definition: IPermission.cs:7
AttributeTargets
Specifies the application elements on which it is valid to apply an attribute.
Specifies the base attribute class for code access security.
string Hex
Gets or sets the hexadecimal representation of the XML encoded permission set.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
FileAccess
Defines constants for read, write, or read/write access to a file.
Definition: FileAccess.cs:9
string XML
Gets or sets the XML representation of a permission set.
Specifies that the class can be serialized.
abstract long Position
When overridden in a derived class, gets or sets the position within the current stream.
Definition: Stream.cs:633
static Encoding UTF8
Gets an encoding for the UTF-8 format.
Definition: Encoding.cs:1023
bool UnicodeEncoded
Gets or sets a value indicating whether the file specified by P:System.Security.Permissions....
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Definition: File.cs:14
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Definition: Stream.cs:16