Inheritance: System.Security.CodeAccessPermission
		public override IPermission Copy () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			if (x509 != null)
				p.Certificate = x509;
			return p;
		}
        public override IPermission Union(IPermission target)
        {
            PublisherIdentityPermission pip = Cast(target);

            if (pip == null)
            {
                return(Copy());
            }

            if ((x509 != null) && (pip.x509 != null))
            {
                if (x509.GetRawCertDataString() == pip.x509.GetRawCertDataString())
                {
                    return(new PublisherIdentityPermission(x509));                     // any cert would do
                }
            }
            else if ((x509 == null) && (pip.x509 != null))
            {
                return(new PublisherIdentityPermission(pip.x509));
            }
            else if ((x509 != null) && (pip.x509 == null))
            {
                return(new PublisherIdentityPermission(x509));
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. -or-The two permissions are not equal.</exception>
        public override IPermission Union(IPermission target)
        {
            PublisherIdentityPermission publisherIdentityPermission = this.Cast(target);

            if (publisherIdentityPermission == null)
            {
                return(this.Copy());
            }
            if (this.x509 != null && publisherIdentityPermission.x509 != null)
            {
                if (this.x509.GetRawCertDataString() == publisherIdentityPermission.x509.GetRawCertDataString())
                {
                    return(new PublisherIdentityPermission(this.x509));
                }
            }
            else
            {
                if (this.x509 == null && publisherIdentityPermission.x509 != null)
                {
                    return(new PublisherIdentityPermission(publisherIdentityPermission.x509));
                }
                if (this.x509 != null && publisherIdentityPermission.x509 == null)
                {
                    return(new PublisherIdentityPermission(this.x509));
                }
            }
            return(null);
        }
        /// <include file='doc\PublisherIdentityPermission.uex' path='docs/doc[@for="PublisherIdentityPermission.IsSubsetOf"]/*' />
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.m_certificate == null);
            }

            try
            {
                PublisherIdentityPermission operand = (PublisherIdentityPermission)target;

                if (this.m_certificate == null)
                {
                    return(true);
                }
                else if (operand.m_certificate == null)
                {
                    return(false);
                }
                else
                {
                    return(this.m_certificate.Equals(operand.m_certificate));
                }
            }
            catch (InvalidCastException)
            {
                throw new
                      ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }
        }
        /// <include file='doc\PublisherIdentityPermission.uex' path='docs/doc[@for="PublisherIdentityPermission.Union"]/*' />
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.m_certificate != null?this.Copy() : null);
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }

            PublisherIdentityPermission operand = (PublisherIdentityPermission)target;

            if (this.m_certificate == null)
            {
                return(operand.m_certificate != null?target.Copy() : null);
            }
            else if (operand.m_certificate == null || this.m_certificate.Equals(((PublisherIdentityPermission)target).m_certificate))
            {
                return(this.Copy());
            }
            else
            {
                return(null);
            }
        }
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                if (m_unrestricted)
                {
                    return(false);
                }
                if (m_certs == null)
                {
                    return(true);
                }
                if (m_certs.Length == 0)
                {
                    return(true);
                }
                return(false);
            }
            PublisherIdentityPermission that = target as PublisherIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            if (that.m_unrestricted)
            {
                return(true);
            }
            if (m_unrestricted)
            {
                return(false);
            }
            if (this.m_certs != null)
            {
                foreach (X509Certificate certThis in this.m_certs)
                {
                    bool bOK = false;
                    if (that.m_certs != null)
                    {
                        foreach (X509Certificate certThat in that.m_certs)
                        {
                            if (certThis.Equals(certThat))
                            {
                                bOK = true;
                                break;
                            }
                        }
                    }
                    if (!bOK)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 7
0
        /// <summary>Creates and returns an identical copy of the current permission.</summary>
        /// <returns>A copy of the current permission.</returns>
        public override IPermission Copy()
        {
            PublisherIdentityPermission publisherIdentityPermission = new PublisherIdentityPermission(PermissionState.None);

            if (this.x509 != null)
            {
                publisherIdentityPermission.Certificate = this.x509;
            }
            return(publisherIdentityPermission);
        }
        public override IPermission Copy()
        {
            PublisherIdentityPermission p = new PublisherIdentityPermission(PermissionState.None);

            if (x509 != null)
            {
                p.Certificate = x509;
            }
            return(p);
        }
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is <see langword="null" /> if the intersection is empty.</returns>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception>
        // Token: 0x060026D9 RID: 9945 RVA: 0x0008CEF8 File Offset: 0x0008B0F8
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            PublisherIdentityPermission publisherIdentityPermission = target as PublisherIdentityPermission;

            if (publisherIdentityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            if (this.m_unrestricted && publisherIdentityPermission.m_unrestricted)
            {
                return(new PublisherIdentityPermission(PermissionState.None)
                {
                    m_unrestricted = true
                });
            }
            if (this.m_unrestricted)
            {
                return(publisherIdentityPermission.Copy());
            }
            if (publisherIdentityPermission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_certs == null || publisherIdentityPermission.m_certs == null || this.m_certs.Length == 0 || publisherIdentityPermission.m_certs.Length == 0)
            {
                return(null);
            }
            ArrayList arrayList = new ArrayList();

            foreach (X509Certificate x509Certificate in this.m_certs)
            {
                foreach (X509Certificate other in publisherIdentityPermission.m_certs)
                {
                    if (x509Certificate.Equals(other))
                    {
                        arrayList.Add(new X509Certificate(x509Certificate));
                    }
                }
            }
            if (arrayList.Count == 0)
            {
                return(null);
            }
            return(new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
            });
        }
Esempio n. 10
0
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                if (!this.m_unrestricted)
                {
                    if (this.m_certs == null)
                    {
                        return(true);
                    }
                    if (this.m_certs.Length == 0)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            PublisherIdentityPermission permission = target as PublisherIdentityPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            if (!permission.m_unrestricted)
            {
                if (this.m_unrestricted)
                {
                    return(false);
                }
                if (this.m_certs != null)
                {
                    foreach (X509Certificate certificate in this.m_certs)
                    {
                        bool flag = false;
                        if (permission.m_certs != null)
                        {
                            foreach (X509Certificate certificate2 in permission.m_certs)
                            {
                                if (certificate.Equals(certificate2))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (!flag)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        /// <summary>创建并返回一个权限,该权限是当前权限和指定权限的交集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的交集。如果交集为空,则此新权限为 null。</returns>
        /// <param name="target">要与当前权限相交的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return((IPermission)null);
            }
            PublisherIdentityPermission identityPermission = target as PublisherIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.m_unrestricted && identityPermission.m_unrestricted)
            {
                return (IPermission) new PublisherIdentityPermission(PermissionState.None)
                       {
                           m_unrestricted = true
                       }
            }
            ;
            if (this.m_unrestricted)
            {
                return(identityPermission.Copy());
            }
            if (identityPermission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_certs == null || identityPermission.m_certs == null || (this.m_certs.Length == 0 || identityPermission.m_certs.Length == 0))
            {
                return((IPermission)null);
            }
            ArrayList arrayList = new ArrayList();

            foreach (X509Certificate mCert1 in this.m_certs)
            {
                foreach (X509Certificate mCert2 in identityPermission.m_certs)
                {
                    if (mCert1.Equals(mCert2))
                    {
                        arrayList.Add((object)new X509Certificate(mCert1));
                    }
                }
            }
            if (arrayList.Count == 0)
            {
                return((IPermission)null);
            }
            return((IPermission) new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
            });
        }
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            PublisherIdentityPermission that = target as PublisherIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            if (this.m_unrestricted && that.m_unrestricted)
            {
                PublisherIdentityPermission res = new PublisherIdentityPermission(PermissionState.None);
                res.m_unrestricted = true;
                return(res);
            }
            if (this.m_unrestricted)
            {
                return(that.Copy());
            }
            if (that.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_certs == null || that.m_certs == null || this.m_certs.Length == 0 || that.m_certs.Length == 0)
            {
                return(null);
            }
            ArrayList alCerts = new ArrayList();

            foreach (X509Certificate certThis in this.m_certs)
            {
                foreach (X509Certificate certThat in that.m_certs)
                {
                    if (certThis.Equals(certThat))
                    {
                        alCerts.Add(new X509Certificate(certThis));
                    }
                }
            }
            if (alCerts.Count == 0)
            {
                return(null);
            }
            PublisherIdentityPermission result = new PublisherIdentityPermission(PermissionState.None);

            result.m_certs = (X509Certificate[])alCerts.ToArray(typeof(X509Certificate));
            return(result);
        }
Esempio n. 13
0
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Intersect(IPermission target)
        {
            PublisherIdentityPermission publisherIdentityPermission = this.Cast(target);

            if (publisherIdentityPermission == null)
            {
                return(null);
            }
            if (this.x509 != null && publisherIdentityPermission.x509 != null && this.x509.GetRawCertDataString() == publisherIdentityPermission.x509.GetRawCertDataString())
            {
                return(new PublisherIdentityPermission(publisherIdentityPermission.x509));
            }
            return(null);
        }
Esempio n. 14
0
        private PublisherIdentityPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            PublisherIdentityPermission publisherIdentityPermission = target as PublisherIdentityPermission;

            if (publisherIdentityPermission == null)
            {
                CodeAccessPermission.ThrowInvalidPermission(target, typeof(PublisherIdentityPermission));
            }
            return(publisherIdentityPermission);
        }
        /// <summary>Creates and returns an identical copy of the current permission.</summary>
        /// <returns>A copy of the current permission.</returns>
        // Token: 0x060026D7 RID: 9943 RVA: 0x0008CDAC File Offset: 0x0008AFAC
        public override IPermission Copy()
        {
            PublisherIdentityPermission publisherIdentityPermission = new PublisherIdentityPermission(PermissionState.None);

            publisherIdentityPermission.m_unrestricted = this.m_unrestricted;
            if (this.m_certs != null)
            {
                publisherIdentityPermission.m_certs = new X509Certificate[this.m_certs.Length];
                for (int i = 0; i < this.m_certs.Length; i++)
                {
                    publisherIdentityPermission.m_certs[i] = ((this.m_certs[i] == null) ? null : new X509Certificate(this.m_certs[i]));
                }
            }
            return(publisherIdentityPermission);
        }
 public override IPermission Copy()
 {
     PublisherIdentityPermission permission = new PublisherIdentityPermission(PermissionState.None) {
         m_unrestricted = this.m_unrestricted
     };
     if (this.m_certs != null)
     {
         permission.m_certs = new X509Certificate[this.m_certs.Length];
         for (int i = 0; i < this.m_certs.Length; i++)
         {
             permission.m_certs[i] = (this.m_certs[i] == null) ? null : new X509Certificate(this.m_certs[i]);
         }
     }
     return permission;
 }
        /// <summary>创建并返回当前权限的相同副本。</summary>
        /// <returns>当前权限的副本。</returns>
        public override IPermission Copy()
        {
            PublisherIdentityPermission identityPermission = new PublisherIdentityPermission(PermissionState.None);

            identityPermission.m_unrestricted = this.m_unrestricted;
            if (this.m_certs != null)
            {
                identityPermission.m_certs = new X509Certificate[this.m_certs.Length];
                for (int index = 0; index < this.m_certs.Length; ++index)
                {
                    identityPermission.m_certs[index] = this.m_certs[index] == null ? (X509Certificate)null : new X509Certificate(this.m_certs[index]);
                }
            }
            return((IPermission)identityPermission);
        }
        //------------------------------------------------------
        //
        // CODEACCESSPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        // IPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------


        public override IPermission Copy()
        {
            PublisherIdentityPermission perm = new PublisherIdentityPermission(PermissionState.None);

            perm.m_unrestricted = m_unrestricted;
            if (this.m_certs != null)
            {
                perm.m_certs = new X509Certificate[this.m_certs.Length];
                int n;
                for (n = 0; n < this.m_certs.Length; n++)
                {
                    perm.m_certs[n] = (m_certs[n] == null ? null : new X509Certificate(m_certs[n]));
                }
            }
            return(perm);
        }
Esempio n. 19
0
        // helpers

        private PublisherIdentityPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            PublisherIdentityPermission pip = (target as PublisherIdentityPermission);

            if (pip == null)
            {
                ThrowInvalidPermission(target, typeof(PublisherIdentityPermission));
            }

            return(pip);
        }
