Inheritance: IBuiltInEvidence
		public void Check ()
		{
			ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
			Evidence e = null;
			Assert.IsFalse (ad.Check (e), "Check (null)");
			e = new Evidence ();
			Assert.IsFalse (ad.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (ad.Check (e), "Check (zone)");

			string codebase = Assembly.GetExecutingAssembly ().CodeBase;
			Url u = new Url (codebase);
			ApplicationDirectory adir = new ApplicationDirectory (codebase);

			e.AddHost (u);
			Assert.IsFalse (ad.Check (e), "Check (url-host)"); // not enough
			e.AddAssembly (adir);
			Assert.IsFalse (ad.Check (e), "Check (url-host+adir-assembly)");

			e = new Evidence ();
			e.AddHost (adir);
			Assert.IsFalse (ad.Check (e), "Check (adir-host)"); // not enough
			e.AddAssembly (u);
			Assert.IsFalse (ad.Check (e), "Check (url-assembly+adir-host)");

			e = new Evidence ();
			e.AddHost (u);
			e.AddHost (adir);
			Assert.IsTrue (ad.Check (e), "Check (url+adir host)"); // both!!
		}
        /// <summary>Determines whether the membership condition is satisfied by the specified evidence.</summary>
        /// <returns>true if the specified evidence satisfies the membership condition; otherwise, false.</returns>
        /// <param name="evidence">The evidence set against which to make the test. </param>
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }
            string      codeBase       = Assembly.GetCallingAssembly().CodeBase;
            Uri         uri            = new Uri(codeBase);
            Url         url            = new Url(codeBase);
            bool        flag           = false;
            bool        flag2          = false;
            IEnumerator hostEnumerator = evidence.GetHostEnumerator();

            while (hostEnumerator.MoveNext())
            {
                object obj = hostEnumerator.Current;
                if (!flag && obj is ApplicationDirectory)
                {
                    ApplicationDirectory applicationDirectory = obj as ApplicationDirectory;
                    string directory = applicationDirectory.Directory;
                    flag = (string.Compare(directory, 0, uri.ToString(), 0, directory.Length, true, CultureInfo.InvariantCulture) == 0);
                }
                else if (!flag2 && obj is Url)
                {
                    flag2 = url.Equals(obj);
                }
                if (flag && flag2)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
        // Token: 0x06002855 RID: 10325 RVA: 0x0009465C File Offset: 0x0009285C
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;
            if (evidence == null)
            {
                return(false);
            }
            ApplicationDirectory hostEvidence = evidence.GetHostEvidence <ApplicationDirectory>();
            Url hostEvidence2 = evidence.GetHostEvidence <Url>();

            if (hostEvidence != null && hostEvidence2 != null)
            {
                string text = hostEvidence.Directory;
                if (text != null && text.Length > 1)
                {
                    if (text[text.Length - 1] == '/')
                    {
                        text += "*";
                    }
                    else
                    {
                        text += "/*";
                    }
                    URLString operand = new URLString(text);
                    if (hostEvidence2.GetURLString().IsSubsetOf(operand))
                    {
                        usedEvidence = hostEvidence;
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#4
0
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = (object)null;
            if (evidence == null)
            {
                return(false);
            }
            ApplicationDirectory hostEvidence1 = evidence.GetHostEvidence <ApplicationDirectory>();
            Url hostEvidence2 = evidence.GetHostEvidence <Url>();

            if (hostEvidence1 != null && hostEvidence2 != null)
            {
                string directory = hostEvidence1.Directory;
                if (directory != null && directory.Length > 1)
                {
                    string    str       = directory;
                    int       index     = str.Length - 1;
                    URLString urlString = new URLString((int)str[index] != 47 ? directory + "/*" : directory + "*");
                    if (hostEvidence2.GetURLString().IsSubsetOf((SiteString)urlString))
                    {
                        usedEvidence = (object)hostEvidence1;
                        return(true);
                    }
                }
            }
            return(false);
        }
        // Implement the IMembership interface.
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }
            IEnumerator e = evidence.GetHostEnumerator();
            IEnumerator e2;

            while (e.MoveNext())
            {
                ApplicationDirectory appDir =
                    (e.Current as ApplicationDirectory);
                if (appDir != null)
                {
                    e2 = evidence.GetHostEnumerator();
                    while (e2.MoveNext())
                    {
                        Url url = (e2.Current as Url);
                        if (url != null)
                        {
                            if (Match(url.parser, appDir.Directory))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
 bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
 {
     usedEvidence = null;
     if (evidence != null)
     {
         ApplicationDirectory hostEvidence = evidence.GetHostEvidence <ApplicationDirectory>();
         Url url = evidence.GetHostEvidence <Url>();
         if ((hostEvidence != null) && (url != null))
         {
             string directory = hostEvidence.Directory;
             if ((directory != null) && (directory.Length > 1))
             {
                 if (directory[directory.Length - 1] == '/')
                 {
                     directory = directory + "*";
                 }
                 else
                 {
                     directory = directory + "/*";
                 }
                 URLString operand = new URLString(directory);
                 if (url.GetURLString().IsSubsetOf(operand))
                 {
                     usedEvidence = hostEvidence;
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
示例#7
0
        /// <include file='doc\ApplicationDirectory.uex' path='docs/doc[@for="ApplicationDirectory.Equals"]/*' />
        public override bool Equals(Object o)
        {
            if (o == null)
            {
                return(false);
            }

            if (o is ApplicationDirectory)
            {
                ApplicationDirectory appDir = (ApplicationDirectory)o;

                if (this.m_appDirectory == null)
                {
                    return(appDir.m_appDirectory == null);
                }
                else if (appDir.m_appDirectory == null)
                {
                    return(false);
                }
                else
                {
                    return(this.m_appDirectory.IsSubsetOf(appDir.m_appDirectory) && appDir.m_appDirectory.IsSubsetOf(this.m_appDirectory));
                }
            }
            return(false);
        }
示例#8
0
 public static void ApplicationDirectoryCallMethods()
 {
     ApplicationDirectory ad = new ApplicationDirectory("test");
     object obj = ad.Copy();
     bool check = ad.Equals(new object());
     int hash = ad.GetHashCode();
     string str = ad.ToString();
 }
示例#9
0
        /// <include file='doc\ApplicationDirectory.uex' path='docs/doc[@for="ApplicationDirectory.Copy"]/*' />
        public Object Copy()
        {
            ApplicationDirectory appDir = new ApplicationDirectory();

            appDir.m_appDirectory = this.m_appDirectory;

            return(appDir);
        }
示例#10
0
		public void ApplicationDirectory_String ()
		{
			ApplicationDirectory ad = new ApplicationDirectory ("mono");
#if NET_2_0
			Assert.AreEqual ("mono", ad.Directory, "Directory");
#else
			Assert.AreEqual ("file://MONO", ad.Directory, "Directory");
#endif
		}
        public override bool Equals(object o)
        {
            ApplicationDirectory directory = o as ApplicationDirectory;

            if (directory == null)
            {
                return(false);
            }
            return(this.m_appDirectory.Equals(directory.m_appDirectory));
        }
示例#12
0
        public override bool Equals(Object o)
        {
            ApplicationDirectory other = o as ApplicationDirectory;
            if (other == null)
            {
                return false;
            }

            return m_appDirectory.Equals(other.m_appDirectory);
        }
示例#13
0
        internal Evidence(char[] buffer)
        {
            int position = 0;
            while (position < buffer.Length)
            {
                switch (buffer[position++])
                {
                    case BuiltInEvidenceHelper.idApplicationDirectory:
                    {
                        IBuiltInEvidence ad = new ApplicationDirectory();
                        position = ad.InitFromBuffer(buffer, position);
                        AddAssembly(ad);
                        break;
                    }
                    case BuiltInEvidenceHelper.idStrongName:
                    {
                        IBuiltInEvidence sn = new StrongName();
                        position = sn.InitFromBuffer(buffer, position);
                        AddHost(sn);
                        break;
                    }
                    case BuiltInEvidenceHelper.idZone:
                    {
                        IBuiltInEvidence z = new Zone();
                        position = z.InitFromBuffer(buffer, position);
                        AddHost(z);
                        break;
                    }
                    case BuiltInEvidenceHelper.idUrl:
                    {
                        IBuiltInEvidence u = new Url();
                        position = u.InitFromBuffer(buffer, position);
                        AddHost(u);
                        break;
                    }
                    case BuiltInEvidenceHelper.idSite:
                    {
                        IBuiltInEvidence s = new Site();
                        position = s.InitFromBuffer(buffer, position);
                        AddHost(s);
                        break;
                    }
                    case BuiltInEvidenceHelper.idPermissionRequestEvidence:
                    {
                        IBuiltInEvidence pre = new PermissionRequestEvidence();
                        position = pre.InitFromBuffer(buffer, position);
                        AddHost(pre);
                        break;
                    }
                    default:
                        throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup"));

                } // switch
            } // while
        }
        //------------------------------------------------------
        //
        // IMEMBERSHIPCONDITION IMPLEMENTATION
        //
        //------------------------------------------------------

        /// <include file='doc\ApplicationDirectoryMembershipCondition.uex' path='docs/doc[@for="ApplicationDirectoryMembershipCondition.Check"]/*' />
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }

            IEnumerator enumerator = evidence.GetHostEnumerator();

            while (enumerator.MoveNext())
            {
                Object obj = enumerator.Current;

                if (obj is ApplicationDirectory)
                {
                    ApplicationDirectory dir = (ApplicationDirectory)obj;

                    IEnumerator innerEnumerator = evidence.GetHostEnumerator();

                    while (innerEnumerator.MoveNext())
                    {
                        Object innerObj = innerEnumerator.Current;

                        if (innerObj is Url)
                        {
                            // We need to add a wildcard at the end because IsSubsetOf
                            // keys off of it.

                            String appDir = dir.Directory;

                            if (appDir != null && appDir.Length > 1)
                            {
                                if (appDir[appDir.Length - 1] == '/')
                                {
                                    appDir += "*";
                                }
                                else
                                {
                                    appDir += "/*";
                                }

                                URLString appDirString = new URLString(appDir);

                                if (((Url)innerObj).GetURLString().IsSubsetOf(appDirString))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>Determines whether instances of the same type of an evidence object are equivalent.</summary>
        /// <returns>true if the two instances are equivalent; otherwise, false.</returns>
        /// <param name="o">An object of same type as the current evidence object. </param>
        public override bool Equals(object o)
        {
            ApplicationDirectory applicationDirectory = o as ApplicationDirectory;

            if (applicationDirectory != null)
            {
                this.ThrowOnInvalid(applicationDirectory.directory);
                return(this.directory == applicationDirectory.directory);
            }
            return(false);
        }
示例#16
0
        public override bool Equals(object other)
        {
            ApplicationDirectory compare = (other as ApplicationDirectory);

            if (compare != null)
            {
                // MS "by design" behaviour (see FDBK14362)
                ThrowOnInvalid(compare.directory);
                // no C14N or other mojo here (it's done elsewhere)
                return(directory == compare.directory);
            }
            return(false);
        }
示例#17
0
        // Methods
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }

            string codebase = Assembly.GetCallingAssembly().CodeBase;
            Uri    local    = new Uri(codebase);
            Url    ucode    = new Url(codebase);

            // *both* ApplicationDirectory and Url must be in *Host* evidences
            bool        adir = false;
            bool        url  = false;
            IEnumerator e    = evidence.GetHostEnumerator();

            while (e.MoveNext())
            {
                object o = e.Current;

                if (!adir && (o is ApplicationDirectory))
                {
                    ApplicationDirectory ad = (o as ApplicationDirectory);
                    string s = ad.Directory;
                    adir = (String.Compare(s, 0, local.ToString(), 0, s.Length, true, CultureInfo.InvariantCulture) == 0);
                }
                else if (!url && (o is Url))
                {
                    url = ucode.Equals(o);
                }

                // got both ?
                if (adir && url)
                {
                    return(true);
                }
            }
            return(false);
        }
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
            {
                return(false);
            }

            ApplicationDirectory dir = evidence.GetHostEvidence <ApplicationDirectory>();
            Url url = evidence.GetHostEvidence <Url>();

            if (dir != null && url != null)
            {
                // We need to add a wildcard at the end because IsSubsetOf keys off of it.
                String appDir = dir.Directory;

                if (appDir != null && appDir.Length > 1)
                {
                    if (appDir[appDir.Length - 1] == '/')
                    {
                        appDir += "*";
                    }
                    else
                    {
                        appDir += "/*";
                    }

                    URLString appDirString = new URLString(appDir);
                    if (url.GetURLString().IsSubsetOf(appDirString))
                    {
                        usedEvidence = dir;
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#19
0
		public void ToString_ ()
		{
			ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
			string ts = ad.ToString ();
			Assert.IsTrue (ts.StartsWith ("<System.Security.Policy.ApplicationDirectory"), "Tag");
			Assert.IsTrue (ts.IndexOf ("version=\"1\"") > 0, "Directory");
			Assert.IsTrue (ts.IndexOf ("<Directory>file://MONO</Directory>") > 0, "Directory");
		}
示例#20
0
		public void Copy ()
		{
			ApplicationDirectory ad = new ApplicationDirectory ("novell");
#if NET_2_0
			Assert.AreEqual ("novell", ad.Directory, "Directory");
#else
			Assert.AreEqual ("file://NOVELL", ad.Directory, "Directory");
#endif
			ApplicationDirectory copy = (ApplicationDirectory)ad.Copy ();
			Assert.IsTrue (ad.Equals (copy), "ad.Equals(copy)");
			Assert.IsTrue (copy.Equals (ad), "copy.Equals(ad)");
			Assert.IsFalse (Object.ReferenceEquals (ad, copy), "Copy");
			Assert.AreEqual (ad.GetHashCode (), copy.GetHashCode (), "GetHashCode");
			Assert.AreEqual (ad.ToString (), copy.ToString (), "ToString");
		}
示例#21
0
		public void ApplicationDirectory_FileUrl ()
		{
			ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
			Assert.AreEqual ("file://MONO", ad.Directory, "Directory");
		}
示例#22
0
		public void ApplicationDirectory_HttpUrl ()
		{
			ApplicationDirectory ad = new ApplicationDirectory ("http://www.go-mono.com/");
			Assert.AreEqual ("http://www.go-mono.com/", ad.Directory, "Directory");
		}
示例#23
0
		public void Equals_Invalid ()
		{
			// funny one
			string appdir = Invalid (true);
			// constructor is ok with an invalid path...
			ApplicationDirectory ad = new ApplicationDirectory (appdir);
			// we can copy it...
			ApplicationDirectory copy = (ApplicationDirectory)ad.Copy ();
			// we can't get it's hash code
			Assert.AreEqual (appdir.GetHashCode (), ad.GetHashCode (), "GetHashCode");
			// we can convert it to string...
			Assert.IsTrue (ad.ToString ().IndexOf (appdir) > 0, "ToString");
			// ... but it throws in Equals - with self!
			Assert.IsTrue (ad.Equals (ad), "Equals(self)");
		}
示例#24
0
     /// <include file='doc\ApplicationDirectory.uex' path='docs/doc[@for="ApplicationDirectory.Copy"]/*' />
     public Object Copy()
     {
         ApplicationDirectory appDir = new ApplicationDirectory();
 
         appDir.m_appDirectory = this.m_appDirectory;
 
         return appDir;
     }
        /// <summary>Determines whether instances of the same type of an evidence object are equivalent.</summary>
        /// <param name="o">An object of same type as the current evidence object. </param>
        /// <returns>
        ///     <see langword="true" /> if the two instances are equivalent; otherwise, <see langword="false" />.</returns>
        // Token: 0x0600284D RID: 10317 RVA: 0x00094594 File Offset: 0x00092794
        public override bool Equals(object o)
        {
            ApplicationDirectory applicationDirectory = o as ApplicationDirectory;

            return(applicationDirectory != null && this.m_appDirectory.Equals(applicationDirectory.m_appDirectory));
        }
示例#26
0
		public void GetHashCode_ ()
		{
			string linux = "/unix/path/mono";
			ApplicationDirectory ad1 = new ApplicationDirectory (linux);
#if NET_2_0
			Assert.AreEqual (linux, ad1.Directory);
			Assert.AreEqual (linux.GetHashCode (), ad1.GetHashCode (), "GetHashCode-Linux");
#else
			Assert.AreEqual ("file://UNIX/PATH/mono", ad1.Directory);
			Assert.AreEqual ("file://UNIX/PATH/mono".GetHashCode (), ad1.GetHashCode (), "GetHashCode-Linux");
#endif

			string windows = "\\windows\\path\\mono";
			ApplicationDirectory ad2 = new ApplicationDirectory (windows);
#if NET_2_0
			Assert.AreEqual (windows, ad2.Directory);
			Assert.AreEqual (windows.GetHashCode (), ad2.GetHashCode (), "GetHashCode-Windows");
#else
			Assert.AreEqual ("file://WINDOWS/PATH/mono", ad2.Directory);
			Assert.AreEqual ("file://WINDOWS/PATH/mono".GetHashCode (), ad2.GetHashCode (), "GetHashCode-Windows");
#endif
		}
示例#27
0
		public void Equals ()
		{
			ApplicationDirectory ad1 = new ApplicationDirectory ("mono");
			Assert.IsFalse (ad1.Equals (null), "Equals(null)");
			Assert.IsFalse (ad1.Equals (String.Empty), "Equals(String.Empty)");
			Assert.IsFalse (ad1.Equals ("mono"), "Equals(mono)");
			Assert.IsTrue (ad1.Equals (ad1), "Equals(self)");
			ApplicationDirectory ad2 = new ApplicationDirectory (ad1.Directory);
			Assert.IsTrue (ad1.Equals (ad2), "Equals(ad2)");
			Assert.IsTrue (ad2.Equals (ad1), "Equals(ad2)");
			ApplicationDirectory ad3 = new ApplicationDirectory ("..");
			Assert.IsFalse (ad2.Equals (ad3), "Equals(ad3)");
		}
示例#28
0
        internal Evidence(char[] buffer)
        {
            int position = 0;

            while (position < buffer.Length)
            {
                switch (buffer[position++])
                {
                case BuiltInEvidenceHelper.idApplicationDirectory:
                {
                    IBuiltInEvidence ad = new ApplicationDirectory();
                    position = ad.InitFromBuffer(buffer, position);
                    AddAssembly(ad);
                    break;
                }

                case BuiltInEvidenceHelper.idPublisher:
                {
                    IBuiltInEvidence p = new Publisher();
                    position = p.InitFromBuffer(buffer, position);
                    AddHost(p);
                    break;
                }

                case BuiltInEvidenceHelper.idStrongName:
                {
                    IBuiltInEvidence sn = new StrongName();
                    position = sn.InitFromBuffer(buffer, position);
                    AddHost(sn);
                    break;
                }

                case BuiltInEvidenceHelper.idZone:
                {
                    IBuiltInEvidence z = new Zone();
                    position = z.InitFromBuffer(buffer, position);
                    AddHost(z);
                    break;
                }

                case BuiltInEvidenceHelper.idUrl:
                {
                    IBuiltInEvidence u = new Url();
                    position = u.InitFromBuffer(buffer, position);
                    AddHost(u);
                    break;
                }

                case BuiltInEvidenceHelper.idSite:
                {
                    IBuiltInEvidence s = new Site();
                    position = s.InitFromBuffer(buffer, position);
                    AddHost(s);
                    break;
                }

                case BuiltInEvidenceHelper.idPermissionRequestEvidence:
                {
                    IBuiltInEvidence pre = new PermissionRequestEvidence();
                    position = pre.InitFromBuffer(buffer, position);
                    AddHost(pre);
                    break;
                }

                case BuiltInEvidenceHelper.idHash:
                {
                    IBuiltInEvidence h = new Hash();
                    position = h.InitFromBuffer(buffer, position);
                    AddHost(h);
                    break;
                }

                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup"));
                } // switch
            }     // while
        }
示例#29
0
		public void ApplicationDirectory_String ()
		{
			ApplicationDirectory ad = new ApplicationDirectory ("mono");
			Assert.AreEqual ("mono", ad.Directory, "Directory");
		}
示例#30
0
		public void ApplicationDirectory_GetRequiredSize ()
		{
			ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
			Assert.AreEqual (14, GetRequiredSize (ad, true), "GetRequiredSize-true");
			Assert.AreEqual (12, GetRequiredSize (ad, false), "GetRequiredSize-false");
			ad = new ApplicationDirectory ("file://NOVELL/mono");
			Assert.AreEqual (21, GetRequiredSize (ad, true), "GetRequiredSize-true-2");
			Assert.AreEqual (19, GetRequiredSize (ad, false), "GetRequiredSize-false-2");
		}
示例#31
0
		public void GetHashCode_ ()
		{
			string linux = "/unix/path/mono";
			ApplicationDirectory ad1 = new ApplicationDirectory (linux);
			Assert.AreEqual (linux, ad1.Directory);
			Assert.AreEqual (linux.GetHashCode (), ad1.GetHashCode (), "GetHashCode-Linux");

			string windows = "\\windows\\path\\mono";
			ApplicationDirectory ad2 = new ApplicationDirectory (windows);
			Assert.AreEqual (windows, ad2.Directory);
			Assert.AreEqual (windows.GetHashCode (), ad2.GetHashCode (), "GetHashCode-Windows");
		}