2 // System.Security.PermissionSet.cs
5 // Nick Drochak(ndrochak@gol.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
9 // Portions (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.com)
10 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Diagnostics;
35 using System.Reflection;
36 using System.Runtime.InteropServices;
37 using System.Runtime.Serialization;
38 using System.Runtime.Serialization.Formatters.Binary;
39 using System.Security.Permissions;
40 using System.Security.Policy;
42 using System.Threading;
44 namespace System.Security {
47 // Microsoft public key - i.e. only MS signed assembly can inherit from PermissionSet (1.x) or (2.0) FullTrust assemblies
48 [StrongNameIdentityPermission (SecurityAction.InheritanceDemand, PublicKey="002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")]
52 public class PermissionSet: ISecurityEncodable, ICollection, IEnumerable, IStackWalk, IDeserializationCallback {
54 private const string tagName = "PermissionSet";
55 private const int version = 1;
56 private static object[] psUnrestricted = new object [1] { PermissionState.Unrestricted };
58 private PermissionState state;
59 private ArrayList list;
60 private int _hashcode;
61 private PolicyLevel _policyLevel;
62 private bool _declsec;
63 private bool _readOnly;
64 private bool[] _ignored; // for asserts and non-CAS permissions
68 // for PolicyLevel (to avoid validation duplication)
69 internal PermissionSet ()
71 list = new ArrayList ();
74 public PermissionSet (PermissionState state) : this ()
76 this.state = CodeAccessPermission.CheckPermissionState (state, true);
79 public PermissionSet (PermissionSet permSet) : this ()
81 // LAMESPEC: This would be handled by the compiler. No way permSet is not a PermissionSet.
82 //if (!(permSet is PermissionSet))
83 // throw new System.ArgumentException(); // permSet is not an instance of System.Security.PermissionSet.
84 if (permSet != null) {
85 state = permSet.state;
86 foreach (IPermission p in permSet.list)
91 state = PermissionState.Unrestricted;
96 internal PermissionSet (string xml)
99 state = PermissionState.None;
101 SecurityElement se = SecurityElement.FromString (xml);
106 // Light version for creating a (non unrestricted) PermissionSet with
107 // a single permission. This allows to relax most validations.
108 internal PermissionSet (IPermission perm)
112 // note: we do not copy IPermission like AddPermission
120 public IPermission AddPermission (IPermission perm)
122 public virtual IPermission AddPermission (IPermission perm)
125 if ((perm == null) || _readOnly)
128 // we don't add to an unrestricted permission set unless...
129 if (state == PermissionState.Unrestricted) {
131 // identity permissions can be unrestricted under 2.x
134 // we're adding identity permission as they don't support unrestricted
135 if (perm is IUnrestrictedPermission) {
137 // we return the union of the permission with unrestricted
138 // which results in a permission of the same type initialized
139 // with PermissionState.Unrestricted
140 return (IPermission) Activator.CreateInstance (perm.GetType (), psUnrestricted);
144 // we can't add two permissions of the same type in a set
145 // so we remove an existing one, union with it and add it back
146 IPermission existing = RemovePermission (perm.GetType ());
147 if (existing != null) {
148 perm = perm.Union (existing);
151 // note: Add doesn't copy
156 [MonoTODO ("Imperative mode isn't supported")]
157 [SecurityPermission (SecurityAction.Demand, Assertion = true)]
159 public void Assert ()
161 public virtual void Assert ()
164 int count = this.Count;
166 // we (current frame) must have the permission to assert it to others
167 // otherwise we don't assert (but we don't throw an exception)
168 foreach (IPermission p in list) {
169 // note: we ignore non-CAS permissions
170 if (p is IStackWalk) {
171 if (!SecurityManager.IsGranted (p)) {
178 // note: we must ignore the stack modifiers for the non-CAS permissions
179 if (SecurityManager.SecurityEnabled && (count > 0))
180 throw new NotSupportedException ("Currently only declarative Assert are supported.");
183 internal void Clear ()
188 public virtual PermissionSet Copy ()
190 return new PermissionSet (this);
193 public virtual void CopyTo (Array array, int index)
196 throw new ArgumentNullException ("array");
198 if (list.Count > 0) {
199 if (array.Rank > 1) {
200 throw new ArgumentException (Locale.GetText (
201 "Array has more than one dimension"));
203 if (index < 0 || index >= array.Length) {
204 throw new IndexOutOfRangeException ("index");
207 list.CopyTo (array, index);
212 public void Demand ()
214 public virtual void Demand ()
217 // Note: SecurityEnabled only applies to CAS permissions
218 // so we're not checking for it (yet)
223 if ((_ignored == null) || (_ignored.Length != n)) {
224 _ignored = new bool [n];
227 bool call_cas_only = this.IsUnrestricted ();
228 // non CAS permissions (e.g. PrincipalPermission) do not requires a stack walk
229 for (int i = 0; i < n; i++) {
230 CodeAccessPermission p = (CodeAccessPermission) list [i];
231 Type t = p.GetType ();
232 if (t.IsSubclassOf (typeof (CodeAccessPermission))) {
233 _ignored [i] = false;
234 call_cas_only = true;
241 // don't start the stack walk if
242 // - the permission set only contains non CAS permissions; or
243 // - security isn't enabled (applis only to CAS!)
244 if (call_cas_only && SecurityManager.SecurityEnabled)
245 CasOnlyDemand (_declsec ? 5 : 3);
248 // The number of frames to skip depends on who's calling
249 // - CodeAccessPermission.Demand (imperative)
250 // - PermissionSet.Demand (imperative)
251 // - SecurityManager.InternalDemand (declarative)
252 internal void CasOnlyDemand (int skip)
254 Assembly current = null;
255 AppDomain domain = null;
257 if (_ignored == null) {
258 // special case when directly called from CodeAccessPermission.Demand
259 _ignored = new bool [list.Count];
262 ArrayList frames = SecurityFrame.GetStack (skip);
263 if ((frames != null) && (frames.Count > 0)) {
264 SecurityFrame first = ((SecurityFrame) frames [0]);
265 current = first.Assembly;
266 domain = first.Domain;
267 // skip ourself, Demand and other security runtime methods
268 foreach (SecurityFrame sf in frames) {
269 if (ProcessFrame (sf, ref current, ref domain)) {
271 return; // reached Assert
274 SecurityFrame last = ((SecurityFrame) frames [frames.Count - 1]);
275 CheckAssembly (current, last);
276 CheckAppDomain (domain, last);
279 // Is there a CompressedStack to handle ?
280 CompressedStack stack = Thread.CurrentThread.GetCompressedStack ();
281 if ((stack != null) && !stack.IsEmpty ()) {
282 foreach (SecurityFrame frame in stack.List) {
283 if (ProcessFrame (frame, ref current, ref domain)) {
285 return; // reached Assert
291 [MonoTODO ("Imperative mode isn't supported")]
295 public virtual void Deny ()
298 if (!SecurityManager.SecurityEnabled)
301 foreach (IPermission p in list) {
302 // note: we ignore non-CAS permissions
303 if (p is IStackWalk) {
304 throw new NotSupportedException ("Currently only declarative Deny are supported.");
309 public virtual void FromXml (SecurityElement et)
312 throw new ArgumentNullException ("et");
313 if (et.Tag != tagName) {
314 string msg = String.Format ("Invalid tag {0} expected {1}", et.Tag, tagName);
315 throw new ArgumentException (msg, "et");
320 if (CodeAccessPermission.IsUnrestricted (et)) {
321 state = PermissionState.Unrestricted;
323 // no need to continue for an unrestricted permission
324 // because identity permissions now "supports" unrestricted
328 state = PermissionState.None;
331 if (et.Children != null) {
332 foreach (SecurityElement se in et.Children) {
333 string className = se.Attribute ("class");
334 if (className == null) {
335 throw new ArgumentException (Locale.GetText (
336 "No permission class is specified."));
338 if (Resolver != null) {
339 // policy class names do not have to be fully qualified
340 className = Resolver.ResolveClassName (className);
343 list.Add (PermissionBuilder.Create (className, se));
349 public IEnumerator GetEnumerator ()
351 public virtual IEnumerator GetEnumerator ()
354 return list.GetEnumerator ();
357 public virtual bool IsSubsetOf (PermissionSet target)
360 // if target is empty we must be empty too
361 if ((target == null) || (target.IsEmpty ()))
362 return this.IsEmpty ();
364 // all permissions support unrestricted in 2.0
365 if (target.IsUnrestricted ())
367 if (this.IsUnrestricted ())
370 if (this.IsUnrestricted () && ((target == null) || !target.IsUnrestricted ()))
373 // if each of our permission is (a) present and (b) a subset of target
374 foreach (IPermission p in list) {
376 if (target == null) {
377 if (!p.IsSubsetOf (null))
382 // non CAS permissions must be evaluated for unrestricted
383 Type t = p.GetType ();
384 IPermission i = null;
385 if (target.IsUnrestricted () && (p is CodeAccessPermission) && (p is IUnrestrictedPermission)) {
386 i = (IPermission) Activator.CreateInstance (t, psUnrestricted);
388 i = target.GetPermission (t);
391 if (!p.IsSubsetOf (i))
392 return false; // not a subset (condition b)
398 [MonoTODO ("Imperative mode isn't supported")]
400 public void PermitOnly ()
402 public virtual void PermitOnly ()
405 if (!SecurityManager.SecurityEnabled)
408 foreach (IPermission p in list) {
409 // note: we ignore non-CAS permissions
410 if (p is IStackWalk) {
411 throw new NotSupportedException ("Currently only declarative Deny are supported.");
416 public bool ContainsNonCodeAccessPermissions ()
418 if (list.Count > 0) {
419 foreach (IPermission p in list) {
420 if (! p.GetType ().IsSubclassOf (typeof (CodeAccessPermission)))
427 [MonoTODO ("little documentation in Fx 2.0 beta 1")]
428 public static byte[] ConvertPermissionSet (string inFormat, byte[] inData, string outFormat)
430 if (inFormat == null)
431 throw new ArgumentNullException ("inFormat");
432 if (outFormat == null)
433 throw new ArgumentNullException ("outFormat");
437 if (inFormat == outFormat)
440 PermissionSet ps = null;
442 if (inFormat == "BINARY") {
443 if (outFormat.StartsWith ("XML")) {
444 using (MemoryStream ms = new MemoryStream (inData)) {
445 BinaryFormatter formatter = new BinaryFormatter ();
446 ps = (PermissionSet) formatter.Deserialize (ms);
449 string xml = ps.ToString ();
453 return Encoding.ASCII.GetBytes (xml);
455 return Encoding.Unicode.GetBytes (xml);
459 else if (inFormat.StartsWith ("XML")) {
460 if (outFormat == "BINARY") {
465 xml = Encoding.ASCII.GetString (inData);
468 xml = Encoding.Unicode.GetString (inData);
472 ps = new PermissionSet (PermissionState.None);
473 ps.FromXml (SecurityElement.FromString (xml));
475 MemoryStream ms = new MemoryStream ();
476 BinaryFormatter formatter = new BinaryFormatter ();
477 formatter.Serialize (ms, ps);
479 return ms.ToArray ();
482 else if (outFormat.StartsWith ("XML")) {
483 string msg = String.Format (Locale.GetText ("Can't convert from {0} to {1}"), inFormat, outFormat);
485 throw new XmlSyntaxException (msg);
487 throw new ArgumentException (msg);
492 // unknown inFormat, returns null
495 // unknown outFormat, throw
496 throw new SerializationException (String.Format (Locale.GetText ("Unknown output format {0}."), outFormat));
500 public IPermission GetPermission (Type permClass)
502 public virtual IPermission GetPermission (Type permClass)
505 if ((permClass == null) || (list.Count == 0))
508 foreach (object o in list) {
509 if ((o != null) && o.GetType ().Equals (permClass))
510 return (IPermission) o;
512 // it's normal to return null for unrestricted sets
517 public PermissionSet Intersect (PermissionSet other)
519 public virtual PermissionSet Intersect (PermissionSet other)
522 // no intersection possible
523 if ((other == null) || (other.IsEmpty ()) || (this.IsEmpty ()))
526 PermissionState state = PermissionState.None;
527 if (this.IsUnrestricted () && other.IsUnrestricted ())
528 state = PermissionState.Unrestricted;
530 PermissionSet interSet = null;
532 // much simpler with 2.0
533 if (state == PermissionState.Unrestricted) {
534 interSet = new PermissionSet (state);
535 } else if (this.IsUnrestricted ()) {
536 interSet = other.Copy ();
537 } else if (other.IsUnrestricted ()) {
538 interSet = this.Copy ();
540 interSet = new PermissionSet (state);
541 InternalIntersect (interSet, this, other, false);
544 interSet = new PermissionSet (state);
545 if (state == PermissionState.Unrestricted) {
546 InternalIntersect (interSet, this, other, true);
547 InternalIntersect (interSet, other, this, true);
548 } else if (this.IsUnrestricted ()) {
549 InternalIntersect (interSet, this, other, true);
550 } else if (other.IsUnrestricted ()) {
551 InternalIntersect (interSet, other, this, true);
553 InternalIntersect (interSet, this, other, false);
559 internal void InternalIntersect (PermissionSet intersect, PermissionSet a, PermissionSet b, bool unrestricted)
561 foreach (IPermission p in b.list) {
562 // for every type in both list
563 IPermission i = a.GetPermission (p.GetType ());
565 // add intersection for this type
566 intersect.AddPermission (p.Intersect (i));
569 // unrestricted is possible for indentity permissions
570 else if (unrestricted) {
572 else if (unrestricted && (p is IUnrestrictedPermission)) {
574 intersect.AddPermission (p);
581 public bool IsEmpty ()
583 public virtual bool IsEmpty ()
586 // note: Unrestricted isn't empty
587 if (state == PermissionState.Unrestricted)
589 if ((list == null) || (list.Count == 0))
591 // the set may include some empty permissions
592 foreach (IPermission p in list) {
593 // empty == fully restricted == IsSubsetOf(null) == true
594 if (!p.IsSubsetOf (null))
601 public bool IsUnrestricted ()
603 public virtual bool IsUnrestricted ()
606 return (state == PermissionState.Unrestricted);
610 public IPermission RemovePermission (Type permClass)
612 public virtual IPermission RemovePermission (Type permClass)
615 if ((permClass == null) || _readOnly)
618 foreach (object o in list) {
619 if (o.GetType ().Equals (permClass)) {
621 return (IPermission) o;
628 public IPermission SetPermission (IPermission perm)
630 public virtual IPermission SetPermission (IPermission perm)
633 if ((perm == null) || _readOnly)
636 IUnrestrictedPermission u = (perm as IUnrestrictedPermission);
638 state = PermissionState.None;
640 state = u.IsUnrestricted () ? state : PermissionState.None;
643 if (perm is IUnrestrictedPermission)
644 state = PermissionState.None;
646 RemovePermission (perm.GetType ());
651 public override string ToString ()
653 return ToXml ().ToString ();
656 public virtual SecurityElement ToXml ()
658 SecurityElement se = new SecurityElement (tagName);
659 se.AddAttribute ("class", GetType ().FullName);
660 se.AddAttribute ("version", version.ToString ());
661 if (state == PermissionState.Unrestricted)
662 se.AddAttribute ("Unrestricted", "true");
664 // required for permissions that do not implement IUnrestrictedPermission
665 foreach (IPermission p in list) {
666 se.AddChild (p.ToXml ());
672 public PermissionSet Union (PermissionSet other)
674 public virtual PermissionSet Union (PermissionSet other)
680 PermissionSet copy = null;
681 if (this.IsUnrestricted () || other.IsUnrestricted ()) {
683 // there are no child elements in unrestricted permission sets
684 return new PermissionSet (PermissionState.Unrestricted);
687 // so we keep the "right" type (e.g. NamedPermissionSet)
689 copy.state = PermissionState.Unrestricted;
690 // copy all permissions that do not implement IUnrestrictedPermission
691 foreach (IPermission p in this.list) {
692 if (!(p is IUnrestrictedPermission))
693 copy.AddPermission (p);
695 foreach (IPermission p in other.list) {
696 if (!(p is IUnrestrictedPermission))
697 copy.AddPermission (p);
702 // PermissionState.None -> copy all permissions
703 foreach (IPermission p in other.list) {
704 copy.AddPermission (p);
710 public virtual int Count {
711 get { return list.Count; }
714 public virtual bool IsSynchronized {
715 get { return list.IsSynchronized; }
718 public virtual bool IsReadOnly {
719 // always false (as documented) but the PermissionSet can be read-only
720 // e.g. in a PolicyStatement
721 get { return false; }
724 public virtual object SyncRoot {
728 internal bool DeclarativeSecurity {
729 get { return _declsec; }
730 set { _declsec = value; }
733 [MonoTODO ("may not be required")]
734 void IDeserializationCallback.OnDeserialization (object sender)
740 public override bool Equals (object obj)
744 PermissionSet ps = (obj as PermissionSet);
747 if (state != ps.state)
749 if (list.Count != ps.Count)
752 for (int i=0; i < list.Count; i++) {
754 for (int j=0; i < ps.list.Count; j++) {
755 if (list [i].Equals (ps.list [j])) {
767 public override int GetHashCode ()
769 return (list.Count == 0) ? (int) state : base.GetHashCode ();
772 [MonoTODO ("(2.0) what's it doing here? There's probably a reason this was added here.")]
773 static public void RevertAssert ()
775 CodeAccessPermission.RevertAssert ();
781 internal PolicyLevel Resolver {
782 get { return _policyLevel; }
783 set { _policyLevel = value; }
786 internal void SetReadOnly (bool value)
791 private bool AllIgnored ()
793 if (_ignored == null)
794 throw new NotSupportedException ("bad bad bad");
796 for (int i=0; i < _ignored.Length; i++) {
800 // everything is ignored (i.e. non-CAS permission or asserted permission).
804 internal bool ProcessFrame (SecurityFrame frame, ref Assembly current, ref AppDomain domain)
806 if (IsUnrestricted ()) {
807 // we request unrestricted
808 if (frame.Deny != null) {
809 // but have restrictions (some denied permissions)
810 CodeAccessPermission.ThrowSecurityException (this, "Deny", frame, SecurityAction.Demand, null);
811 } else if ((frame.PermitOnly != null) && !frame.PermitOnly.IsUnrestricted ()) {
812 // but have restrictions (only some permitted permissions)
813 CodeAccessPermission.ThrowSecurityException (this, "PermitOnly", frame, SecurityAction.Demand, null);
817 // skip next steps if no Assert, Deny or PermitOnly are present
818 if (frame.HasStackModifiers) {
819 for (int i = 0; i < list.Count; i++) {
820 CodeAccessPermission cap = (CodeAccessPermission) list [i];
821 if (cap.ProcessFrame (frame)) {
822 _ignored [i] = true; // asserted
824 return true; // no more, abort stack walk!
829 // however the "final" grant set is resolved by assembly, so
830 // there's no need to check it every time (just when we're
831 // changing assemblies between frames).
832 if (frame.Assembly != current) {
833 CheckAssembly (current, frame);
834 current = frame.Assembly;
837 if (frame.Domain != domain) {
838 CheckAppDomain (domain, frame);
839 domain = frame.Domain;
845 internal void CheckAssembly (Assembly a, SecurityFrame frame)
847 IPermission p = SecurityManager.CheckPermissionSet (a, this, false);
849 CodeAccessPermission.ThrowSecurityException (this, "Demand failed assembly permissions checks.",
850 frame, SecurityAction.Demand, p);
854 internal void CheckAppDomain (AppDomain domain, SecurityFrame frame)
856 IPermission p = SecurityManager.CheckPermissionSet (domain, this);
858 CodeAccessPermission.ThrowSecurityException (this, "Demand failed appdomain permissions checks.",
859 frame, SecurityAction.Demand, p);
863 // 2.0 metadata format
865 internal static PermissionSet CreateFromBinaryFormat (byte[] data)
867 if ((data == null) || (data [0] != 0x2E) || (data.Length < 2)) {
868 string msg = Locale.GetText ("Invalid data in 2.0 metadata format.");
869 throw new SecurityException (msg);
873 int numattr = ReadEncodedInt (data, ref pos);
874 PermissionSet ps = new PermissionSet (PermissionState.None);
875 for (int i = 0; i < numattr; i++) {
876 IPermission p = ProcessAttribute (data, ref pos);
878 string msg = Locale.GetText ("Unsupported data found in 2.0 metadata format.");
879 throw new SecurityException (msg);
881 ps.AddPermission (p);
886 internal static int ReadEncodedInt (byte[] data, ref int position)
889 if ((data [position] & 0x80) == 0) {
890 len = data [position];
892 } else if ((data [position] & 0x40) == 0) {
893 len = ((data [position] & 0x3f) << 8 | data [position + 1]);
896 len = (((data [position] & 0x1f) << 24) | (data [position + 1] << 16) |
897 (data [position + 2] << 8) | (data [position + 3]));
903 static object[] action = new object [1] { (SecurityAction) 0 };
905 // TODO: add support for arrays and enums (2.0)
906 internal static IPermission ProcessAttribute (byte[] data, ref int position)
908 int clen = ReadEncodedInt (data, ref position);
909 string cnam = Encoding.UTF8.GetString (data, position, clen);
912 Type secattr = Type.GetType (cnam);
913 SecurityAttribute sa = (Activator.CreateInstance (secattr, action) as SecurityAttribute);
917 /*int optionalParametersLength =*/ ReadEncodedInt (data, ref position);
918 int numberOfParameters = ReadEncodedInt (data, ref position);
919 for (int j=0; j < numberOfParameters; j++) {
920 bool property = false;
921 switch (data [position++]) {
922 case 0x53: // field (technically possible and working)
925 case 0x54: // property (common case)
933 byte type = data [position++];
936 type = data [position++];
939 int plen = ReadEncodedInt (data, ref position);
940 string pnam = Encoding.UTF8.GetString (data, position, plen);
945 arrayLength = BitConverter.ToInt32 (data, position);
950 object[] arrayIndex = null;
951 for (int i = 0; i < arrayLength; i++) {
953 // TODO - setup index (2.0)
956 // sadly type values doesn't match ther TypeCode enum :(
958 case 0x02: // MONO_TYPE_BOOLEAN
959 obj = (object) Convert.ToBoolean (data [position++]);
961 case 0x03: // MONO_TYPE_CHAR
962 obj = (object) Convert.ToChar (data [position]);
965 case 0x04: // MONO_TYPE_I1
966 obj = (object) Convert.ToSByte (data [position++]);
968 case 0x05: // MONO_TYPE_U1
969 obj = (object) Convert.ToByte (data [position++]);
971 case 0x06: // MONO_TYPE_I2
972 obj = (object) Convert.ToInt16 (data [position]);
975 case 0x07: // MONO_TYPE_U2
976 obj = (object) Convert.ToUInt16 (data [position]);
979 case 0x08: // MONO_TYPE_I4
980 obj = (object) Convert.ToInt32 (data [position]);
983 case 0x09: // MONO_TYPE_U4
984 obj = (object) Convert.ToUInt32 (data [position]);
987 case 0x0A: // MONO_TYPE_I8
988 obj = (object) Convert.ToInt64 (data [position]);
991 case 0x0B: // MONO_TYPE_U8
992 obj = (object) Convert.ToUInt64 (data [position]);
995 case 0x0C: // MONO_TYPE_R4
996 obj = (object) Convert.ToSingle (data [position]);
999 case 0x0D: // MONO_TYPE_R8
1000 obj = (object) Convert.ToDouble (data [position]);
1003 case 0x0E: // MONO_TYPE_STRING
1005 if (data [position] != 0xFF) {
1006 int slen = ReadEncodedInt (data, ref position);
1007 s = Encoding.UTF8.GetString (data, position, slen);
1014 case 0x50: // special for TYPE
1015 int tlen = ReadEncodedInt (data, ref position);
1016 obj = (object) Type.GetType (Encoding.UTF8.GetString (data, position, tlen));
1020 return null; // unsupported
1024 PropertyInfo pi = secattr.GetProperty (pnam);
1025 pi.SetValue (sa, obj, arrayIndex);
1027 FieldInfo fi = secattr.GetField (pnam);
1028 fi.SetValue (sa, obj);
1032 return sa.CreatePermission ();