Esempio n. 20
0
        public override IPermission Intersect(IPermission target)
        {
            PublisherIdentityPermission pip = Cast(target);

            if (pip == null)
            {
                return(null);
            }

            if ((x509 != null) && (pip.x509 != null))
            {
                if (x509.GetRawCertDataString() == pip.x509.GetRawCertDataString())
                {
                    return(new PublisherIdentityPermission(pip.x509));
                }
            }
            return(null);
        }
Esempio n. 21
0
        public override bool IsSubsetOf(IPermission target)
        {
            PublisherIdentityPermission pip = Cast(target);

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

            if (x509 == null)
            {
                return(true);
            }
            if (pip.x509 == null)
            {
                return(false);
            }
            return(x509.GetRawCertDataString() == pip.x509.GetRawCertDataString());
        }
		public void IsSubsetOfNull () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			Assert.IsTrue (!p1.IsSubsetOf (null), "IsSubsetOf(null)");
		}
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (p, "PublisherIdentityPermission(PermissionState.None)");
			PublisherIdentityPermission copy = (PublisherIdentityPermission)p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert.IsTrue (se.Attribute ("class").StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", se.Attribute("version"), "ToXml-version");
			Assert.AreEqual ("true", se.Attribute("Unrestricted"), "ToXml-Unrestricted");
			Assert.IsNull (p.Certificate, "Certificate==null");
			// and they aren't equals to None
			Assert.IsTrue (!p.Equals (new PublisherIdentityPermission (PermissionState.None)));
		}
		public void PermissionStateNone () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			AssertNotNull ("PublisherIdentityPermission(PermissionState.None)", p);
			PublisherIdentityPermission copy = (PublisherIdentityPermission) p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert ("ToXml-class", se.Attribute ("class").StartsWith (className));
			AssertEquals ("ToXml-version", "1", se.Attribute("version"));
			AssertNull ("ToXml-Unrestricted", se.Attribute("Unrestricted"));
			AssertNull ("Certificate==null", p.Certificate);
		}
		public void PermissionStateNone () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			Assert.IsNotNull (p, "PublisherIdentityPermission(PermissionState.None)");
			PublisherIdentityPermission copy = (PublisherIdentityPermission) p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert.IsTrue (se.Attribute ("class").StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", se.Attribute("version"), "ToXml-version");
			Assert.IsNull (se.Attribute("Unrestricted"), "ToXml-Unrestricted");
			Assert.IsNull (p.Certificate, "Certificate==null");
		}
        //------------------------------------------------------
        //
        // CODEACCESSPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        // IPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------


        public override IPermission Copy()
        {
            PublisherIdentityPermission perm = new PublisherIdentityPermission(PermissionState.None);
            perm.m_unrestricted = m_unrestricted;
            if(this.m_certs != null)
            {
                perm.m_certs = new X509Certificate[this.m_certs.Length];
                int n;
                for(n = 0; n < this.m_certs.Length; n++)
                    perm.m_certs[n] = (m_certs[n] == null ? null : new X509Certificate(m_certs[n]));
            }
            return perm;
        }
 public override IPermission Intersect(IPermission target)
 {
     if (target == null)
         return null;
     PublisherIdentityPermission that = target as PublisherIdentityPermission;
     if(that == null)
         throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
     if(this.m_unrestricted && that.m_unrestricted)
     {
         PublisherIdentityPermission res = new PublisherIdentityPermission(PermissionState.None);
         res.m_unrestricted = true;
         return res;
     }
     if(this.m_unrestricted)
         return that.Copy();
     if(that.m_unrestricted)
         return this.Copy();
     if(this.m_certs == null || that.m_certs == null || this.m_certs.Length == 0 || that.m_certs.Length == 0)
         return null;
     ArrayList alCerts = new ArrayList();
     foreach(X509Certificate certThis in this.m_certs)
     {
         foreach(X509Certificate certThat in that.m_certs)
         {
             if(certThis.Equals(certThat))
                 alCerts.Add(new X509Certificate(certThis));
         }
     }
     if(alCerts.Count == 0)
         return null;
     PublisherIdentityPermission result = new PublisherIdentityPermission(PermissionState.None);
     result.m_certs = (X509Certificate[])alCerts.ToArray(typeof(X509Certificate));
     return result;
 }
		public void PropertyCertificateNull () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			p.Certificate = null;
		}
		public void ConstructorCertificateNull () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (null);
		}
		public void Certificate () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);

			PublisherIdentityPermission p2 = new PublisherIdentityPermission (PermissionState.None);
			p2.Certificate = x509;

			Assert.AreEqual (p1.ToXml ().ToString (), p2.ToXml ().ToString (), "Certificate");
		}
		public void IsSubsetOf () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (PermissionState.None);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (PermissionState.None);
			Assert.IsTrue (p1.IsSubsetOf (p2), "None.IsSubsetOf(None)");
			PublisherIdentityPermission p3 = new PublisherIdentityPermission (x509);
			Assert.IsTrue (!p3.IsSubsetOf (p2), "Cert.IsSubsetOf(None)");
			Assert.IsTrue (p2.IsSubsetOf (p3), "None.IsSubsetOf(Cert)");
			PublisherIdentityPermission p4 = new PublisherIdentityPermission (x509);
			Assert.IsTrue (p3.IsSubsetOf (p4), "Cert.IsSubsetOf(Cert)");
			X509Certificate x2 = new X509Certificate (cert2);
			PublisherIdentityPermission p5 = new PublisherIdentityPermission (x2);
			Assert.IsTrue (!p5.IsSubsetOf (p3), "Cert2.IsSubsetOf(Cert)");
			Assert.IsTrue (!p3.IsSubsetOf (p5), "Cert.IsSubsetOf(Cert2)");
		}
		public void IsSubsetOfNull () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			Assert ("IsSubsetOf(null)", !p1.IsSubsetOf (null));
		}
		public void IsSubsetOfBadPermission () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted);
			Assert.IsTrue (p1.IsSubsetOf (fdp2), "IsSubsetOf(PublisherIdentityPermission)");
		}
		public void Union_DifferentCertificates ()
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			X509Certificate x2 = new X509Certificate (cert2);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (x2);
			IPermission p = p1.Union (p2);
			// new XML format is used to contain more than one X.509 certificate
			SecurityElement se = p.ToXml ();
			Assert.AreEqual (2, se.Children.Count, "Childs");
			Assert.AreEqual ((se.Children [0] as SecurityElement).Attribute ("X509v3Certificate"), p1.ToXml ().Attribute ("X509v3Certificate"), "Cert#1");
			Assert.AreEqual ((se.Children [1] as SecurityElement).Attribute ("X509v3Certificate"), p2.ToXml ().Attribute ("X509v3Certificate"), "Cert#2");
			// strangely it is still versioned as 'version="1"'.
			Assert.AreEqual ("1", se.Attribute ("version"), "Version");
		}
 /// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
 /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
 /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
 /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. -or-The two permissions are not equal.</exception>
 // Token: 0x060026DA RID: 9946 RVA: 0x0008D02C File Offset: 0x0008B22C
 public override IPermission Union(IPermission target)
 {
     if (target == null)
     {
         if ((this.m_certs == null || this.m_certs.Length == 0) && !this.m_unrestricted)
         {
             return(null);
         }
         return(this.Copy());
     }
     else
     {
         PublisherIdentityPermission publisherIdentityPermission = target as PublisherIdentityPermission;
         if (publisherIdentityPermission == null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
             {
                 base.GetType().FullName
             }));
         }
         if (this.m_unrestricted || publisherIdentityPermission.m_unrestricted)
         {
             return(new PublisherIdentityPermission(PermissionState.None)
             {
                 m_unrestricted = true
             });
         }
         if (this.m_certs == null || this.m_certs.Length == 0)
         {
             if (publisherIdentityPermission.m_certs == null || publisherIdentityPermission.m_certs.Length == 0)
             {
                 return(null);
             }
             return(publisherIdentityPermission.Copy());
         }
         else
         {
             if (publisherIdentityPermission.m_certs == null || publisherIdentityPermission.m_certs.Length == 0)
             {
                 return(this.Copy());
             }
             ArrayList arrayList = new ArrayList();
             foreach (X509Certificate value in this.m_certs)
             {
                 arrayList.Add(value);
             }
             foreach (X509Certificate x509Certificate in publisherIdentityPermission.m_certs)
             {
                 bool flag = false;
                 foreach (object obj in arrayList)
                 {
                     X509Certificate other = (X509Certificate)obj;
                     if (x509Certificate.Equals(other))
                     {
                         flag = true;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     arrayList.Add(x509Certificate);
                 }
             }
             return(new PublisherIdentityPermission(PermissionState.None)
             {
                 m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
             });
         }
     }
 }
		public void UnionWithBadPermission () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (PermissionState.None);
			EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.None);
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Union (ep2);
		}
