public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message) { SetErrorCode(__HResults.COR_E_HOSTPROTECTION); m_protected = protectedResources; m_demanded = demandedResources; }
public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message) { SetErrorCode(__HResults.COR_E_HOSTPROTECTION); m_protected = protectedResources; m_demanded = demandedResources; }
/// <summary>用指定的错误消息、受保护的主机资源和导致引发异常的主机资源初始化 <see cref="T:System.Security.HostProtectionException" /> 类的新实例。</summary> /// <param name="message">解释异常原因的错误信息。</param> /// <param name="protectedResources">枚举值的按位组合,这些值指定部分受信任的代码不可访问的主机资源。</param> /// <param name="demandedResources">枚举值的按位组合,这些值指定所需的主机资源。</param> public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message) { this.SetErrorCode(-2146232768); this.m_protected = protectedResources; this.m_demanded = demandedResources; }
private HostProtectionException(HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(SecurityException.GetResString("HostProtection_HostProtection")) { this.SetErrorCode(-2146232768); this.m_protected = protectedResources; this.m_demanded = demandedResources; }
// constructors public HostProtectionPermission (PermissionState state) { if (CheckPermissionState (state, true) == PermissionState.Unrestricted) _resources = HostProtectionResource.All; else _resources = HostProtectionResource.None; }
// Called from the VM to create a HP Exception private HostProtectionException(HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(SecurityException.GetResString("HostProtection_HostProtection")) { SetErrorCode(__HResults.COR_E_HOSTPROTECTION); m_protected = protectedResources; m_demanded = demandedResources; }
public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message) { HResult = E_HostProtection; ProtectedResources = protectedResources; DemandedResources = demandedResources; }
// Called from the VM to create a HP Exception private HostProtectionException(HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(SecurityException.GetResString("HostProtection_HostProtection")) { SetErrorCode(__HResults.COR_E_HOSTPROTECTION); m_protected = protectedResources; m_demanded = demandedResources; }
protected HostProtectionException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info==null) throw new ArgumentNullException("info"); m_protected = (HostProtectionResource)info.GetValue(ProtectedResourcesName, typeof(HostProtectionResource)); m_demanded = (HostProtectionResource)info.GetValue(DemandedResourcesName, typeof(HostProtectionResource)); }
protected HostProtectionException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException("info"); } this.m_protected = (HostProtectionResource)info.GetValue("ProtectedResources", typeof(HostProtectionResource)); this.m_demanded = (HostProtectionResource)info.GetValue("DemandedResources", typeof(HostProtectionResource)); }
public override IPermission Union(IPermission target) { if (target == null) return(this.Copy()); if(this.GetType() != target.GetType()) throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); HostProtectionResource newResources = (HostProtectionResource)((uint)this.m_resources | (uint)((HostProtectionPermission)target).m_resources); return new HostProtectionPermission(newResources); }
public override void FromXml(SecurityElement e) { // General validation in CodeAccessPermission CheckSecurityElement(e, "e", version, version); // Note: we do not (yet) care about the return value // as we only accept version 1 (min/max values) _resources = (HostProtectionResource)Enum.Parse( typeof(HostProtectionResource), e.Attribute("Resources")); }
protected HostProtectionException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException("info"); } Contract.EndContractBlock(); m_protected = (HostProtectionResource)info.GetValue(ProtectedResourcesName, typeof(HostProtectionResource)); m_demanded = (HostProtectionResource)info.GetValue(DemandedResourcesName, typeof(HostProtectionResource)); }
public HostProtectionPermission(PermissionState state) { if (CodeAccessPermission.CheckPermissionState(state, true) == PermissionState.Unrestricted) { this._resources = HostProtectionResource.All; } else { this._resources = HostProtectionResource.None; } }
public override void FromXml(SecurityElement esd) { CodeAccessPermission.ValidateElement( esd, this ); if (XMLUtil.IsUnrestricted( esd )) Resources = HostProtectionResource.All; else { String resources = esd.Attribute( "Resources" ); if (resources == null) Resources = HostProtectionResource.None; else Resources = (HostProtectionResource)Enum.Parse( typeof( HostProtectionResource ), resources ); } }
public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (this.GetType() != target.GetType()) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); } HostProtectionResource newResources = (HostProtectionResource)((uint)this.m_resources | (uint)((HostProtectionPermission)target).m_resources); return(new HostProtectionPermission(newResources)); }
public HostProtectionPermission(PermissionState state) { if (state == PermissionState.Unrestricted) { this.Resources = HostProtectionResource.All; } else { if (state != PermissionState.None) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState")); } this.Resources = HostProtectionResource.None; } }
// Token: 0x06002516 RID: 9494 RVA: 0x00087084 File Offset: 0x00085284 public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (base.GetType() != target.GetType()) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } HostProtectionResource resources = this.m_resources | ((HostProtectionPermission)target).m_resources; return(new HostProtectionPermission(resources)); }
// Token: 0x0600251A RID: 9498 RVA: 0x000871C0 File Offset: 0x000853C0 public override void FromXml(SecurityElement esd) { CodeAccessPermission.ValidateElement(esd, this); if (XMLUtil.IsUnrestricted(esd)) { this.Resources = HostProtectionResource.All; return; } string text = esd.Attribute("Resources"); if (text == null) { this.Resources = HostProtectionResource.None; return; } this.Resources = (HostProtectionResource)Enum.Parse(typeof(HostProtectionResource), text); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } if (this.GetType() != target.GetType()) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } HostProtectionResource newResources = (HostProtectionResource)((uint)this.m_resources & (uint)((HostProtectionPermission)target).m_resources); if (newResources == HostProtectionResource.None) { return(null); } return(new HostProtectionPermission(newResources)); }
public override void FromXml(SecurityElement esd) { CodeAccessPermission.ValidateElement(esd, (IPermission)this); if (XMLUtil.IsUnrestricted(esd)) { this.Resources = HostProtectionResource.All; } else { string str = esd.Attribute("Resources"); if (str == null) { this.Resources = HostProtectionResource.None; } else { this.Resources = (HostProtectionResource)Enum.Parse(typeof(HostProtectionResource), str); } } }
// Token: 0x06002517 RID: 9495 RVA: 0x000870EC File Offset: 0x000852EC public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } if (base.GetType() != target.GetType()) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } HostProtectionResource hostProtectionResource = this.m_resources & ((HostProtectionPermission)target).m_resources; if (hostProtectionResource == HostProtectionResource.None) { return(null); } return(new HostProtectionPermission(hostProtectionResource)); }
private bool DecodeXml(byte[] data, HostProtectionResource fullTrustOnlyResources, HostProtectionResource inaccessibleResources ) { if (data != null && data.Length > 0) { FromXml( new Parser( data, Tokenizer.ByteTokenEncoding.UnicodeTokens ).GetTopElement() ); } FilterHostProtectionPermissions(fullTrustOnlyResources, inaccessibleResources); // We call this method from unmanaged to code a set we are going to use declaratively. In // this case, all the lazy evaluation for partial policy resolution is wasted since we'll // need to decode all of these shortly to make the demand for whatever. Therefore, we // pay that price now so that we can calculate whether all the permissions in the set // implement the IUnrestrictedPermission interface (the common case) for use in some // unmanaged optimizations. DecodeAllPermissions(); return true; }
public HostProtectionException(string message, Exception e) : base(message, e) { m_protected = HostProtectionResource.None; m_demanded = HostProtectionResource.None; }
public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) { }
public override void FromXml(SecurityElement e) { CodeAccessPermission.CheckSecurityElement(e, "e", 1, 1); this._resources = (HostProtectionResource)((int)Enum.Parse(typeof(HostProtectionResource), e.Attribute("Resources"))); }
public HostProtectionPermission(HostProtectionResource resources) { this.Resources = this._resources; }
public HostProtectionException() : base() { m_protected = HostProtectionResource.None; m_demanded = HostProtectionResource.None; }
public HostProtectionException(string message) : base(message) { this.m_protected = HostProtectionResource.None; this.m_demanded = HostProtectionResource.None; }
internal void FilterHostProtectionPermissions(HostProtectionResource fullTrustOnly, HostProtectionResource inaccessible) { HostProtectionPermission.protectedResources = fullTrustOnly; HostProtectionPermission permission = (HostProtectionPermission) this.GetPermission(HostProtectionPermission.GetTokenIndex()); if (permission != null) { HostProtectionPermission perm = (HostProtectionPermission) permission.Intersect(new HostProtectionPermission(fullTrustOnly)); if (perm == null) { this.RemovePermission(typeof(HostProtectionPermission)); } else if (perm.Resources != permission.Resources) { this.SetPermission(perm); } } }
public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message) { this._protected = protectedResources; this._demanded = demandedResources; }
private static byte[] CreateSerialized(object[] attrs, bool serialize, ref byte[] nonCasBlob, out PermissionSet casPset, HostProtectionResource fullTrustOnlyResources, bool allowEmptyPermissionSets) { casPset = null; PermissionSet nonCasPset = null; for (int i = 0; i < attrs.Length; i++) { if (attrs[i] is PermissionSetAttribute) { PermissionSet permSet = ((PermissionSetAttribute) attrs[i]).CreatePermissionSet(); if (permSet == null) { throw new ArgumentException(Environment.GetResourceString("Argument_UnableToGeneratePermissionSet")); } PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(permSet); while (internal2.MoveNext()) { IPermission current = (IPermission) internal2.Current; MergePermission(current, serialize, ref casPset, ref nonCasPset); } if (casPset == null) { casPset = new PermissionSet(false); } if (permSet.IsUnrestricted()) { casPset.SetUnrestricted(true); } } else { MergePermission(((SecurityAttribute) attrs[i]).CreatePermission(), serialize, ref casPset, ref nonCasPset); } } if (casPset != null) { casPset.FilterHostProtectionPermissions(fullTrustOnlyResources, HostProtectionResource.None); casPset.ContainsNonCodeAccessPermissions(); if (allowEmptyPermissionSets && casPset.IsEmpty()) { casPset = null; } } if (nonCasPset != null) { nonCasPset.FilterHostProtectionPermissions(fullTrustOnlyResources, HostProtectionResource.None); nonCasPset.ContainsNonCodeAccessPermissions(); if (allowEmptyPermissionSets && nonCasPset.IsEmpty()) { nonCasPset = null; } } byte[] buffer = null; nonCasBlob = null; if (serialize) { if (casPset != null) { buffer = casPset.EncodeXml(); } if (nonCasPset != null) { nonCasBlob = nonCasPset.EncodeXml(); } } return buffer; }
private bool DecodeXml(byte[] data, HostProtectionResource fullTrustOnlyResources, HostProtectionResource inaccessibleResources) { if ((data != null) && (data.Length > 0)) { this.FromXml(new Parser(data, Tokenizer.ByteTokenEncoding.UnicodeTokens).GetTopElement()); } this.FilterHostProtectionPermissions(fullTrustOnlyResources, inaccessibleResources); this.DecodeAllPermissions(); return true; }
public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message) { base.SetErrorCode(-2146232768); this.m_protected = protectedResources; this.m_demanded = demandedResources; }
public HostProtectionException() { this.m_protected = HostProtectionResource.None; this.m_demanded = HostProtectionResource.None; }
public HostProtectionException(string message) : base(message) { this.m_protected = HostProtectionResource.None; this.m_demanded = HostProtectionResource.None; }
internal void FilterHostProtectionPermissions(HostProtectionResource fullTrustOnly, HostProtectionResource inaccessible) { HostProtectionPermission.protectedResources = fullTrustOnly; HostProtectionPermission hpp = (HostProtectionPermission)GetPermission(HostProtectionPermission.GetTokenIndex()); if(hpp == null) return; HostProtectionPermission newHpp = (HostProtectionPermission)hpp.Intersect(new HostProtectionPermission(fullTrustOnly)); if (newHpp == null) { #if FEATURE_CAS_POLICY RemovePermission(typeof(HostProtectionPermission)); #else // !FEATURE_CAS_POLICY RemovePermission(HostProtectionPermission.GetTokenIndex()); #endif // FEATURE_CAS_POLICY } else if (newHpp.Resources != hpp.Resources) { SetPermission(newHpp); } }
public override void FromXml (SecurityElement e) { // General validation in CodeAccessPermission CheckSecurityElement (e, "e", version, version); // Note: we do not (yet) care about the return value // as we only accept version 1 (min/max values) _resources = (HostProtectionResource) Enum.Parse ( typeof (HostProtectionResource), e.Attribute ("Resources")); }
[System.Security.SecurityCritical] // auto-generated #endif private static byte[] CreateSerialized(Object[] attrs, bool serialize, ref byte[] nonCasBlob, out PermissionSet casPset, HostProtectionResource fullTrustOnlyResources, bool allowEmptyPermissionSets) { // Create two new (empty) sets. casPset = null; PermissionSet nonCasPset = null; // 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++) { #pragma warning disable 618 Contract.Assert(i == 0 || ((SecurityAttribute)attrs[i]).m_action == ((SecurityAttribute)attrs[i - 1]).m_action, "Mixed SecurityActions"); #pragma warning restore 618 if (attrs[i] is PermissionSetAttribute) { PermissionSet pset = ((PermissionSetAttribute)attrs[i]).CreatePermissionSet(); if (pset == null) throw new ArgumentException( Environment.GetResourceString( "Argument_UnableToGeneratePermissionSet" ) ); PermissionSetEnumeratorInternal enumerator = new PermissionSetEnumeratorInternal(pset); while (enumerator.MoveNext()) { IPermission perm = (IPermission)enumerator.Current; MergePermission(perm, serialize, ref casPset, ref nonCasPset); } if(casPset == null) casPset = new PermissionSet(false); if (pset.IsUnrestricted()) casPset.SetUnrestricted(true); } else { #pragma warning disable 618 IPermission perm = ((SecurityAttribute)attrs[i]).CreatePermission(); #pragma warning restore 618 MergePermission(perm, serialize, ref casPset, ref nonCasPset); } } Contract.Assert(serialize || nonCasPset == null, "We shouldn't separate nonCAS permissions unless fSerialize is true"); // // Filter HostProtection permission. In the VM, some optimizations are done based upon these // declarative permission sets being NULL if they do not exist. When filtering the permission // set if we end up with an empty set, we can the permission set NULL rather than returning the // empty set in order to enable those optimizations. // if(casPset != null) { casPset.FilterHostProtectionPermissions(fullTrustOnlyResources, HostProtectionResource.None); casPset.ContainsNonCodeAccessPermissions(); // make sure all declarative PermissionSets are checked for non-CAS so we can just check the flag from native code if (allowEmptyPermissionSets && casPset.IsEmpty()) casPset = null; } if(nonCasPset != null) { nonCasPset.FilterHostProtectionPermissions(fullTrustOnlyResources, HostProtectionResource.None); nonCasPset.ContainsNonCodeAccessPermissions(); // make sure all declarative PermissionSets are checked for non-CAS so we can just check the flag from native code if (allowEmptyPermissionSets && nonCasPset.IsEmpty()) nonCasPset = null; } // Serialize the set(s). byte[] casBlob = null; nonCasBlob = null; #if FEATURE_CAS_POLICY if(serialize) { if(casPset != null) casBlob = casPset.EncodeXml(); if(nonCasPset != null) nonCasBlob = nonCasPset.EncodeXml(); } #else // FEATURE_CAS_POLICY Contract.Assert(!serialize, "Cannot serialize permission sets on CoreCLR"); #endif // FEATURE_CAS_POLICY return casBlob; }
public HostProtectionException() { this.m_protected = HostProtectionResource.None; this.m_demanded = HostProtectionResource.None; }
public HostProtectionException(string message, Exception e) : base(message, e) { m_protected = HostProtectionResource.None; m_demanded = HostProtectionResource.None; }
internal void FilterHostProtectionPermissions(HostProtectionResource fullTrustOnly, HostProtectionResource inaccessible) { HostProtectionPermission.protectedResources = fullTrustOnly; HostProtectionPermission hpp = (HostProtectionPermission)GetPermission(HostProtectionPermission.GetTokenIndex()); if(hpp == null) return; HostProtectionPermission newHpp = (HostProtectionPermission)hpp.Intersect(new HostProtectionPermission(fullTrustOnly)); if(newHpp == null) RemovePermission(PermissionToken.FindTokenByIndex(HostProtectionPermission.GetTokenIndex())); else if(newHpp.Resources != hpp.Resources) SetPermission(newHpp); }
/// <summary>Initializes a new instance of the <see cref="T:System.Security.HostProtectionException" /> class with a specified error message, the protected host resources, and the host resources that caused the exception to be thrown.</summary><param name="message">The error message that explains the reason for the exception.</param><param name="protectedResources">A bitwise combination of the enumeration values that specify the host resources that are inaccessible to partially trusted code.</param><param name="demandedResources">A bitwise combination of the enumeration values that specify the demanded host resources.</param> public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) { throw new NotImplementedException(); }
private HostProtectionException(HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(SecurityException.GetResString("HostProtection_HostProtection")) { base.SetErrorCode(-2146232768); this.m_protected = protectedResources; this.m_demanded = demandedResources; }
public HostProtectionPermission (HostProtectionResource resources) { // reuse validation by the Flags property Resources = _resources; }
public void Properties() { HostProtectionAttribute hpa = new HostProtectionAttribute(SecurityAction.LinkDemand); HostProtectionResource expected = HostProtectionResource.None; Assert.AreEqual(expected, hpa.Resources, "None"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-1"); hpa.ExternalProcessMgmt = true; expected |= HostProtectionResource.ExternalProcessMgmt; Assert.AreEqual(expected, hpa.Resources, "+ExternalProcessMgmt"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-2"); hpa.ExternalThreading = true; expected |= HostProtectionResource.ExternalThreading; Assert.AreEqual(expected, hpa.Resources, "+ExternalThreading"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-3"); hpa.MayLeakOnAbort = true; expected |= HostProtectionResource.MayLeakOnAbort; Assert.AreEqual(expected, hpa.Resources, "+MayLeakOnAbort"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-4"); hpa.SecurityInfrastructure = true; expected |= HostProtectionResource.SecurityInfrastructure; Assert.AreEqual(expected, hpa.Resources, "+SecurityInfrastructure"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-5"); hpa.SelfAffectingProcessMgmt = true; expected |= HostProtectionResource.SelfAffectingProcessMgmt; Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingProcessMgmt"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-6"); hpa.SelfAffectingThreading = true; expected |= HostProtectionResource.SelfAffectingThreading; Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingThreading"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-7"); hpa.SharedState = true; expected |= HostProtectionResource.SharedState; Assert.AreEqual(expected, hpa.Resources, "+SharedState"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-8"); hpa.Synchronization = true; expected |= HostProtectionResource.Synchronization; Assert.AreEqual(expected, hpa.Resources, "+Synchronization"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-9"); hpa.UI = true; expected |= HostProtectionResource.UI; Assert.AreEqual(expected, hpa.Resources, "+UI"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted"); hpa.ExternalProcessMgmt = false; expected &= ~HostProtectionResource.ExternalProcessMgmt; Assert.AreEqual(expected, hpa.Resources, "-ExternalProcessMgmt"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-10"); hpa.ExternalThreading = false; expected &= ~HostProtectionResource.ExternalThreading; Assert.AreEqual(expected, hpa.Resources, "+ExternalThreading"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-11"); hpa.MayLeakOnAbort = false; expected &= ~HostProtectionResource.MayLeakOnAbort; Assert.AreEqual(expected, hpa.Resources, "+MayLeakOnAbort"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-12"); hpa.SecurityInfrastructure = false; expected &= ~HostProtectionResource.SecurityInfrastructure; Assert.AreEqual(expected, hpa.Resources, "+SecurityInfrastructure"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-13"); hpa.SelfAffectingProcessMgmt = false; expected &= ~HostProtectionResource.SelfAffectingProcessMgmt; Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingProcessMgmt"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-14"); hpa.SelfAffectingThreading = false; expected &= ~HostProtectionResource.SelfAffectingThreading; Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingThreading"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-15"); hpa.SharedState = false; expected &= ~HostProtectionResource.SharedState; Assert.AreEqual(expected, hpa.Resources, "+SharedState"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-16"); hpa.Synchronization = false; expected &= ~HostProtectionResource.Synchronization; Assert.AreEqual(expected, hpa.Resources, "+Synchronization"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-17"); hpa.UI = false; expected &= ~HostProtectionResource.UI; Assert.AreEqual(expected, hpa.Resources, "+UI"); Assert.IsFalse(hpa.Unrestricted, "Unrestricted-18"); }
public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) { }
public HostProtectionException() : base() { m_protected = HostProtectionResource.None; m_demanded = HostProtectionResource.None; }
public HostProtectionPermission(HostProtectionResource resources) { Resources = resources; }
public HostProtectionPermission(HostProtectionResource resources) { // reuse validation by the Flags property Resources = _resources; }
public HostProtectionException (string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base (message) { this._protected = protectedResources; this._demanded = demandedResources; }
private static byte[] CreateSerialized(Object[] attrs, bool serialize, ref byte[] nonCasBlob, out PermissionSet casPset, HostProtectionResource fullTrustOnlyResources) { // Create two new (empty) sets. casPset = null; PermissionSet nonCasPset = null; // 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++) { BCLDebug.Assert(i == 0 || ((SecurityAttribute)attrs[i]).m_action == ((SecurityAttribute)attrs[i - 1]).m_action, "Mixed SecurityActions"); if (attrs[i] is PermissionSetAttribute) { PermissionSet pset = ((PermissionSetAttribute)attrs[i]).CreatePermissionSet(); if (pset == null) throw new ArgumentException( Environment.GetResourceString( "Argument_UnableToGeneratePermissionSet" ) ); PermissionSetEnumeratorInternal enumerator = new PermissionSetEnumeratorInternal(pset); while (enumerator.MoveNext()) { IPermission perm = (IPermission)enumerator.Current; MergePermission(perm, serialize, ref casPset, ref nonCasPset); } if(casPset == null) casPset = new PermissionSet(false); if (pset.IsUnrestricted()) casPset.SetUnrestricted(true); } else { IPermission perm = ((SecurityAttribute)attrs[i]).CreatePermission(); MergePermission(perm, serialize, ref casPset, ref nonCasPset); } } BCLDebug.Assert(serialize || nonCasPset == null, "We shouldn't separate nonCAS permissions unless fSerialize is true"); // Filter HostProtection permission if(casPset != null) { casPset.FilterHostProtectionPermissions(fullTrustOnlyResources, HostProtectionResource.None); casPset.ContainsNonCodeAccessPermissions(); // make sure all declarative PermissionSets are checked for non-CAS so we can just check the flag from native code } if(nonCasPset != null) { nonCasPset.FilterHostProtectionPermissions(fullTrustOnlyResources, HostProtectionResource.None); nonCasPset.ContainsNonCodeAccessPermissions(); // make sure all declarative PermissionSets are checked for non-CAS so we can just check the flag from native code } // Serialize the set(s). byte[] casBlob = null; nonCasBlob = null; if(serialize) { if(casPset != null) casBlob = casPset.EncodeXml(); if(nonCasPset != null) nonCasBlob = nonCasPset.EncodeXml(); } return casBlob; }