internal TokenBasedSet SpecialUnion(TokenBasedSet other)
        {
            int maxUsedIndex;

            this.OnDeserializedInternal();
            TokenBasedSet set = new TokenBasedSet();

            if (other != null)
            {
                other.OnDeserializedInternal();
                maxUsedIndex = (this.GetMaxUsedIndex() > other.GetMaxUsedIndex()) ? this.GetMaxUsedIndex() : other.GetMaxUsedIndex();
            }
            else
            {
                maxUsedIndex = this.GetMaxUsedIndex();
            }
            for (int i = 0; i <= maxUsedIndex; i++)
            {
                object                  item        = this.GetItem(i);
                IPermission             perm        = item as IPermission;
                ISecurityElementFactory factory     = item as ISecurityElementFactory;
                object                  obj3        = (other != null) ? other.GetItem(i) : null;
                IPermission             permission2 = obj3 as IPermission;
                ISecurityElementFactory factory2    = obj3 as ISecurityElementFactory;
                if ((item != null) || (obj3 != null))
                {
                    if (item == null)
                    {
                        if (factory2 != null)
                        {
                            permission2 = PermissionSet.CreatePerm(factory2, false);
                        }
                        PermissionToken token = PermissionToken.GetToken(permission2);
                        if (token == null)
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                        }
                        set.SetItem(token.m_index, permission2);
                    }
                    else if (obj3 == null)
                    {
                        if (factory != null)
                        {
                            perm = PermissionSet.CreatePerm(factory, false);
                        }
                        PermissionToken token2 = PermissionToken.GetToken(perm);
                        if (token2 == null)
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                        }
                        set.SetItem(token2.m_index, perm);
                    }
                }
            }
            return(set);
        }
Esempio n. 2
0
        internal void SpecialSplit(ref TokenBasedSet unrestrictedPermSet, ref TokenBasedSet normalPermSet, bool ignoreTypeLoadFailures)
        {
            int maxIndex = GetMaxUsedIndex();

            for (int i = GetStartingIndex(); i <= maxIndex; ++i)
            {
                Object obj = GetItem(i);
                if (obj != null)
                {
                    IPermission perm = obj as IPermission;
#if FEATURE_CAS_POLICY
                    if (perm == null)
                    {
                        perm = PermissionSet.CreatePerm(obj, ignoreTypeLoadFailures);
                    }
#endif // FEATURE_CAS_POLICY
                    PermissionToken token = PermissionToken.GetToken(perm);

                    if (perm == null || token == null)
                    {
                        continue;
                    }

                    if (perm is IUnrestrictedPermission)
                    {
                        // Add to unrestrictedPermSet
                        if (unrestrictedPermSet == null)
                        {
                            unrestrictedPermSet = new TokenBasedSet();
                        }
                        unrestrictedPermSet.SetItem(token.m_index, perm);
                    }
                    else
                    {
                        // Add to normalPermSet
                        if (normalPermSet == null)
                        {
                            normalPermSet = new TokenBasedSet();
                        }
                        normalPermSet.SetItem(token.m_index, perm);
                    }
                }
            }
        }
Esempio n. 3
0
        // Token: 0x06002B52 RID: 11090 RVA: 0x000A147C File Offset: 0x0009F67C
        internal void SpecialSplit(ref TokenBasedSet unrestrictedPermSet, ref TokenBasedSet normalPermSet, bool ignoreTypeLoadFailures)
        {
            int maxUsedIndex = this.GetMaxUsedIndex();

            for (int i = this.GetStartingIndex(); i <= maxUsedIndex; i++)
            {
                object item = this.GetItem(i);
                if (item != null)
                {
                    IPermission permission = item as IPermission;
                    if (permission == null)
                    {
                        permission = PermissionSet.CreatePerm(item, ignoreTypeLoadFailures);
                    }
                    PermissionToken token = PermissionToken.GetToken(permission);
                    if (permission != null && token != null)
                    {
                        if (permission is IUnrestrictedPermission)
                        {
                            if (unrestrictedPermSet == null)
                            {
                                unrestrictedPermSet = new TokenBasedSet();
                            }
                            unrestrictedPermSet.SetItem(token.m_index, permission);
                        }
                        else
                        {
                            if (normalPermSet == null)
                            {
                                normalPermSet = new TokenBasedSet();
                            }
                            normalPermSet.SetItem(token.m_index, permission);
                        }
                    }
                }
            }
        }
        // Used to merge two distinct TokenBasedSets (used currently only in PermissionSet Deserialization)
        internal TokenBasedSet SpecialUnion(TokenBasedSet other, ref bool canUnrestrictedOverride)
        {
            // This gets called from PermissionSet.OnDeserialized and it's possible that the TokenBasedSets have
            // not been subjected to VTS callbacks yet
            OnDeserializedInternal();
            TokenBasedSet unionSet = new TokenBasedSet();
            int           maxMax;

            if (other != null)
            {
                other.OnDeserializedInternal();
                maxMax = this.GetMaxUsedIndex() > other.GetMaxUsedIndex() ? this.GetMaxUsedIndex() : other.GetMaxUsedIndex();
            }
            else
            {
                maxMax = this.GetMaxUsedIndex();
            }

            for (int i = 0; i <= maxMax; ++i)
            {
                Object                  thisObj  = this.GetItem(i);
                IPermission             thisPerm = thisObj as IPermission;
                ISecurityElementFactory thisElem = thisObj as ISecurityElementFactory;

                Object                  otherObj  = (other != null)?other.GetItem(i):null;
                IPermission             otherPerm = otherObj as IPermission;
                ISecurityElementFactory otherElem = otherObj as ISecurityElementFactory;

                if (thisObj == null && otherObj == null)
                {
                    continue;
                }


                if (thisObj == null)
                {
                    if (otherElem != null)
                    {
                        otherPerm = PermissionSet.CreatePerm(otherElem, false);
                    }



                    PermissionToken token = PermissionToken.GetToken(otherPerm);

                    if (token == null)
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                    }

                    unionSet.SetItem(token.m_index, otherPerm);
                    if (!CodeAccessPermission.CanUnrestrictedOverride(otherPerm))
                    {
                        canUnrestrictedOverride = false;
                    }
                }
                else if (otherObj == null)
                {
                    if (thisElem != null)
                    {
                        thisPerm = PermissionSet.CreatePerm(thisElem, false);
                    }
                    PermissionToken token = PermissionToken.GetToken(thisPerm);
                    if (token == null)
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                    }
                    unionSet.SetItem(token.m_index, thisPerm);
                    if (!CodeAccessPermission.CanUnrestrictedOverride(thisPerm))
                    {
                        canUnrestrictedOverride = false;
                    }
                }
                else
                {
                    BCLDebug.Assert((thisObj == null || otherObj == null), "Permission cannot be in both TokenBasedSets");
                }
            }
            return(unionSet);
        }