SetItem() private méthode

private SetItem ( int index, Object item ) : void
index int
item Object
Résultat void
Exemple #1
0
        // Used to merge two distinct TokenBasedSets (used currently only in PermissionSet Deserialization)
        internal TokenBasedSet SpecialUnion(TokenBasedSet other)
        {
            // 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;

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

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

                if (thisObj == null)
                {
                    PermissionToken token = PermissionToken.GetToken(otherPerm);

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

                    unionSet.SetItem(token.m_index, otherPerm);
                }
                else if (otherObj == null)
                {
                    PermissionToken token = PermissionToken.GetToken(thisPerm);
                    if (token == null)
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                    }
                    unionSet.SetItem(token.m_index, thisPerm);
                }
                else
                {
                    Debug.Assert((thisObj == null || otherObj == null), "Permission cannot be in both TokenBasedSets");
                }
            }
            return(unionSet);
        }
        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);
        }
Exemple #3
0
        private void GenericIntersect(TokenBasedSet target, TokenBasedSet other)
        {
            // Note: Assumes target set is large enough and empty.
            int thisMaxIndex  = this.m_maxIndex;
            int otherMaxIndex = other != null ? other.m_maxIndex : 0;
            int minMaxIndex   = thisMaxIndex < otherMaxIndex ? thisMaxIndex : otherMaxIndex;

            // We want to save any exceptions that occur and throw them at the end.
            Exception savedException = null;

            for (int i = 0; i <= minMaxIndex; i++)
            {
                try
                {
                    IPermission p1 = other != null ? (IPermission)other.m_objSet[i] : null;
                    IPermission p2 = (IPermission)this.m_objSet[i];
                    if (p1 != null && p2 != null)
                    {
                        target.SetItem(i, p1.Intersect(p2));
                    }
                    else
                    {
                        target.SetItem(i, null);
                    }
                }
                catch (Exception e)
                {
                    if (savedException == null)
                    {
                        savedException = e;
                    }

                    // Remove the permission from the intersection set

                    target.SetItem(i, null);
                }
            }

            if (minMaxIndex == otherMaxIndex)
            {
                for (int i = otherMaxIndex + 1; i <= target.m_maxIndex; ++i)
                {
                    target.RemoveItem(i);
                }
            }

            if (savedException != null)
            {
                throw savedException;
            }
        }
        // Removes the current element from the underlying set of objects. This
        // method will throw a NotSupportedException if the underlying set of
        // objects cannot be modified.
        //
        public virtual void Remove()
        {
            if (m_currentIndex == -1)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
            }
            if (EndConditionReached())
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));
            }

            m_set.SetItem(m_currentIndex, null);
        }
Exemple #5
0
        public static TokenBasedSet CopyTokenBasedSet( TokenBasedSet set )
        {
            if (set == null || set.GetCount() == 0)
                return null;

            int maxIndex = set.GetMaxUsedIndex();

            TokenBasedSet copySet = new TokenBasedSet( maxIndex + 1, 4 );

            for (int i = 0; i <= maxIndex; ++i)
            {
                Object obj = set.GetItem( i );

                if (obj == null)
                    copySet.SetItem( i, null );
                else if (obj is IPermission)
                    copySet.SetItem( i, ((IPermission)obj).Copy() );
                else if (obj is PermissionList)
                    copySet.SetItem( i, ((PermissionList)obj).Copy() );
                else
                {
                    BCLDebug.Assert( false, "CopyTokenBasedSet can only be used for IPermission and PermissionList based TokenBasedSets" );
                    copySet.SetItem( i, obj );
                }
            }

            return copySet;
        }
