Esempio n. 1
0
        private void Common(StrongNameMembershipCondition snmc)
        {
            Assert.IsFalse(snmc.Check(allEmpty), "Check(allEmpty)");
            Assert.IsFalse(snmc.Check(hostOther), "Check(hostOther)");
            Assert.IsFalse(snmc.Check(assemblyEcmaCorlibVersion), "Check(assemblyEcmaCorlibVersion)");
            Assert.IsFalse(snmc.Check(assemblyEcmaVersion), "Check(assemblyEcmaVersion)");
            Assert.IsFalse(snmc.Check(assemblyMsSystemSecurityVersion), "Check(assemblyMsSystemSecurityVersion)");
            Assert.IsFalse(snmc.Check(assemblyMsVersion), "Check(assemblyMsVersion)");
            Assert.IsFalse(snmc.Check(assemblyOther), "Check(assemblyOther)");

            StrongNameMembershipCondition copy = (StrongNameMembershipCondition)snmc.Copy();

            Assert.IsTrue(copy.Equals(snmc), "copy.Equals (snmc)");
            Assert.IsTrue(snmc.Equals(copy), "snmc.Equals (copy)");
            copy.Name    = null;
            copy.Version = null;
            bool original = ((snmc.Name == null) && (snmc.Version == null));

            Assert.AreEqual(original, copy.Equals(snmc), "bad.Equals (snmc)");
            Assert.AreEqual(original, snmc.Equals(copy), "snmc.Equals (bad)");

            SecurityElement se = snmc.ToXml();

            copy.FromXml(se);
            Assert.AreEqual(snmc.PublicKey, copy.PublicKey, "PublicKey");
            Assert.AreEqual(snmc.Name, copy.Name, "Name");
            Assert.AreEqual(snmc.Version, copy.Version, "Version");
            Assert.AreEqual(snmc.GetHashCode(), copy.GetHashCode(), "GetHashCode ()");
            Assert.AreEqual(snmc.ToString(), copy.ToString(), "ToString ()");
            Assert.IsTrue(copy.Equals(snmc), "xml.Equals (snmc)");
            Assert.IsTrue(snmc.Equals(copy), "snmc.Equals (xml)");
        }
        }// CreatePermissionSetFromAllPolicy

        internal static String BuildMCDisplayName(String sName)
        {
            String sOutString = sName;

            byte[] ab = new byte[16];
            StrongNameMembershipCondition snmc = new StrongNameMembershipCondition(
                new StrongNamePublicKeyBlob(ab), null, null);

            HashMembershipCondition hmc = new HashMembershipCondition(
                System.Security.Cryptography.HashAlgorithm.Create(), ab);

            String[] args   = sName.Split(new char[] { ' ' });
            String[] argsSN = snmc.ToString().Split(new char[] { ' ' });
            String[] argsH  = hmc.ToString().Split(new char[] { ' ' });
            if (args[0].Equals(argsSN[0]) || args[0].Equals(argsH[0]))
            {
                sOutString = args[0];
            }
            else if (args.Length == 3 && args[1].Equals("-"))
            {
                sOutString = args[0] + ": " + args[2];
            }

            return(sOutString);
        }// BuildMCDisplayName
Esempio n. 3
0
        public void StrongNameMembershipCondition_Mscorlib()
        {
            StrongNameMembershipCondition snmc = new StrongNameMembershipCondition(blob, name, version);

            Assert.AreEqual(blob, snmc.PublicKey, "PublicKey");
            Assert.AreEqual("mscorlib", snmc.Name, "Name");
            Assert.AreEqual(version, snmc.Version, "Version");
            Assert.AreEqual(blob.GetHashCode(), snmc.GetHashCode(), "GetHashCode ()");
            Assert.IsTrue(snmc.ToString().StartsWith("StrongName - 00000000000000000400000000000000 name = mscorlib version = "), "ToString ()");

            Assert.IsTrue(snmc.Check(hostEcmaCorlibVersion), "Check(hostEcmaCorlibVersion)");
            Assert.IsFalse(snmc.Check(hostEcmaVersion), "Check(hostEcmaVersion)");
            Assert.IsFalse(snmc.Check(hostMsSystemSecurityVersion), "Check(hostMsSystemSecurityVersion)");
            Assert.IsFalse(snmc.Check(hostMsVersion), "Check(hostMsVersion)");
            Common(snmc);
        }
Esempio n. 4
0
        public void StrongNameMembershipCondition_NullNameVersion()
        {
            StrongNameMembershipCondition snmc = new StrongNameMembershipCondition(blob, null, null);

            Assert.AreEqual(blob, snmc.PublicKey, "PublicKey");
            Assert.IsNull(snmc.Name, "Name");
            Assert.IsNull(snmc.Version, "Version");
            Assert.AreEqual(blob.GetHashCode(), snmc.GetHashCode(), "GetHashCode ()");
            Assert.AreEqual("StrongName - 00000000000000000400000000000000", snmc.ToString(), "ToString ()");

            Assert.IsTrue(snmc.Check(hostEcmaCorlibVersion), "Check(hostEcmaCorlibVersion)");
            Assert.IsTrue(snmc.Check(hostEcmaVersion), "Check(hostEcmaVersion)");
            Assert.IsFalse(snmc.Check(hostMsSystemSecurityVersion), "Check(hostMsSystemSecurityVersion)");
            Assert.IsFalse(snmc.Check(hostMsVersion), "Check(hostMsVersion)");
            Common(snmc);
        }
        public static void StrongNameMembershipConditionCallMethods()
        {
            StrongNameMembershipCondition snmc = new StrongNameMembershipCondition(new StrongNamePublicKeyBlob(new byte[1]), "test", new Version(0, 1));
            bool check = snmc.Check(new Evidence());
            IMembershipCondition obj = snmc.Copy();

            check = snmc.Equals(new object());
            int             hash = snmc.GetHashCode();
            string          str  = snmc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)FormatterServices.GetUninitializedObject(typeof(PolicyLevel));

            snmc.FromXml(se);
            snmc.FromXml(se, pl);
            se = snmc.ToXml();
            se = snmc.ToXml(pl);
        }