public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) { throw new ArgumentNullException("pset"); } if ((!Enum.IsDefined(typeof(SecurityAction), action) || (action == SecurityAction.RequestMinimum)) || ((action == SecurityAction.RequestOptional) || (action == SecurityAction.RequestRefuse))) { throw new ArgumentOutOfRangeException("action"); } if (this.m_methodBuilder.IsTypeCreated()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } byte[] blob = pset.EncodeXml(); TypeBuilder.AddDeclarativeSecurity(this.GetModuleBuilder().GetNativeHandle(), this.GetToken().Token, action, blob, blob.Length); }
public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) { throw new ArgumentNullException("pset"); } this.ThrowIfGeneric(); if ((!Enum.IsDefined(typeof(SecurityAction), action) || (action == SecurityAction.RequestMinimum)) || ((action == SecurityAction.RequestOptional) || (action == SecurityAction.RequestRefuse))) { throw new ArgumentOutOfRangeException("action"); } this.m_containingType.ThrowIfCreated(); byte[] blob = null; int cb = 0; if (!pset.IsEmpty()) { blob = pset.EncodeXml(); cb = blob.Length; } TypeBuilder.AddDeclarativeSecurity(this.m_module.GetNativeHandle(), this.MetadataTokenInternal, action, blob, cb); }
[System.Security.SecurityCritical] // auto-generated private void AddDeclarativeSecurityNoLock(SecurityAction action, PermissionSet pset) { if (pset == null) throw new ArgumentNullException("pset"); #pragma warning disable 618 if (!Enum.IsDefined(typeof(SecurityAction), action) || action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse) { throw new ArgumentOutOfRangeException("action"); } #pragma warning restore 618 Contract.EndContractBlock(); ThrowIfCreated(); // Translate permission set into serialized format(uses standard binary serialization format). byte[] blob = null; int length = 0; if (!pset.IsEmpty()) { blob = pset.EncodeXml(); length = blob.Length; } // Write the blob into the metadata. AddDeclarativeSecurity(m_module.GetNativeHandle(), m_tdType.Token, action, blob, length); }
[System.Security.SecuritySafeCritical] // auto-generated public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) throw new ArgumentNullException("pset"); #pragma warning disable 618 if (!Enum.IsDefined(typeof(SecurityAction), action) || action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse) { throw new ArgumentOutOfRangeException("action"); } #pragma warning restore 618 Contract.EndContractBlock(); // Cannot add declarative security after type is created. if (m_methodBuilder.IsTypeCreated()) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); // Translate permission set into serialized format (use standard binary serialization). byte[] blob = pset.EncodeXml(); // Write the blob into the metadata. TypeBuilder.AddDeclarativeSecurity(GetModuleBuilder().GetNativeHandle(), GetToken().Token, action, blob, blob.Length); }
public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { ThrowIfGeneric (); if (pset == null) throw new ArgumentNullException("pset"); if (!Enum.IsDefined(typeof(SecurityAction), action) || action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse ) throw new ArgumentOutOfRangeException("action"); // cannot declarative security after type is created m_containingType.ThrowIfCreated(); // Translate permission set into serialized format (uses standard binary serialization format). byte[] blob = null; if (!pset.IsEmpty()) blob = pset.EncodeXml(); // Write the blob into the metadata. TypeBuilder.InternalAddDeclarativeSecurity (m_module, MetadataTokenInternal, action, blob); }
[System.Security.SecurityCritical] // auto-generated private void AddDeclarativeSecurity(PermissionSet pset, SecurityAction action) { // Translate sets into internal encoding (uses standard binary serialization). byte[] blob = pset.EncodeXml(); AddDeclarativeSecurity(GetNativeHandle(), action, blob, blob.Length); }
// Internal routine used to create a temporary permission set (given a // set of security attribute classes as input) and return the serialized // version. May actually return two sets, split into CAS and non-CAS // variants. private static byte[] CreateSerialized(Object[] attrs, ref byte[] nonCasBlob) { // Create two new (empty) sets. PermissionSet casPset = new PermissionSet(false); PermissionSet nonCasPset = new PermissionSet(false); // Most security attributes generate a single permission. The // PermissionSetAttribute class generates an entire permission set we // need to merge, however. for (int i = 0; i < attrs.Length; i++) if (attrs[i] is PermissionSetAttribute) { PermissionSet pset = null; pset = ((PermissionSetAttribute)attrs[i]).CreatePermissionSet(); if (pset == null) { throw new ArgumentException( Environment.GetResourceString( "Argument_UnableToGeneratePermissionSet" ) ); } if (pset.m_normalPermSet != null) { for (int j = 0; j <= pset.m_normalPermSet.GetMaxUsedIndex(); ++j) { IPermission perm = (IPermission)pset.m_normalPermSet.GetItem(j); if (perm != null) { if (perm is CodeAccessPermission) casPset.AddPermission(perm); else nonCasPset.AddPermission(perm); } } } if (pset.IsUnrestricted()) casPset.SetUnrestricted(true); if (pset.m_unrestrictedPermSet != null) { for (int j = 0; j <= pset.m_unrestrictedPermSet.GetMaxUsedIndex(); ++j) { IPermission perm = (IPermission)pset.m_unrestrictedPermSet.GetItem(j); if (perm != null) { if (perm is CodeAccessPermission) casPset.AddPermission(perm); else nonCasPset.AddPermission(perm); } } } } else { IPermission perm = ((SecurityAttribute)attrs[i]).CreatePermission(); if (perm is CodeAccessPermission) casPset.AddPermission(perm); else nonCasPset.AddPermission(perm); } // Serialize the set(s). if (!nonCasPset.IsEmpty()) nonCasBlob = nonCasPset.EncodeXml(); return casPset.IsEmpty() ? null : casPset.EncodeXml(); }
// Internal routine. Called by native code to create a safe binary encoding // given an action. internal static byte[] GetSafePermissionSet(int action) { PermissionSet permSet; switch (action) { case (int)System.Security.Permissions.SecurityAction.Demand: case (int)System.Security.Permissions.SecurityAction.Deny: case (int)System.Security.Permissions.SecurityAction.LinkDemand: case (int)System.Security.Permissions.SecurityAction.InheritanceDemand: case (int)System.Security.Permissions.SecurityAction.RequestOptional: permSet = new PermissionSet(true); break; case (int)System.Security.Permissions.SecurityAction.PermitOnly: case (int)System.Security.Permissions.SecurityAction.Assert: case (int)System.Security.Permissions.SecurityAction.RequestMinimum: case (int)System.Security.Permissions.SecurityAction.RequestRefuse: permSet = new PermissionSet(false); break; default : BCLDebug.Assert(false, "false"); throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag")); } return permSet.EncodeXml(); }
private void AddDeclarativeSecurityNoLock(SecurityAction action, PermissionSet pset) { ThrowIfGeneric(); if (pset == null) throw new ArgumentNullException("pset"); if (!Enum.IsDefined(typeof(SecurityAction), action) || action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse ) throw new ArgumentOutOfRangeException("action"); ThrowIfCreated(); // Translate permission set into serialized format(uses standard binary serialization format). byte[] blob = null; if (!pset.IsEmpty()) blob = pset.EncodeXml(); // Write the blob into the metadata. InternalAddDeclarativeSecurity(m_module, m_tdType.Token, action, blob); }
// Add declarative security to the class. // /// <include file='doc\TypeBuilder.uex' path='docs/doc[@for="TypeBuilder.AddDeclarativeSecurity"]/*' /> public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { try { Enter(); BCLDebug.Log("DYNIL","## DYNIL LOGGING: TypeBuilder.AddDeclarativeSecurity( )"); if ((action < SecurityAction.Demand) || (action > SecurityAction.InheritanceDemand)) throw new ArgumentOutOfRangeException("action"); if (pset == null) throw new ArgumentNullException("pset"); ThrowIfCreated(); // Translate permission set into serialized format (uses standard binary serialization format). byte[] blob = null; if (!pset.IsEmpty()) blob = pset.EncodeXml(); // Write the blob into the metadata. InternalAddDeclarativeSecurity(m_module, m_tdType.Token, action, blob); } finally { Exit(); } }
// Add declarative security to the constructor. // /// <include file='doc\ConstructorBuilder.uex' path='docs/doc[@for="ConstructorBuilder.AddDeclarativeSecurity"]/*' /> public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if ((action < SecurityAction.Demand) || (action > SecurityAction.InheritanceDemand)) throw new ArgumentOutOfRangeException("action"); if (pset == null) throw new ArgumentNullException("pset"); // Cannot add declarative security after type is created. if (m_methodBuilder.IsTypeCreated()) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); // Translate permission set into serialized format (use standard binary serialization). byte[] blob = pset.EncodeXml(); // Write the blob into the metadata. TypeBuilder.InternalAddDeclarativeSecurity(GetModule(), GetToken().Token, action, blob); }