mscorlib(4.0.0.0) API with additions
RawAcl.cs
1 using System.Collections;
2 
4 {
6  public sealed class RawAcl : GenericAcl
7  {
8  private byte _revision;
9 
10  private ArrayList _aces;
11 
14  public override byte Revision => _revision;
15 
18  public override int Count => _aces.Count;
19 
22  public override int BinaryLength
23  {
24  get
25  {
26  int num = 8;
27  for (int i = 0; i < Count; i++)
28  {
29  GenericAce genericAce = _aces[i] as GenericAce;
30  num += genericAce.BinaryLength;
31  }
32  return num;
33  }
34  }
35 
39  public override GenericAce this[int index]
40  {
41  get
42  {
43  return _aces[index] as GenericAce;
44  }
45  set
46  {
47  if (value == null)
48  {
49  throw new ArgumentNullException("value");
50  }
51  if (value.BinaryLength % 4 != 0)
52  {
53  throw new SystemException();
54  }
55  int num = BinaryLength - ((index < _aces.Count) ? (_aces[index] as GenericAce).BinaryLength : 0) + value.BinaryLength;
56  if (num > GenericAcl.MaxBinaryLength)
57  {
58  throw new OverflowException(Environment.GetResourceString("AccessControl_AclTooLong"));
59  }
60  _aces[index] = value;
61  }
62  }
63 
64  private static void VerifyHeader(byte[] binaryForm, int offset, out byte revision, out int count, out int length)
65  {
66  if (binaryForm == null)
67  {
68  throw new ArgumentNullException("binaryForm");
69  }
70  if (offset < 0)
71  {
72  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
73  }
74  if (binaryForm.Length - offset >= 8)
75  {
76  revision = binaryForm[offset + 0];
77  length = binaryForm[offset + 2] + (binaryForm[offset + 3] << 8);
78  count = binaryForm[offset + 4] + (binaryForm[offset + 5] << 8);
79  if (length <= binaryForm.Length - offset)
80  {
81  return;
82  }
83  }
84  throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
85  }
86 
87  private void MarshalHeader(byte[] binaryForm, int offset)
88  {
89  if (binaryForm == null)
90  {
91  throw new ArgumentNullException("binaryForm");
92  }
93  if (offset < 0)
94  {
95  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
96  }
97  if (BinaryLength > GenericAcl.MaxBinaryLength)
98  {
99  throw new InvalidOperationException(Environment.GetResourceString("AccessControl_AclTooLong"));
100  }
101  if (binaryForm.Length - offset < BinaryLength)
102  {
103  throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
104  }
105  binaryForm[offset + 0] = Revision;
106  binaryForm[offset + 1] = 0;
107  binaryForm[offset + 2] = (byte)BinaryLength;
108  binaryForm[offset + 3] = (byte)(BinaryLength >> 8);
109  binaryForm[offset + 4] = (byte)Count;
110  binaryForm[offset + 5] = (byte)(Count >> 8);
111  binaryForm[offset + 6] = 0;
112  binaryForm[offset + 7] = 0;
113  }
114 
115  internal void SetBinaryForm(byte[] binaryForm, int offset)
116  {
117  VerifyHeader(binaryForm, offset, out _revision, out int count, out int length);
118  length += offset;
119  offset += 8;
120  _aces = new ArrayList(count);
121  int num = 8;
122  int num2 = 0;
123  while (true)
124  {
125  if (num2 < count)
126  {
127  GenericAce genericAce = GenericAce.CreateFromBinaryForm(binaryForm, offset);
128  int binaryLength = genericAce.BinaryLength;
129  if (num + binaryLength > GenericAcl.MaxBinaryLength)
130  {
131  throw new ArgumentException(Environment.GetResourceString("ArgumentException_InvalidAclBinaryForm"), "binaryForm");
132  }
133  _aces.Add(genericAce);
134  if (binaryLength % 4 != 0)
135  {
136  throw new SystemException();
137  }
138  num += binaryLength;
139  offset = ((_revision != GenericAcl.AclRevisionDS) ? (offset + binaryLength) : (offset + (binaryForm[offset + 2] + (binaryForm[offset + 3] << 8))));
140  if (offset > length)
141  {
142  break;
143  }
144  num2++;
145  continue;
146  }
147  return;
148  }
149  throw new ArgumentException(Environment.GetResourceString("ArgumentException_InvalidAclBinaryForm"), "binaryForm");
150  }
151 
155  public RawAcl(byte revision, int capacity)
156  {
157  _revision = revision;
158  _aces = new ArrayList(capacity);
159  }
160 
164  public RawAcl(byte[] binaryForm, int offset)
165  {
166  SetBinaryForm(binaryForm, offset);
167  }
168 
174  public override void GetBinaryForm(byte[] binaryForm, int offset)
175  {
176  MarshalHeader(binaryForm, offset);
177  offset += 8;
178  int num = 0;
179  while (true)
180  {
181  if (num < Count)
182  {
183  GenericAce genericAce = _aces[num] as GenericAce;
184  genericAce.GetBinaryForm(binaryForm, offset);
185  int binaryLength = genericAce.BinaryLength;
186  if (binaryLength % 4 != 0)
187  {
188  break;
189  }
190  offset += binaryLength;
191  num++;
192  continue;
193  }
194  return;
195  }
196  throw new SystemException();
197  }
198 
204  public void InsertAce(int index, GenericAce ace)
205  {
206  if (ace == null)
207  {
208  throw new ArgumentNullException("ace");
209  }
211  {
212  throw new OverflowException(Environment.GetResourceString("AccessControl_AclTooLong"));
213  }
214  _aces.Insert(index, ace);
215  }
216 
220  public void RemoveAce(int index)
221  {
222  GenericAce genericAce = _aces[index] as GenericAce;
223  _aces.RemoveAt(index);
224  }
225  }
226 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override void GetBinaryForm(byte[] binaryForm, int offset)
Marshals the contents of the T:System.Security.AccessControl.RawAcl object into the specified byte ar...
Definition: RawAcl.cs:174
static readonly int MaxBinaryLength
The maximum allowed binary length of a T:System.Security.AccessControl.GenericAcl object.
Definition: GenericAcl.cs:15
override int BinaryLength
Gets the length, in bytes, of the binary representation of the current T:System.Security....
Definition: RawAcl.cs:23
virtual void Insert(int index, object value)
Inserts an element into the T:System.Collections.ArrayList at the specified index.
Definition: ArrayList.cs:2698
Serves as the base class for system exceptions namespace.
virtual void RemoveAt(int index)
Removes the element at the specified index of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2847
RawAcl(byte revision, int capacity)
Initializes a new instance of the T:System.Security.AccessControl.RawAcl class with the specified rev...
Definition: RawAcl.cs:155
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
Represents an Access Control Entry (ACE), and is the base class for all other ACE classes.
Definition: GenericAce.cs:6
The exception that is thrown when an arithmetic, casting, or conversion operation in a checked contex...
Represents an Access Control List (ACL).
Definition: RawAcl.cs:6
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
void InsertAce(int index, GenericAce ace)
Inserts the specified Access Control Entry (ACE) at the specified index.
Definition: RawAcl.cs:204
RawAcl(byte[] binaryForm, int offset)
Initializes a new instance of the T:System.Security.AccessControl.RawAcl class from the specified bin...
Definition: RawAcl.cs:164
override int Count
Gets the number of access control entries (ACEs) in the current T:System.Security....
Definition: RawAcl.cs:18
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
override byte Revision
Gets the revision level of the T:System.Security.AccessControl.RawAcl.
Definition: RawAcl.cs:14
abstract void GetBinaryForm(byte[] binaryForm, int offset)
Marshals the contents of the T:System.Security.AccessControl.GenericAce object into the specified byt...
Represents an access control list (ACL) and is the base class for the T:System.Security....
Definition: GenericAcl.cs:6
void RemoveAce(int index)
Removes the Access Control Entry (ACE) at the specified location.
Definition: RawAcl.cs:220
abstract int BinaryLength
Gets the length, in bytes, of the binary representation of the current T:System.Security....
Definition: GenericAce.cs:99
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14