Esempio n. 37
0
        /// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
        /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
        /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override bool IsSubsetOf(IPermission target)
        {
            PublisherIdentityPermission publisherIdentityPermission = this.Cast(target);

            return(publisherIdentityPermission != null && (this.x509 == null || (publisherIdentityPermission.x509 != null && this.x509.GetRawCertDataString() == publisherIdentityPermission.x509.GetRawCertDataString())));
        }
		public void IntersectWithNull () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			PublisherIdentityPermission p2 = null;
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Intersect (p2);
			Assert.IsNull (p3, "P1 N null == null");
		}
		public void PermissionStateUnrestricted () 
		{
			// Unrestricted isn't permitted for identity permissions
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.Unrestricted);
		}
		public void Intersect () 
		{
			// intersect None with None
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (PermissionState.None);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (PermissionState.None);
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Intersect (p2);
			Assert.IsNull (p3, "None N None == null");
			// with 1 certificate
			p1 = new PublisherIdentityPermission (x509);
			p2 = new PublisherIdentityPermission (PermissionState.None);
			p3 = (PublisherIdentityPermission) p1.Intersect (p2);
			Assert.IsNull (p3, "cert N None == None");
			// 2 different certificates
			X509Certificate x2 = new X509Certificate (cert2);
			p2 = new PublisherIdentityPermission (x2);
			p3 = (PublisherIdentityPermission) p1.Intersect (p2);
			Assert.IsNull (p3, "cert1 N cert2 == null");
			// 2 certificates (same)
			x2 = new X509Certificate (cert);
			p2 = new PublisherIdentityPermission (x2);
			p3 = (PublisherIdentityPermission) p1.Intersect (p2);
			Assert.AreEqual (p3.ToString (), p1.ToString (), "cert1 N cert1 == cert1");
		}
