Beispiel #1
0
        // Create a permission object that corresponds to this attribute.
        public override IPermission CreatePermission()
        {
            X509Certificate certificate;

            if (Unrestricted)
            {
                throw new ArgumentException(_("Arg_PermissionState"));
            }
            else if (certFile == null && signedFile == null && cert == null)
            {
                return(new PublisherIdentityPermission
                           (PermissionState.None));
            }
            else if (cert != null)
            {
                certificate = new X509Certificate
                                  (StrongNamePublicKeyBlob.FromHex(cert));
            }
            else if (certFile != null)
            {
                certificate =
                    System.Security.Cryptography.X509Certificates
                    .X509Certificate.CreateFromCertFile(certFile);
            }
            else
            {
                certificate =
                    System.Security.Cryptography.X509Certificates
                    .X509Certificate.CreateFromSignedFile(signedFile);
            }
            return(new PublisherIdentityPermission(certificate));
        }
        // Convert an XML value into a permissions value.
        public override void FromXml(SecurityElement esd)
        {
            if (esd == null)
            {
                throw new ArgumentNullException("esd");
            }
            if (esd.Attribute("version") != "1")
            {
                throw new ArgumentException(_("Arg_PermissionVersion"));
            }
            String value = esd.Attribute("X509v3Certificate");

            if (value != null)
            {
                certificate = new X509Certificate
                                  (StrongNamePublicKeyBlob.FromHex(value));
            }
            else
            {
                certificate = null;
            }
        }