Exemple #6
0
     public PermissionListSet(PermissionListSet permListSet)
     {
         if (permListSet == null)
         {
             Reset();
             return;
         }
         
         m_unrestrictedPermSet = new TokenBasedSet(permListSet.m_unrestrictedPermSet);
 
         // Now deep copy all permission lists in set.
         // Note that this DOES deep copy permissions in the list.
         for (int i = 0; i <= m_unrestrictedPermSet.GetMaxUsedIndex(); i++)
         {
             PermissionList plist = (PermissionList)m_unrestrictedPermSet.GetItem(i);
             if (plist != null)
             {
                 m_unrestrictedPermSet.SetItem(i, plist.Copy());
             }
         }
         
         m_normalPermSet = new TokenBasedSet(permListSet.m_normalPermSet);
         
         // Now deep copy all permission lists in set.
         // Note that this DOES deep copy permissions in the list.
         for (int i = 0; i <= m_normalPermSet.GetMaxUsedIndex(); i++)
         {
             PermissionList plist = (PermissionList)m_normalPermSet.GetItem(i);
             if (plist != null)
             {
                 m_normalPermSet.SetItem(i, plist.Copy());
             }
         }        
         
         m_unrestricted = permListSet.m_unrestricted;
         m_state = permListSet.m_state;
     }
        // Used to merge two distinct TokenBasedSets (used currently only in PermissionSet Deserialization)
        internal TokenBasedSet SpecialUnion(TokenBasedSet other)
        {
            // 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;
#if FEATURE_CAS_POLICY
                ISecurityElementFactory thisElem = thisObj as ISecurityElementFactory;
#endif // FEATURE_CAS_POLICY

                Object otherObj = (other != null)?other.GetItem( i ):null;
                IPermission otherPerm = otherObj as IPermission;
#if FEATURE_CAS_POLICY
                ISecurityElementFactory otherElem = otherObj as ISecurityElementFactory;
#endif // FEATURE_CAS_POLICY

                if (thisObj == null && otherObj == null)
                    continue;
        
             
                if (thisObj == null)
                {
#if FEATURE_CAS_POLICY
                    if (otherElem != null)
                    {
                        otherPerm = PermissionSet.CreatePerm(otherElem, false);
                    }
#endif // FEATURE_CAS_POLICY

                    PermissionToken token = PermissionToken.GetToken(otherPerm);
                    
                    if (token == null)
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                    }
                    
                    unionSet.SetItem(token.m_index, otherPerm);
                }
                else if (otherObj == null)
                {
#if FEATURE_CAS_POLICY
                    if (thisElem != null)
                    {
                        thisPerm = PermissionSet.CreatePerm(thisElem, false);
                    }
#endif // FEATURE_CAS_POLICY

                    PermissionToken token = PermissionToken.GetToken(thisPerm);
                    if (token == null)
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                    }
                    unionSet.SetItem( token.m_index, thisPerm);
                }
                else
                {
                    Contract.Assert( (thisObj == null || otherObj == null), "Permission cannot be in both TokenBasedSets" );
                }
            }
            return unionSet;
        }
Exemple #8
0
        public PermissionSet(PermissionSet permSet)
            : this()
        {
            if (permSet == null)
            {
                Reset();
                return;
            }

            m_Unrestricted = permSet.m_Unrestricted;
            m_CheckedForNonCas = permSet.m_CheckedForNonCas;
            m_ContainsCas = permSet.m_ContainsCas;
            m_ContainsNonCas = permSet.m_ContainsNonCas;
            m_ignoreTypeLoadFailures = permSet.m_ignoreTypeLoadFailures;

            if (permSet.m_permSet != null)
            {
                m_permSet = new TokenBasedSet(permSet.m_permSet);
                
                // now deep copy all permissions in set
                for (int i = m_permSet.GetStartingIndex(); i <= m_permSet.GetMaxUsedIndex(); i++)
                {
                    Object obj = m_permSet.GetItem(i);
                    IPermission perm = obj as IPermission;
#if FEATURE_CAS_POLICY
                    ISecurityElementFactory elem = obj as ISecurityElementFactory;
#endif // FEATURE_CAS_POLICY
                    if (perm != null)
                    {
                        m_permSet.SetItem(i, perm.Copy());
                    }
#if FEATURE_CAS_POLICY
                    else if (elem != null)
                    {
                        m_permSet.SetItem(i, elem.Copy());
                    }
#endif // FEATURE_CAS_POLICY
                }
            }
        }
        // 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);
        }