Esempio n. 41
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if (((this.m_certs == null) || (this.m_certs.Length == 0)) && !this.m_unrestricted)
                {
                    return(null);
                }
                return(this.Copy());
            }
            PublisherIdentityPermission permission = target as PublisherIdentityPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            if (this.m_unrestricted || permission.m_unrestricted)
            {
                return(new PublisherIdentityPermission(PermissionState.None)
                {
                    m_unrestricted = true
                });
            }
            if ((this.m_certs == null) || (this.m_certs.Length == 0))
            {
                if ((permission.m_certs != null) && (permission.m_certs.Length != 0))
                {
                    return(permission.Copy());
                }
                return(null);
            }
            if ((permission.m_certs == null) || (permission.m_certs.Length == 0))
            {
                return(this.Copy());
            }
            ArrayList list = new ArrayList();

            foreach (X509Certificate certificate in this.m_certs)
            {
                list.Add(certificate);
            }
            foreach (X509Certificate certificate2 in permission.m_certs)
            {
                bool flag = false;
                foreach (X509Certificate certificate3 in list)
                {
                    if (certificate2.Equals(certificate3))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    list.Add(certificate2);
                }
            }
            return(new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])list.ToArray(typeof(X509Certificate))
            });
        }
		public void IntersectWithBadPermission () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted);
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Intersect (fdp2);
		}
		public void FromXmlWrongVersion () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			SecurityElement se = p.ToXml ();
			// can't modify - so we create our own
			SecurityElement se2 = new SecurityElement (se.Tag, se.Text);
			se2.AddAttribute ("class", se.Attribute ("class"));
			se2.AddAttribute ("version", "2");
			p.FromXml (se2);
		}
 public override IPermission Union(IPermission target)
 {
     if (target == null)
     {
         if((this.m_certs == null || this.m_certs.Length == 0) && !this.m_unrestricted)
             return null;
         return this.Copy();
     }
     PublisherIdentityPermission that = target as PublisherIdentityPermission;
     if(that == null)
         throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
     if(this.m_unrestricted || that.m_unrestricted)
     {
         PublisherIdentityPermission res = new PublisherIdentityPermission(PermissionState.None);
         res.m_unrestricted = true;
         return res;
     }
     if (this.m_certs == null || this.m_certs.Length == 0)
     {
         if(that.m_certs == null || that.m_certs.Length == 0)
             return null;
         return that.Copy();
     }
     if(that.m_certs == null || that.m_certs.Length == 0)
         return this.Copy();
     ArrayList alCerts = new ArrayList();
     foreach(X509Certificate certThis in this.m_certs)
         alCerts.Add(certThis);
     foreach(X509Certificate certThat in that.m_certs)
     {
         bool bDupe = false;
         foreach(X509Certificate cert in alCerts)
         {
             if(certThat.Equals(cert))
             {
                 bDupe = true;
                 break;
             }
         }
         if(!bDupe)
             alCerts.Add(certThat);
     }
     PublisherIdentityPermission result = new PublisherIdentityPermission(PermissionState.None);
     result.m_certs = (X509Certificate[])alCerts.ToArray(typeof(X509Certificate));
     return result;
 }
        /// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns>
        /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -这两个权限不相等。</exception>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if ((this.m_certs == null || this.m_certs.Length == 0) && !this.m_unrestricted)
                {
                    return((IPermission)null);
                }
                return(this.Copy());
            }
            PublisherIdentityPermission identityPermission = target as PublisherIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.m_unrestricted || identityPermission.m_unrestricted)
            {
                return (IPermission) new PublisherIdentityPermission(PermissionState.None)
                       {
                           m_unrestricted = true
                       }
            }
            ;
            if (this.m_certs == null || this.m_certs.Length == 0)
            {
                if (identityPermission.m_certs == null || identityPermission.m_certs.Length == 0)
                {
                    return((IPermission)null);
                }
                return(identityPermission.Copy());
            }
            if (identityPermission.m_certs == null || identityPermission.m_certs.Length == 0)
            {
                return(this.Copy());
            }
            ArrayList arrayList = new ArrayList();

            foreach (X509Certificate mCert in this.m_certs)
            {
                arrayList.Add((object)mCert);
            }
            foreach (X509Certificate mCert in identityPermission.m_certs)
            {
                bool flag = false;
                foreach (X509Certificate other in arrayList)
                {
                    if (mCert.Equals(other))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    arrayList.Add((object)mCert);
                }
            }
            return((IPermission) new PublisherIdentityPermission(PermissionState.None)
            {
                m_certs = (X509Certificate[])arrayList.ToArray(typeof(X509Certificate))
            });
        }
		public void FromXml () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml()");
			p.FromXml (se);

			se.AddAttribute ("X509v3Certificate", x509.GetRawCertDataString ());
			p.FromXml (se);
			Assert.AreEqual (x509.GetCertHashString (), p.Certificate.GetCertHashString (), "CertificateHash");
		}
		public void UnionWithNull () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			PublisherIdentityPermission p2 = null;
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.AreEqual (p1.ToXml ().ToString (), p3.ToXml ().ToString (), "P1 U null == P1");
		}
		public void Union () 
		{
			// with no certificates
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (PermissionState.None);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (PermissionState.None);
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.IsNull (p3, "None U None == null");
			// with 1 certificate
			p1 = new PublisherIdentityPermission (x509);
			p2 = new PublisherIdentityPermission (PermissionState.None);
			p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.AreEqual (p3.ToXml ().ToString (), p1.ToXml ().ToString (), "cert U None == cert");
			X509Certificate x2 = new X509Certificate (cert2);
			// 2 certificates (same)
			x2 = new X509Certificate (cert);
			p2 = new PublisherIdentityPermission (x2);
			p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.AreEqual (p3.ToString (), p1.ToString (), "cert1 U cert1 == cert1");
		}
 /// <internalonly/>
 int IBuiltInPermission.GetTokenIndex()
 {
     return(PublisherIdentityPermission.GetTokenIndex());
 }
		public void Union_DifferentCertificates ()
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			X509Certificate x2 = new X509Certificate (cert2);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (x2);
			IPermission p = p1.Union (p2);
#if NET_2_0
			// new XML format is used to contain more than one X.509 certificate
			SecurityElement se = p.ToXml ();
			AssertEquals ("Childs", 2, se.Children.Count);
			AssertEquals ("Cert#1", (se.Children [0] as SecurityElement).Attribute ("X509v3Certificate"), p1.ToXml ().Attribute ("X509v3Certificate"));
			AssertEquals ("Cert#2", (se.Children [1] as SecurityElement).Attribute ("X509v3Certificate"), p2.ToXml ().Attribute ("X509v3Certificate"));
			// strangely it is still versioned as 'version="1"'.
			AssertEquals ("Version", "1", se.Attribute ("version"));
#else
			AssertNull ("cert1 U cert2 == null", p);
#endif
		}