-#if NET_2_0
- internal static PermissionSetCollection DecodeCollection (IntPtr permissions, int length)
- {
- // Permission sets from the runtime (declarative security) can be cached
- // for performance as they can never change (i.e. they are read-only).
-
- if (_declsecCache == null) {
- lock (_lockObject) {
- if (_declsecCache == null) {
- _declsecCache = new Hashtable ();
- }
- }
- }
-
- PermissionSetCollection psc = null;
- lock (_lockObject) {
- object key = (object) (int) permissions;
- psc = (PermissionSetCollection) _declsecCache [key];
- if (psc == null) {
- // create permissionset and add it to the cache
- byte[] data = new byte [length];
- Marshal.Copy (permissions, data, 0, length);
- psc = DecodeCollection (data);
- _declsecCache.Add (key, psc);
- }
- }
- return psc;
- }
-
- internal static PermissionSetCollection DecodeCollection (byte[] encodedPermissions)
- {
- if ((encodedPermissions == null) || (encodedPermissions.Length < 1))
- throw new SecurityException ("Invalid metadata format.");
-
- switch (encodedPermissions [0]) {
- case 60:
- // Fx 1.0/1.1 declarative security permissions metadata is in Unicode-encoded XML
- throw new SecurityException (Locale.GetText ("1.0 metadata format doesn't support collections."));
- case 0x2E:
- // Fx 2.0 are encoded "somewhat, but not enough, like" custom attributes
- // note: we still support the older format!
- return PermissionSetCollection.CreateFromBinaryFormat (encodedPermissions);
- default:
- throw new SecurityException (Locale.GetText ("Unknown metadata format."));
- }
- }
-#endif