Exemple #10
0
     private void GenericUnion( TokenBasedSet target, TokenBasedSet other, bool needToCopy )
     {
         // Note: Assumes target set is large enough and empty.
         
         // Get the max indicies
         int thisMaxIndex = this.m_maxIndex;
         int otherMaxIndex = other != null ? other.m_maxIndex : 0;
         int minMaxUsedIndex;
         int maxMaxUsedIndex;
         TokenBasedSet biggerSet;
         
         // We want to save any exceptions that occur and throw them at the end.
         Exception savedException = null;
         
         if (thisMaxIndex < otherMaxIndex)
         {
             minMaxUsedIndex = thisMaxIndex;
             maxMaxUsedIndex = otherMaxIndex;
             biggerSet = other;
         }
         else
         {
             minMaxUsedIndex = otherMaxIndex;
             maxMaxUsedIndex = thisMaxIndex;
             biggerSet = this;
         }
 
         IPermission p1;
         IPermission p2;
         int i;
         
         for (i = 0; i<=minMaxUsedIndex; ++i)
         {
             try
             {
                 p2 = other != null ? (IPermission)other.m_objSet[i] : null;
                 p1 = (IPermission)this.m_objSet[i];
                 if (p2 != null)
                 {
                     // we only need to do something is the other set has something in this slot
                     if (p1 == null)
                     {
                         // nothing in this set, so insert a copy.
                         if (needToCopy)
                         target.SetItem( i, p2.Copy() );
                         else
                             target.SetItem( i, p2 );
                     }
                     else
                     {
                         // both have it, so replace this's with the union.
                         target.SetItem( i, p1.Union( p2 ) );
                     }
                 }
                 else if (needToCopy)
                 {
                     if (p1 != null)
                         target.SetItem( i, p1.Copy() );
                     else
                         target.SetItem( i, null );
                 }
                 else
                 {
                     target.SetItem( i, p1 );
                 }
             }
             catch (Exception e)
             {
                 if (savedException == null)
                     savedException = e;
             }
         }
         
         for (i = minMaxUsedIndex+1; i <= maxMaxUsedIndex; ++i)
         {
             try
             {
                 if (needToCopy && biggerSet.m_objSet[i] != null)
                     target.SetItem( i, ((IPermission)biggerSet.m_objSet[i]).Copy() );
                 else
                     target.SetItem( i, biggerSet.m_objSet[i] );
             }
             catch (Exception e)
             {
                 if (savedException == null)
                     savedException = e;
             }
         }
         
         if (savedException != null)
             throw savedException;
     }
Exemple #11
0
        private void GenericUnion(TokenBasedSet target, TokenBasedSet other, bool needToCopy)
        {
            // Note: Assumes target set is large enough and empty.

            // Get the max indicies
            int           thisMaxIndex  = this.m_maxIndex;
            int           otherMaxIndex = other != null ? other.m_maxIndex : 0;
            int           minMaxUsedIndex;
            int           maxMaxUsedIndex;
            TokenBasedSet biggerSet;

            // We want to save any exceptions that occur and throw them at the end.
            Exception savedException = null;

            if (thisMaxIndex < otherMaxIndex)
            {
                minMaxUsedIndex = thisMaxIndex;
                maxMaxUsedIndex = otherMaxIndex;
                biggerSet       = other;
            }
            else
            {
                minMaxUsedIndex = otherMaxIndex;
                maxMaxUsedIndex = thisMaxIndex;
                biggerSet       = this;
            }

            IPermission p1;
            IPermission p2;
            int         i;

            for (i = 0; i <= minMaxUsedIndex; ++i)
            {
                try
                {
                    p2 = other != null ? (IPermission)other.m_objSet[i] : null;
                    p1 = (IPermission)this.m_objSet[i];
                    if (p2 != null)
                    {
                        // we only need to do something is the other set has something in this slot
                        if (p1 == null)
                        {
                            // nothing in this set, so insert a copy.
                            if (needToCopy)
                            {
                                target.SetItem(i, p2.Copy());
                            }
                            else
                            {
                                target.SetItem(i, p2);
                            }
                        }
                        else
                        {
                            // both have it, so replace this's with the union.
                            target.SetItem(i, p1.Union(p2));
                        }
                    }
                    else if (needToCopy)
                    {
                        if (p1 != null)
                        {
                            target.SetItem(i, p1.Copy());
                        }
                        else
                        {
                            target.SetItem(i, null);
                        }
                    }
                    else
                    {
                        target.SetItem(i, p1);
                    }
                }
                catch (Exception e)
                {
                    if (savedException == null)
                    {
                        savedException = e;
                    }
                }
            }

            for (i = minMaxUsedIndex + 1; i <= maxMaxUsedIndex; ++i)
            {
                try
                {
                    if (needToCopy && biggerSet.m_objSet[i] != null)
                    {
                        target.SetItem(i, ((IPermission)biggerSet.m_objSet[i]).Copy());
                    }
                    else
                    {
                        target.SetItem(i, biggerSet.m_objSet[i]);
                    }
                }
                catch (Exception e)
                {
                    if (savedException == null)
                    {
                        savedException = e;
                    }
                }
            }

            if (savedException != null)
            {
                throw savedException;
            }
        }
