Exemplo n.º 1
0
        public void Intersect()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            StrongNameIdentityPermission intersect = (StrongNameIdentityPermission)snip.Intersect(null);

            Assert.IsNull(intersect, "snip N null");

            StrongNameIdentityPermission empty = new StrongNameIdentityPermission(PermissionState.None);

            intersect = (StrongNameIdentityPermission)snip.Intersect(empty);
#if NET_2_0
            Assert.IsNull(intersect, "snip N empty");
#else
            Compare(empty, intersect, "snip U empty");
#endif
            intersect = (StrongNameIdentityPermission)snip.Intersect(snip);
            Compare(snip, intersect, "snip U snip");

            StrongNameIdentityPermission samePk = new StrongNameIdentityPermission(blob, "novell", new Version(1, 2));
            intersect = (StrongNameIdentityPermission)snip.Intersect(samePk);
            Assert.IsNull(intersect, "(snip N samePk)");
            // strange, I would have expected a SNIP with the same public key...
        }
Exemplo n.º 2
0
        public void Intersect_DifferentPermissions()
        {
            StrongNameIdentityPermission a = new StrongNameIdentityPermission(PermissionState.None);
            SecurityPermission           b = new SecurityPermission(PermissionState.None);

            Assert.IsNull(a.Intersect(b));
        }
Exemplo n.º 3
0
    //</Snippet3>
    //<Snippet4>
    // Intersect creates and returns a new permission that is the intersection of the current
    // permission and the permission specified.
    private bool IntersectDemo()
    {
        bool returnValue = true;

        StrongNameIdentityPermission snIdPerm1, snIdPerm2, snIdPerm3;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
        snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", new Version("1.0.0.0"));

        try
        {
            snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Intersect(snIdPerm2);

            Console.WriteLine("The intersection of MyCompany.MyDepartment.*"
                              + "MyCompany.MyDepartment.MyFile is "
                              + ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());
        }
        catch (Exception e)
        {
            Console.WriteLine("An exception was thrown: " + e);
            returnValue = false;
        }

        return(returnValue);
    }
Exemplo n.º 4
0
        public static void StrongNameIdentityPermissionCallMethods()
        {
            StrongNameIdentityPermission snip  = new StrongNameIdentityPermission(new Permissions.PermissionState());
            StrongNameIdentityPermission snip2 = new StrongNameIdentityPermission(new Permissions.StrongNamePublicKeyBlob(new byte[1]), "test", new Version(1, 2));
            IPermission ip       = snip.Copy();
            IPermission ip2      = snip.Intersect(ip);
            bool        testbool = snip.IsSubsetOf(ip);

            ip2 = snip.Union(ip);
            SecurityElement se = new SecurityElement("");

            snip.FromXml(se);
            se = snip.ToXml();
        }
Exemplo n.º 5
0
 public static void StrongNameIdentityPermissionCallMethods()
 {
     StrongNameIdentityPermission snip = new StrongNameIdentityPermission(new Permissions.PermissionState());
     StrongNameIdentityPermission snip2 = new StrongNameIdentityPermission(new Permissions.StrongNamePublicKeyBlob(new byte[1]), "test", new System.Version(1, 2));
     IPermission ip = snip.Copy();
     IPermission ip2 = snip.Intersect(ip);
     bool testbool = snip.IsSubsetOf(ip);
     ip2 = snip.Union(ip);
     SecurityElement se = new SecurityElement("");
     snip.FromXml(se);
     se = snip.ToXml();
 }
Exemplo n.º 6
0
	// Intersect creates and returns a new permission that is the intersection of the current 
	// permission and the permission specified. 
	private bool IntersectDemo()
	{

		bool returnValue = true;

		StrongNameIdentityPermission snIdPerm1, snIdPerm2, snIdPerm3;

		snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
		snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", new Version("1.0.0.0"));

		try
		{

			snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Intersect(snIdPerm2);

			Console.WriteLine("The intersection of MyCompany.MyDepartment.*"
			+ "MyCompany.MyDepartment.MyFile is "
			+ ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());

		}
		catch (Exception e)
		{
			Console.WriteLine("An exception was thrown: " + e);
			returnValue = false;
		}

		return returnValue;

	}