dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Security/Policy AllMem


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Security/Policy AllMembershipCondition.cs,NONE,1.1 ApplicationDirectory.cs,NONE,1.1 ApplicationDirectoryMembershipCondition.cs,NONE,1.1 CodeGroup.cs,NONE,1.1 IIdentityPermissionFactory.cs,NONE,1.1 IMembershipCondition.cs,NONE,1.1 PolicyStatement.cs,NONE,1.1 PolicyStatementAttribute.cs,NONE,1.1 Evidence.cs,1.3,1.4
Date: Mon, 07 Apr 2003 05:58:40 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy
In directory subversions:/tmp/cvs-serv19567/runtime/System/Security/Policy

Modified Files:
        Evidence.cs 
Added Files:
        AllMembershipCondition.cs ApplicationDirectory.cs 
        ApplicationDirectoryMembershipCondition.cs CodeGroup.cs 
        IIdentityPermissionFactory.cs IMembershipCondition.cs 
        PolicyStatement.cs PolicyStatementAttribute.cs 
Log Message:


Implement some of the missing classes in "System.Security.Policy";
fill out the implementation of "Evidence".


--- NEW FILE ---
/*
 * AllMembershipCondition.cs - Implementation of the
 *              "System.Security.Policy.AllMembershipCondition" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

[Serializable]
public sealed class AllMembershipCondition
        : IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
{
        // Constructor.
        public AllMembershipCondition() {}

        // Implement the IMembership interface.
        public bool Check(Evidence evidence)
                        {
                                return true;
                        }
        public IMembershipCondition Copy()
                        {
                                return new AllMembershipCondition();
                        }
        public override bool Equals(Object obj)
                        {
                                return (obj is AllMembershipCondition);
                        }
        public override String ToString()
                        {
                                return _("Security_AllMembershipCondition");
                        }

        // Implement the ISecurityEncodable interface.
        public void FromXml(SecurityElement et)
                        {
                                FromXml(et, null);
                        }
        public SecurityElement ToXml()
                        {
                                return ToXml(null);
                        }

        // Implement the ISecurityPolicyEncodable interface.
        public void FromXml(SecurityElement et, PolicyLevel level)
                        {
                                if(et == null)
                                {
                                        throw new ArgumentNullException("et");
                                }
                                if(et.Tag != "IMembershipCondition")
                                {
                                        throw new ArgumentException
                                                (_("Security_PolicyName"));
                                }
                                if(et.Attribute("version") != "1")
                                {
                                        throw new ArgumentException
                                                (_("Security_PolicyVersion"));
                                }
                        }
        public SecurityElement ToXml(PolicyLevel level)
                        {
                                SecurityElement element;
                                element = new 
SecurityElement("IMembershipCondition");
                                element.AddAttribute
                                        ("class",
                                         
SecurityElement.Escape(typeof(AllMembershipCondition).
                                                                                
        AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                return element;
                        }

        // Get the hash code for this instance.
        public override int GetHashCode()
                        {
                                // All instances of this type are identical.
                                return GetType().GetHashCode();
                        }

}; // class AllMembershipCondition

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

--- NEW FILE ---
/*
 * ApplicationDirectory.cs - Implementation of the
 *              "System.Security.Policy.ApplicationDirectory" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

[Serializable]
public sealed class ApplicationDirectory
{
        // Internal state.
        private String name;

        // Constructor.
        public ApplicationDirectory(String name)
                        {
                                if(name == null)
                                {
                                        throw new ArgumentNullException("name");
                                }
                                this.name = name;
                        }

        // Get the directory path from this object.
        public String Directory
                        {
                                get
                                {
                                        return name;
                                }
                        }

        // Create a copy of this object.
        public ApplicationDirectory Copy()
                        {
                                return new ApplicationDirectory(name);
                        }

        // Determine if two objects are equal.
        public override bool Equals(Object obj)
                        {
                                ApplicationDirectory other = (obj as 
ApplicationDirectory);
                                if(other != null)
                                {
                                        return (other.name == name);
                                }
                                else
                                {
                                        return false;
                                }
                        }

        // Get the hash code for this instance.
        public override int GetHashCode()
                        {
                                return name.GetHashCode();
                        }

        // Convert this object into a string.
        public override String ToString()
                        {
                                return 
"<System.Security.Policy.ApplicationDirectory>\n" +
                                           "   <Directory>" +
                                           SecurityElement.Escape(name) +
                                           "</Directory>\n" +
                                           
"</System.Security.Policy.ApplicationDirectory>\n";
                        }

}; // class ApplicationDirectory

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

--- NEW FILE ---
/*
 * ApplicationDirectoryMembershipCondition.cs - Implementation of the
 *              
"System.Security.Policy.ApplicationDirectoryMembershipCondition" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

[Serializable]
public sealed class ApplicationDirectoryMembershipCondition
        : IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
{
        // Constructor.
        public ApplicationDirectoryMembershipCondition() {}

        // Implement the IMembership interface.
        [TODO]
        public bool Check(Evidence evidence)
                        {
                                // TODO
                                return true;
                        }
        public IMembershipCondition Copy()
                        {
                                return new 
ApplicationDirectoryMembershipCondition();
                        }
        public override bool Equals(Object obj)
                        {
                                return (obj is 
ApplicationDirectoryMembershipCondition);
                        }
        public override String ToString()
                        {
                                return _("Security_AppDirMembershipCondition");
                        }

        // Implement the ISecurityEncodable interface.
        public void FromXml(SecurityElement et)
                        {
                                FromXml(et, null);
                        }
        public SecurityElement ToXml()
                        {
                                return ToXml(null);
                        }

        // Implement the ISecurityPolicyEncodable interface.
        public void FromXml(SecurityElement et, PolicyLevel level)
                        {
                                if(et == null)
                                {
                                        throw new ArgumentNullException("et");
                                }
                                if(et.Tag != "IMembershipCondition")
                                {
                                        throw new ArgumentException
                                                (_("Security_PolicyName"));
                                }
                                if(et.Attribute("version") != "1")
                                {
                                        throw new ArgumentException
                                                (_("Security_PolicyVersion"));
                                }
                        }
        public SecurityElement ToXml(PolicyLevel level)
                        {
                                SecurityElement element;
                                element = new 
SecurityElement("IMembershipCondition");
                                element.AddAttribute
                                        ("class",
                                         SecurityElement.Escape
                                                
(typeof(ApplicationDirectoryMembershipCondition).
                                                                
AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                return element;
                        }

        // Get the hash code for this instance.
        public override int GetHashCode()
                        {
                                // All instances of this type are identical.
                                return GetType().GetHashCode();
                        }

}; // class ApplicationDirectoryMembershipCondition

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

--- NEW FILE ---
/*
 * CodeGroup.cs - Implementation of the
 *              "System.Security.Policy.CodeGroup" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

using System.Collections;

[Serializable]
public abstract class CodeGroup
{
        // Internal state.
        private IMembershipCondition membershipCondition;
        private PolicyStatement policy;
        private IList children;
        private String description;
        private String name;

        // Constructor.
        public CodeGroup(IMembershipCondition membershipCondition,
                                         PolicyStatement policy)
                        {
                                if(membershipCondition == null)
                                {
                                        throw new 
ArgumentNullException("membershipCondition");
                                }
                                this.membershipCondition = membershipCondition;
                                this.policy = policy;
                                this.children = new ArrayList();
                        }

        // Properties.
        public virtual String AttributeString
                        {
                                get
                                {
                                        // TODO
                                        return null;
                                }
                        }
        public IList Children
                        {
                                get
                                {
                                        return children;
                                }
                                set
                                {
                                        if(value == null)
                                        {
                                                throw new 
ArgumentNullException("value");
                                        }
                                        children = value;
                                }
                        }
        public String Description
                        {
                                get
                                {
                                        return description;
                                }
                                set
                                {
                                        description = value;
                                }
                        }
        public IMembershipCondition MembershipCondition
                        {
                                get
                                {
                                        return membershipCondition;
                                }
                                set
                                {
                                        if(value == null)
                                        {
                                                throw new 
ArgumentNullException("value");
                                        }
                                        membershipCondition = value;
                                }
                        }
        public abstract String MergeLogic { get; }
        public String Name
                        {
                                get
                                {
                                        return name;
                                }
                                set
                                {
                                        name = value;
                                }
                        }
        public virtual String PermissionSetName
                        {
                                get
                                {
                                        // TODO
                                        return null;
                                }
                        }
        public PolicyStatement PolicyStatement
                        {
                                get
                                {
                                        return policy;
                                }
                                set
                                {
                                        policy = value;
                                }
                        }

        // Add a child to this code group.
        public void AddChild(CodeGroup group)
                        {
                                if(group == null)
                                {
                                        throw new 
ArgumentNullException("group");
                                }
                                Children.Add(group);
                        }

        // Make a copy of this code group.
        public abstract CodeGroup Copy();

        // Create the XML form of this code group.
        public virtual void CreateXml(SecurityElement element, PolicyLevel 
level)
                        {
                                // Nothing to do in the base class.
                        }

        // Compare two code groups for equality.
        public override bool Equals(Object obj)
                        {
                                CodeGroup cg = (obj as CodeGroup);
                                if(cg != null)
                                {
                                        return Equals(cg, false);
                                }
                                else
                                {
                                        return false;
                                }
                        }
        public bool Equals(CodeGroup cg, bool compareChildren)
                        {
                                if(cg == null)
                                {
                                        return false;
                                }
                                if(Name != cg.Name || Description != 
cg.Description ||
                                   
!MembershipCondition.Equals(cg.MembershipCondition))
                                {
                                        return false;
                                }
                                if(compareChildren)
                                {
                                        IList list1 = Children;
                                        IList list2 = cg.Children;
                                        if(list1.Count != list2.Count)
                                        {
                                                return false;
                                        }
                                        int posn;
                                        for(posn = 0; posn < list1.Count; 
++posn)
                                        {
                                                
if(!((CodeGroup)(list1[posn])).Equals
                                                                
(((CodeGroup)(list2[posn])), true))
                                                {
                                                        return false;
                                                }
                                        }
                                }
                                return true;
                        }

        // Convert an XML security element into a code group.
        public void FromXml(SecurityElement et)
                        {
                                FromXml(et, null);
                        }
        public void FromXml(SecurityElement et, PolicyLevel level)
                        {
                                if(et == null)
                                {
                                        throw new ArgumentNullException("et");
                                }
                                if(et.Tag != "CodeGroup")
                                {
                                        throw new ArgumentException
                                                (_("Security_CodeGroupName"));
                                }
                                if(et.Attribute("version") != "1")
                                {
                                        throw new ArgumentException
                                                (_("Security_PolicyVersion"));
                                }
                                // TODO
                                ParseXml(et, level);
                        }

        // Get the hash code for this instance.
        public override int GetHashCode()
                        {
                                return membershipCondition.GetHashCode();
                        }

        // Remove a child from this code group.
        public void RemoveChild(CodeGroup group)
                        {
                                if(group == null)
                                {
                                        throw new 
ArgumentNullException("group");
                                }
                                if(!(Children.Contains(group)))
                                {
                                        throw new ArgumentException
                                                
(_("Security_NotCodeGroupChild"));
                                }
                        }

        // Resolve the policy for this code group.
        public abstract PolicyStatement Resolve(Evidence evidence);

        // Resolve code groups that match specific evidence.
        public abstract CodeGroup ResolveMatchingCodeGroups(Evidence evidence);

        // Convert a code group into an XML security element
        public SecurityElement ToXml()
                        {
                                return ToXml(null);
                        }
        public SecurityElement ToXml(PolicyLevel level)
                        {
                                SecurityElement element;
                                element = new SecurityElement("CodeGroup");
                                element.AddAttribute
                                        ("class",
                                         
SecurityElement.Escape(typeof(CodeGroup).
                                                                                
        AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                // TODO
                                CreateXml(element, level);
                                return element;
                        }

        // Parse the XML form of this code group.
        public virtual void ParseXml(SecurityElement element, PolicyLevel level)
                        {
                                // Nothing to do in the base class.
                        }

}; // class CodeGroup

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

--- NEW FILE ---
/*
 * IIdentityPermissionFactory.cs - Implementation of the
 *              "System.Security.Policy.IIdentityPermissionFactory" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

public interface IIdentityPermissionFactory
{

        // Create a new identity permission for the specified evidence.
        IPermission CreateIdentityPermission(Evidence evidence);

}; // interface IIdentityPermissionFactory

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

--- NEW FILE ---
/*
 * IMembershipCondition.cs - Implementation of the
 *              "System.Security.Policy.IMembershipCondition" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

public interface IMembershipCondition
        : ISecurityEncodable, ISecurityPolicyEncodable
{

        // Check to see if the evidence satisfies the membership condition.
        bool Check(Evidence evidence);

        // Make a copy of this object.
        IMembershipCondition Copy();

        // Determine if two membership conditions are equal.
        bool Equals(Object obj);

        // Convert this membership condition into a string.
        String ToString();

}; // interface IMembershipCondition

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

--- NEW FILE ---
/*
 * PolicyStatement.cs - Implementation of the
 *              "System.Security.Policy.PolicyStatement" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

[Serializable]
public sealed class PolicyStatement
        : ISecurityEncodable, ISecurityPolicyEncodable
{
        // Internal state.
        private PermissionSet permSet;
        private PolicyStatementAttribute attributes;

        // Constructors.
        public PolicyStatement(PermissionSet permSet)
                        : this(permSet, PolicyStatementAttribute.Nothing) {}
        public PolicyStatement(PermissionSet permSet,
                                                   PolicyStatementAttribute 
attributes)
                        {
                                this.permSet = permSet;
                                this.attributes = attributes;
                        }

        // Properties.
        public PolicyStatementAttribute Attributes
                        {
                                get
                                {
                                        return attributes;
                                }
                                set
                                {
                                        attributes = value;
                                }
                        }
        public String AttributeString
                        {
                                get
                                {
                                        // TODO
                                        return null;
                                }
                        }
        public PermissionSet PermissionSet
                        {
                                get
                                {
                                        return permSet;
                                }
                                set
                                {
                                        permSet = value;
                                }
                        }

        // Make a copy of this object.
        public PolicyStatement Copy()
                        {
                                return new PolicyStatement(permSet, attributes);
                        }

        // Implement the ISecurityEncodable interface.
        public void FromXml(SecurityElement et)
                        {
                                FromXml(et, null);
                        }
        public SecurityElement ToXml()
                        {
                                return ToXml(null);
                        }

        // Implement the ISecurityPolicyEncodable interface.
        public void FromXml(SecurityElement et, PolicyLevel level)
                        {
                                if(et == null)
                                {
                                        throw new ArgumentNullException("et");
                                }
                                if(et.Tag != "PolicyStatement")
                                {
                                        throw new ArgumentException
                                                (_("Security_PolicyName"));
                                }
                                if(et.Attribute("version") != "1")
                                {
                                        throw new ArgumentException
                                                (_("Security_PolicyVersion"));
                                }
                                // TODO
                        }
        public SecurityElement ToXml(PolicyLevel level)
                        {
                                SecurityElement element;
                                element = new 
SecurityElement("PolicyStatement");
                                element.AddAttribute
                                        ("class",
                                         
SecurityElement.Escape(typeof(PolicyStatement).
                                                                                
        AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                // TODO
                                return element;
                        }

}; // class PolicyStatement

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

--- NEW FILE ---
/*
 * PolicyStatementAttribute.cs - Implementation of the
 *              "System.Security.Policy.PolicyStatementAttribute" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Policy
{

#if !ECMA_COMPAT

[Flags]
[Serializable]
public enum PolicyStatementAttribute
{
        Nothing         = 0x0000,
        Exclusive       = 0x0001,
        LevelFinal      = 0x0002,
        All                     = 0x0003

}; // enum PolicyStatementAttribute

#endif // !ECMA_COMPAT

}; // namespace System.Security.Policy

Index: Evidence.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/Evidence.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Evidence.cs 1 Feb 2003 03:31:45 -0000       1.3
--- Evidence.cs 7 Apr 2003 09:58:38 -0000       1.4
***************
*** 2,6 ****
   * Evidence.cs - Implementation of the "System.Security.Policy.Evidence" 
class.
   *
!  * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
--- 2,6 ----
   * Evidence.cs - Implementation of the "System.Security.Policy.Evidence" 
class.
   *
!  * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
***************
*** 22,34 ****
  {
  
! [TODO]
! public class Evidence
  {
  
! // TODO
  
        public Evidence(Evidence e) {}
  
  }; // class Evidence
  
  }; // namespace System.Security.Policy
--- 22,367 ----
  {
  
! #if !ECMA_COMPAT
! 
! using System.Collections;
! using System.Security.Permissions;
! 
! [Serializable]
! public sealed class Evidence : ICollection, IEnumerable
  {
+       // Internal state.
+       private Object[] hostEvidence;
+       private Object[] assemblyEvidence;
+       private bool locked;
+ 
+       // Constructors.
+       public Evidence()
+                       {
+                               this.hostEvidence = null;
+                               this.assemblyEvidence = null;
+                       }
+       public Evidence(Evidence evidence)
+                       {
+                               if(evidence == null)
+                               {
+                                       throw new 
ArgumentNullException("evidence");
+                               }
+                               this.hostEvidence = evidence.hostEvidence;
+                               this.assemblyEvidence = 
evidence.assemblyEvidence;
+                       }
+       public Evidence(Object[] hostEvidence, Object[] assemblyEvidence)
+                       {
+                               this.hostEvidence = hostEvidence;
+                               this.assemblyEvidence = assemblyEvidence;
+                       }
+ 
+       // Implement the ICollection interface.
+       public void CopyTo(Array array, int index)
+                       {
+                               if(hostEvidence != null)
+                               {
+                                       foreach(Object o1 in hostEvidence)
+                                       {
+                                               array.SetValue(o1, index++);
+                                       }
+                               }
+                               if(assemblyEvidence != null)
+                               {
+                                       foreach(Object o2 in assemblyEvidence)
+                                       {
+                                               array.SetValue(o2, index++);
+                                       }
+                               }
+                       }
+       public int Count
+                       {
+                               get
+                               {
+                                       return ((hostEvidence != null) ? 
hostEvidence.Length : 0) +
+                                                  ((assemblyEvidence != null)
+                                                               ? 
assemblyEvidence.Length : 0);
+                               }
+                       }
+       public bool IsSynchronized
+                       {
+                               get
+                               {
+                                       return false;
+                               }
+                       }
+       public Object SyncRoot
+                       {
+                               get
+                               {
+                                       return this;
+                               }
+                       }
+ 
+       // Determine if this evidence set is read-only.
+       public bool IsReadOnly
+                       {
+                               get
+                               {
+                                       return false;
+                               }
+                       }
+ 
+       // Get or set the lock flag on this evidence list.
+       public bool Locked
+                       {
+                               get
+                               {
+                                       return locked;
+                               }
+                               set
+                               {
+                                       (new SecurityPermission
+                                               
(SecurityPermissionFlag.ControlEvidence)).Demand();
+                                       locked = value;
+                               }
+                       }
+ 
+       // Add to the assembly evidence list.
+       public void AddAssembly(Object id)
+                       {
+                               if(locked)
+                               {
+                                       (new SecurityPermission
+                                               
(SecurityPermissionFlag.ControlEvidence)).Demand();
+                               }
+                               if(id != null)
+                               {
+                                       if(assemblyEvidence == null)
+                                       {
+                                               assemblyEvidence = new Object 
[] {id};
+                                       }
+                                       else
+                                       {
+                                               Object[] newList =
+                                                       new Object 
[assemblyEvidence.Length + 1];
+                                               Array.Copy(assemblyEvidence, 0, 
newList, 0,
+                                                                  
assemblyEvidence.Length);
+                                               
newList[assemblyEvidence.Length] = id;
+                                               assemblyEvidence = newList;
+                                       }
+                               }
+                       }
+ 
+       // Add to the host evidence list.
+       public void AddHost(Object id)
+                       {
+                               if(locked)
+                               {
+                                       (new SecurityPermission
+                                               
(SecurityPermissionFlag.ControlEvidence)).Demand();
+                               }
+                               if(id != null)
+                               {
+                                       if(hostEvidence == null)
+                                       {
+                                               hostEvidence = new Object [] 
{id};
+                                       }
+                                       else
+                                       {
+                                               Object[] newList =
+                                                       new Object 
[hostEvidence.Length + 1];
+                                               Array.Copy(hostEvidence, 0, 
newList, 0,
+                                                                  
hostEvidence.Length);
+                                               newList[hostEvidence.Length] = 
id;
+                                               hostEvidence = newList;
+                                       }
+                               }
+                       }
+ 
+       // Implement the IEnumerable interface.
+       public IEnumerator GetEnumerator()
+                       {
+                               return new EvidenceEnumerator(this, true, true);
+                       }
+ 
+       // Enumerate the assembly evidence objects.
+       public IEnumerator GetAssemblyEnumerator()
+                       {
+                               return new EvidenceEnumerator(this, true, 
false);
+                       }
+ 
+       // Enumerate the host evidence objects.
+       public IEnumerator GetHostEnumerator()
+                       {
+                               return new EvidenceEnumerator(this, false, 
true);
+                       }
+ 
+       // Merge two object arrays.
+       private static Object[] Merge(Object[] list1, Object[] list2)
+                       {
+                               if(list1 == null)
+                               {
+                                       return list2;
+                               }
+                               else if(list2 == null)
+                               {
+                                       return list1;
+                               }
+                               Object[] newList = new Object [list1.Length + 
list2.Length];
+                               Array.Copy(list1, 0, newList, 0, list1.Length);
+                               Array.Copy(list2, 0, newList, list1.Length, 
list2.Length);
+                               return newList;
+                       }
  
!       // Merge another evidence set into this one.
!       public void Merge(Evidence evidence)
!                       {
!                               if(evidence == null)
!                               {
!                                       throw new 
ArgumentNullException("evidence");
!                               }
!                               if(locked)
!                               {
!                                       (new SecurityPermission
!                                               
(SecurityPermissionFlag.ControlEvidence)).Demand();
!                               }
!                               hostEvidence = Merge(hostEvidence, 
evidence.hostEvidence);
!                               assemblyEvidence =
!                                       Merge(assemblyEvidence, 
evidence.assemblyEvidence);
!                       }
  
+       // Get the number of hosts and assemblies.
+       private int HostCount
+                       {
+                               get
+                               {
+                                       if(hostEvidence != null)
+                                       {
+                                               return hostEvidence.Length;
+                                       }
+                                       else
+                                       {
+                                               return 0;
+                                       }
+                               }
+                       }
+       private int AssemblyCount
+                       {
+                               get
+                               {
+                                       if(assemblyEvidence != null)
+                                       {
+                                               return assemblyEvidence.Length;
+                                       }
+                                       else
+                                       {
+                                               return 0;
+                                       }
+                               }
+                       }
+ 
+       // Evidence enumerator class.
+       private sealed class EvidenceEnumerator : IEnumerator
+       {
+               // Internal state.
+               private Evidence evidence;
+               private bool enumHosts;
+               private bool enumAssemblies;
+               private int index;
+ 
+               // Constructor.
+               public EvidenceEnumerator(Evidence evidence, bool enumHosts,
+                                                                 bool 
enumAssemblies)
+                               {
+                                       this.evidence = evidence;
+                                       this.enumHosts = enumHosts;
+                                       this.enumAssemblies = enumAssemblies;
+                                       this.index = -1;
+                               }
+ 
+               // Implement the IEnumerator interface.
+               public bool MoveNext()
+                               {
+                                       ++index;
+                                       if(enumHosts && enumAssemblies)
+                                       {
+                                               return (index < evidence.Count);
+                                       }
+                                       else if(enumHosts)
+                                       {
+                                               return (index < 
evidence.HostCount);
+                                       }
+                                       else
+                                       {
+                                               return (index < 
evidence.AssemblyCount);
+                                       }
+                               }
+               public void Reset()
+                               {
+                                       index = -1;
+                               }
+               public Object Current
+                               {
+                                       get
+                                       {
+                                               if(enumHosts && enumAssemblies)
+                                               {
+                                                       if(index < 0)
+                                                       {
+                                                               throw new 
InvalidOperationException
+                                                                       
(_("Invalid_BadEnumertorPosition"));
+                                                       }
+                                                       else if(index < 
evidence.HostCount)
+                                                       {
+                                                               return 
evidence.hostEvidence[index];
+                                                       }
+                                                       else if(index < 
evidence.Count)
+                                                       {
+                                                               return 
evidence.assemblyEvidence
+                                                                       [index 
- evidence.HostCount];
+                                                       }
+                                                       else
+                                                       {
+                                                               throw new 
InvalidOperationException
+                                                                       
(_("Invalid_BadEnumertorPosition"));
+                                                       }
+                                               }
+                                               else if(enumHosts)
+                                               {
+                                                       if(index < 0 || index 
>= evidence.HostCount)
+                                                       {
+                                                               throw new 
InvalidOperationException
+                                                                       
(_("Invalid_BadEnumertorPosition"));
+                                                       }
+                                                       else
+                                                       {
+                                                               return 
evidence.hostEvidence[index];
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       if(index < 0 || index 
>= evidence.AssemblyCount)
+                                                       {
+                                                               throw new 
InvalidOperationException
+                                                                       
(_("Invalid_BadEnumertorPosition"));
+                                                       }
+                                                       else
+                                                       {
+                                                               return 
evidence.assemblyEvidence[index];
+                                                       }
+                                               }
+                                       }
+                               }
+ 
+       }; // class EvidenceEnumerator
+ 
+ }; // class Evidence
+ 
+ #else // ECMA_COMPAT
+ 
+ // Dummy class for ECMA compilation mode.
+ 
+ public sealed class Evidence
+ {
        public Evidence(Evidence e) {}
  
  }; // class Evidence
+ 
+ #endif // ECMA_COMPAT
  
  }; // namespace System.Security.Policy





reply via email to

[Prev in Thread] Current Thread [Next in Thread]