Exemple #12
0
        /// <include file='doc\PermissionSet.uex' path='docs/doc[@for="PermissionSet.PermissionSet1"]/*' />
        public PermissionSet(PermissionSet permSet)
            : this()
        {
            if (permSet == null)
            {
                Reset();
                return;
            }
    
            m_Unrestricted = permSet.m_Unrestricted;
            m_CheckedForNonCas = permSet.m_CheckedForNonCas;
            m_ContainsCas = permSet.m_ContainsCas;
            m_ContainsNonCas = permSet.m_ContainsNonCas;
            
            if (permSet.m_normalPermSet != null)
            {
                m_normalPermSet = new TokenBasedSet(permSet.m_normalPermSet);
                
                 // now deep copy all permissions in set
                for (int i = 0; i <= m_normalPermSet.GetMaxUsedIndex(); i++)
                {
                    IPermission perm = (IPermission)m_normalPermSet.GetItem(i);
                    if (perm != null)
                    {
                        m_normalPermSet.SetItem(i, perm.Copy());
                    }
                }
            }
               
            if (permSet.m_unrestrictedPermSet != null)
            {
                m_unrestrictedPermSet = new TokenBasedSet(permSet.m_unrestrictedPermSet);
                
                 // now deep copy all permissions in set
                for (int i = 0; i <= m_unrestrictedPermSet.GetMaxUsedIndex(); i++)
                {
                    IPermission perm = (IPermission)m_unrestrictedPermSet.GetItem(i);
                    if (perm != null)
                    {
                        m_unrestrictedPermSet.SetItem(i, perm.Copy());
                    }
                }
            }

            if (permSet.m_toBeLoaded != null)
            {
                this.m_toBeLoaded = new SecurityElement();

                IEnumerator enumerator = permSet.m_toBeLoaded.m_lChildren.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    this.m_toBeLoaded.AddChild( (SecurityElement)enumerator.Current );
                }
            }

        }
Exemple #13
0
        public PermissionSet(PermissionSet permSet)
            : this()
        {
            if (permSet == null)
            {
                Reset();
                return;
            }

            m_Unrestricted = permSet.m_Unrestricted;
            m_CheckedForNonCas = permSet.m_CheckedForNonCas;
            m_ContainsCas = permSet.m_ContainsCas;
            m_ContainsNonCas = permSet.m_ContainsNonCas;
            m_ignoreTypeLoadFailures = permSet.m_ignoreTypeLoadFailures;

            if (permSet.m_permSet != null)
            {
                m_permSet = new TokenBasedSet(permSet.m_permSet);
                
                // now deep copy all permissions in set
                for (int i = m_permSet.GetStartingIndex(); i <= m_permSet.GetMaxUsedIndex(); i++)
                {
                    Object obj = m_permSet.GetItem(i);
                    IPermission perm = obj as IPermission;

                    if (perm != null)
                    {
                        m_permSet.SetItem(i, perm.Copy());
                    }
                }
            }
        }
 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;
 }
        // 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;
        }
