CreatePermission() public abstract method

public abstract CreatePermission ( ) : IPermission
return IPermission
コード例 #1
0
        public SecurityDeclaration FromByteArray(SecurityAction action, byte [] declaration, bool resolve)
        {
            SecurityDeclaration dec = new SecurityDeclaration(action);

#if !CF_1_0 && !CF_2_0
            dec.PermissionSet = new PermissionSet(SSP.PermissionState.None);

            if (declaration == null || declaration.Length == 0)
            {
                return(dec);
            }

            if (declaration[0] == 0x2e)
            {
                // new binary format introduced in 2.0
                int pos = 1;
                int start;
                int numattr = Utilities.ReadCompressedInteger(declaration, pos, out start);
                if (numattr == 0)
                {
                    return(dec);
                }

                BinaryReader br = new BinaryReader(new MemoryStream(declaration));
                for (int i = 0; i < numattr; i++)
                {
                    pos = start;
                    SSP.SecurityAttribute sa = CreateSecurityAttribute(action, br, declaration, pos, out start, resolve);
                    if (sa == null)
                    {
                        dec.Resolved = false;
                        dec.Blob     = declaration;
                        return(dec);
                    }

                    IPermission p = sa.CreatePermission();
                    dec.PermissionSet.AddPermission(p);
                }
            }
            else
            {
                Parser.LoadXml(Encoding.Unicode.GetString(declaration));
                try {
                    dec.PermissionSet.FromXml(Parser.ToXml());
                    dec.PermissionSet.ToXml();
                } catch {
                    dec.Resolved = false;
                    dec.Blob     = declaration;
                }
            }
#endif
            return(dec);
        }
コード例 #2
0
        private static IPermission CreatePermission(SecurityDeclaration declaration, Mono.Cecil.SecurityAttribute attribute)
        {
            Type type = Type.GetType(attribute.AttributeType.FullName);

            if (type == null)
            {
                throw new ArgumentException("attribute");
            }
            System.Security.Permissions.SecurityAttribute securityAttribute = SecurityDeclarationRocks.CreateSecurityAttribute(type, declaration);
            if (securityAttribute == null)
            {
                throw new InvalidOperationException();
            }
            SecurityDeclarationRocks.CompleteSecurityAttribute(securityAttribute, attribute);
            return(securityAttribute.CreatePermission());
        }