Exemple #16
0
     private void AppendTokenBasedSets( TokenBasedSet thisSet, TokenBasedSet permSet, int type, bool unrestricted )
     {
         int thisMaxIndex = thisSet.GetMaxUsedIndex();
         int permMaxIndex = permSet == null ? 0 : permSet.GetMaxUsedIndex();
         int maxIndex = thisMaxIndex > permMaxIndex ? thisMaxIndex : permMaxIndex;
         
         // Loop over the relevant indexes...
         for (int i = 0; i <= maxIndex; i++)
         {
             PermissionList plist = (PermissionList)thisSet.GetItem(i);
             CodeAccessPermission cap = permSet == null ? null : (CodeAccessPermission)permSet.GetItem(i);
             
             if (plist == null)
             {
                 if (this.m_unrestricted)
                 {
                     switch (type)
                     {
                     case PermissionList.MatchChecked:
                     case PermissionList.MatchPermitOnly:
                         plist = new PermissionList();
                         plist.AppendPermission(cap, type);
                         thisSet.SetItem( i, plist );
                         break;
                     
                     case PermissionList.MatchDeny:
                     case PermissionList.MatchAssert:
                         if (cap != null)
                         {
                             plist = new PermissionList();
                             plist.AppendPermission(cap, type);
                             thisSet.SetItem( i, plist );
                         }
                         break;
                     
                     default:
                         throw new ArgumentException(Environment.GetResourceString( "Argument_InvalidPermissionListType" ));
                     }
                 }
             }
             else
             {                    
                 // A list already exists. All lists should have at least
                 // one element in them.
 
                 // Normally, only append if the permission is not null.
                 // However, if the type is Checked, then make sure the
                 // list is terminated with a permission, null or not.
                 switch (type)
                 {
                 case PermissionList.MatchChecked:
                 case PermissionList.MatchPermitOnly:
                     plist.AppendPermissionAndCompress(cap, type);
                     break;
                         
                 case PermissionList.MatchDeny:
                 case PermissionList.MatchAssert:
                     if (cap != null)
                         plist.AppendPermissionAndCompress(cap, type);
                     break;
                         
                 default:
                     throw new ArgumentException(Environment.GetResourceString( "Argument_InvalidPermissionListType" ));
                 }
             }
         }
     }
Exemple #17
0
		private void AppendStackHelper( TokenBasedSet thisSet, TokenBasedSet permSet, bool unrestrictedThisSet, bool unrestrictedPermSet, bool unrestricted )
		{
            int maxThis = thisSet.GetMaxUsedIndex();
            int maxPerm = permSet.GetMaxUsedIndex();
            
            int maxIndex = maxThis > maxPerm ? maxThis : maxPerm;
            
            for (int i = 0; i <= maxIndex; i++)
            {
                PermissionList plist = (PermissionList)thisSet.GetItem(i);
                PermissionList appendList = (PermissionList)permSet.GetItem(i);
                if (plist != null)
                {
                    if (appendList != null)
                    {
                        // This call will not add the permission if the list is
                        // empty, or if the last element is a normal check with
                        // a null Permission. Let the method take care of it...
                        plist.AppendStack(appendList.Copy());
                    }
                    else
                    {
                        // Nothing on the compressed stack for this index,
                        // so terminate current list.
                        if (!unrestrictedPermSet)
                        {
                            thisSet.SetItem( i, plist.Copy() );
                        }
                    }
                }
                else if (unrestrictedThisSet && appendList != null)
                {
                    thisSet.SetItem(i, appendList.Copy());
                }
            }
		}
Exemple #18
0
 private void GenericIntersect( TokenBasedSet target, TokenBasedSet other )
 {
     // Note: Assumes target set is large enough and empty.
     int thisMaxIndex = this.m_maxIndex; 
     int otherMaxIndex = other != null ? other.m_maxIndex : 0;
     int minMaxIndex = thisMaxIndex < otherMaxIndex ? thisMaxIndex : otherMaxIndex;
     
     // We want to save any exceptions that occur and throw them at the end.
     Exception savedException = null;
     
     for (int i = 0; i <= minMaxIndex; i++)
     {
         try
         {
             IPermission p1 = other != null ? (IPermission)other.m_objSet[i] : null;
             IPermission p2 = (IPermission)this.m_objSet[i];
             if (p1 != null && p2 != null)
             {
                 target.SetItem( i, p1.Intersect(p2) );
             }
             else
             {
                 target.SetItem( i, null );
             }
         }
         catch (Exception e)
         {
             if (savedException == null)
                 savedException = e;
                 
             // Remove the permission from the intersection set
             
             target.SetItem( i, null );
         }
     }
     
     if (minMaxIndex == otherMaxIndex)
     {
         for (int i = otherMaxIndex+1; i <= target.m_maxIndex; ++i)
         {
             target.RemoveItem( i );
         }
     }
     
     if (savedException != null)
         throw savedException;
 }