236 lines
12 KiB
C#
236 lines
12 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Security.Permissions
|
|
{
|
|
/// <summary>Controls the ability to access key containers. This class cannot be inherited.</summary>
|
|
// Token: 0x02000554 RID: 1364
|
|
[ComVisible(true)]
|
|
[Serializable]
|
|
public sealed class KeyContainerPermission : CodeAccessPermission, IBuiltInPermission, IUnrestrictedPermission
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.KeyContainerPermission" /> class with either restricted or unrestricted permission.</summary>
|
|
/// <param name="state">One of the <see cref="T:System.Security.Permissions.PermissionState" /> values. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="state" /> is not a valid <see cref="T:System.Security.Permissions.PermissionState" /> value. </exception>
|
|
// Token: 0x060031C8 RID: 12744 RVA: 0x000AB2B0 File Offset: 0x000A94B0
|
|
public KeyContainerPermission(PermissionState state)
|
|
{
|
|
if (CodeAccessPermission.CheckPermissionState(state, true) == PermissionState.Unrestricted)
|
|
{
|
|
this._flags = KeyContainerPermissionFlags.AllFlags;
|
|
}
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.KeyContainerPermission" /> class with the specified access.</summary>
|
|
/// <param name="flags">A bitwise combination of the <see cref="T:System.Security.Permissions.KeyContainerPermissionFlags" /> values. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="flags" /> is not a valid combination of the <see cref="T:System.Security.Permissions.KeyContainerPermissionFlags" /> values. </exception>
|
|
// Token: 0x060031C9 RID: 12745 RVA: 0x000AB2D0 File Offset: 0x000A94D0
|
|
public KeyContainerPermission(KeyContainerPermissionFlags flags)
|
|
{
|
|
this.SetFlags(flags);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.KeyContainerPermission" /> class with the specified global access and specific key container access rights.</summary>
|
|
/// <param name="flags">A bitwise combination of the <see cref="T:System.Security.Permissions.KeyContainerPermissionFlags" /> values. </param>
|
|
/// <param name="accessList">An array of <see cref="T:System.Security.Permissions.KeyContainerPermissionAccessEntry" /> objects identifying specific key container access rights. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="flags" /> is not a valid combination of the <see cref="T:System.Security.Permissions.KeyContainerPermissionFlags" /> values. </exception>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="accessList" /> is null. </exception>
|
|
// Token: 0x060031CA RID: 12746 RVA: 0x000AB2E0 File Offset: 0x000A94E0
|
|
public KeyContainerPermission(KeyContainerPermissionFlags flags, KeyContainerPermissionAccessEntry[] accessList)
|
|
{
|
|
this.SetFlags(flags);
|
|
if (accessList != null)
|
|
{
|
|
foreach (KeyContainerPermissionAccessEntry keyContainerPermissionAccessEntry in accessList)
|
|
{
|
|
this._accessEntries.Add(keyContainerPermissionAccessEntry);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060031CB RID: 12747 RVA: 0x000AB328 File Offset: 0x000A9528
|
|
int IBuiltInPermission.GetTokenIndex()
|
|
{
|
|
return 16;
|
|
}
|
|
|
|
/// <summary>Gets the collection of <see cref="T:System.Security.Permissions.KeyContainerPermissionAccessEntry" /> objects associated with the current permission.</summary>
|
|
/// <returns>A <see cref="T:System.Security.Permissions.KeyContainerPermissionAccessEntryCollection" /> containing the <see cref="T:System.Security.Permissions.KeyContainerPermissionAccessEntry" /> objects for this <see cref="T:System.Security.Permissions.KeyContainerPermission" />.</returns>
|
|
// Token: 0x170009BE RID: 2494
|
|
// (get) Token: 0x060031CC RID: 12748 RVA: 0x000AB32C File Offset: 0x000A952C
|
|
public KeyContainerPermissionAccessEntryCollection AccessEntries
|
|
{
|
|
get
|
|
{
|
|
return this._accessEntries;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the key container permission flags that apply to all key containers associated with the permission.</summary>
|
|
/// <returns>A bitwise combination of the <see cref="T:System.Security.Permissions.KeyContainerPermissionFlags" /> values.</returns>
|
|
// Token: 0x170009BF RID: 2495
|
|
// (get) Token: 0x060031CD RID: 12749 RVA: 0x000AB334 File Offset: 0x000A9534
|
|
public KeyContainerPermissionFlags Flags
|
|
{
|
|
get
|
|
{
|
|
return this._flags;
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates and returns an identical copy of the current permission.</summary>
|
|
/// <returns>A copy of the current permission.</returns>
|
|
// Token: 0x060031CE RID: 12750 RVA: 0x000AB33C File Offset: 0x000A953C
|
|
public override IPermission Copy()
|
|
{
|
|
if (this._accessEntries.Count == 0)
|
|
{
|
|
return new KeyContainerPermission(this._flags);
|
|
}
|
|
KeyContainerPermissionAccessEntry[] array = new KeyContainerPermissionAccessEntry[this._accessEntries.Count];
|
|
this._accessEntries.CopyTo(array, 0);
|
|
return new KeyContainerPermission(this._flags, array);
|
|
}
|
|
|
|
/// <summary>Reconstructs a permission with a specified state from an XML encoding.</summary>
|
|
/// <param name="securityElement">A <see cref="T:System.Security.SecurityElement" /> that contains the XML encoding used to reconstruct the permission. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="securityElement" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="securityElement" /> is not a valid permission element.-or- The version number of <paramref name="securityElement" /> is not supported. </exception>
|
|
// Token: 0x060031CF RID: 12751 RVA: 0x000AB390 File Offset: 0x000A9590
|
|
[MonoTODO("(2.0) missing support for AccessEntries")]
|
|
public override void FromXml(SecurityElement securityElement)
|
|
{
|
|
CodeAccessPermission.CheckSecurityElement(securityElement, "securityElement", 1, 1);
|
|
if (CodeAccessPermission.IsUnrestricted(securityElement))
|
|
{
|
|
this._flags = KeyContainerPermissionFlags.AllFlags;
|
|
}
|
|
else
|
|
{
|
|
this._flags = (KeyContainerPermissionFlags)((int)Enum.Parse(typeof(KeyContainerPermissionFlags), securityElement.Attribute("Flags")));
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
|
|
/// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
|
|
/// <param name="target">A permission to intersect with the current permission. It must be the same type as the current permission. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="target" /> is not null and does not specify a permission of the same type as the current permission. </exception>
|
|
// Token: 0x060031D0 RID: 12752 RVA: 0x000AB3EC File Offset: 0x000A95EC
|
|
[MonoTODO("(2.0)")]
|
|
public override IPermission Intersect(IPermission target)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
|
|
/// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
|
|
/// <param name="target">A permission to test for the subset relationship. This permission must be the same type as the current permission. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="target" /> is not null and does not specify a permission of the same type as the current permission. </exception>
|
|
// Token: 0x060031D1 RID: 12753 RVA: 0x000AB3F0 File Offset: 0x000A95F0
|
|
[MonoTODO("(2.0)")]
|
|
public override bool IsSubsetOf(IPermission target)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Determines whether the current permission is unrestricted.</summary>
|
|
/// <returns>true if the current permission is unrestricted; otherwise, false.</returns>
|
|
// Token: 0x060031D2 RID: 12754 RVA: 0x000AB3F4 File Offset: 0x000A95F4
|
|
public bool IsUnrestricted()
|
|
{
|
|
return this._flags == KeyContainerPermissionFlags.AllFlags;
|
|
}
|
|
|
|
/// <summary>Creates an XML encoding of the permission and its current state.</summary>
|
|
/// <returns>A <see cref="T:System.Security.SecurityElement" /> that contains an XML encoding of the permission, including state information.</returns>
|
|
// Token: 0x060031D3 RID: 12755 RVA: 0x000AB404 File Offset: 0x000A9604
|
|
[MonoTODO("(2.0) missing support for AccessEntries")]
|
|
public override SecurityElement ToXml()
|
|
{
|
|
SecurityElement securityElement = base.Element(1);
|
|
if (this.IsUnrestricted())
|
|
{
|
|
securityElement.AddAttribute("Unrestricted", "true");
|
|
}
|
|
return securityElement;
|
|
}
|
|
|
|
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
|
|
/// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
|
|
/// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="target" /> is not null and does not specify a permission of the same type as the current permission. </exception>
|
|
// Token: 0x060031D4 RID: 12756 RVA: 0x000AB43C File Offset: 0x000A963C
|
|
public override IPermission Union(IPermission target)
|
|
{
|
|
KeyContainerPermission keyContainerPermission = this.Cast(target);
|
|
if (keyContainerPermission == null)
|
|
{
|
|
return this.Copy();
|
|
}
|
|
KeyContainerPermissionAccessEntryCollection keyContainerPermissionAccessEntryCollection = new KeyContainerPermissionAccessEntryCollection();
|
|
foreach (KeyContainerPermissionAccessEntry keyContainerPermissionAccessEntry in this._accessEntries)
|
|
{
|
|
keyContainerPermissionAccessEntryCollection.Add(keyContainerPermissionAccessEntry);
|
|
}
|
|
foreach (KeyContainerPermissionAccessEntry keyContainerPermissionAccessEntry2 in keyContainerPermission._accessEntries)
|
|
{
|
|
if (this._accessEntries.IndexOf(keyContainerPermissionAccessEntry2) == -1)
|
|
{
|
|
keyContainerPermissionAccessEntryCollection.Add(keyContainerPermissionAccessEntry2);
|
|
}
|
|
}
|
|
if (keyContainerPermissionAccessEntryCollection.Count == 0)
|
|
{
|
|
return new KeyContainerPermission(this._flags | keyContainerPermission._flags);
|
|
}
|
|
KeyContainerPermissionAccessEntry[] array = new KeyContainerPermissionAccessEntry[keyContainerPermissionAccessEntryCollection.Count];
|
|
keyContainerPermissionAccessEntryCollection.CopyTo(array, 0);
|
|
return new KeyContainerPermission(this._flags | keyContainerPermission._flags, array);
|
|
}
|
|
|
|
// Token: 0x060031D5 RID: 12757 RVA: 0x000AB51C File Offset: 0x000A971C
|
|
private void SetFlags(KeyContainerPermissionFlags flags)
|
|
{
|
|
if ((flags & KeyContainerPermissionFlags.AllFlags) != KeyContainerPermissionFlags.NoFlags)
|
|
{
|
|
string text = string.Format(Locale.GetText("Invalid enum {0}"), flags);
|
|
throw new ArgumentException(text, "KeyContainerPermissionFlags");
|
|
}
|
|
this._flags = flags;
|
|
}
|
|
|
|
// Token: 0x060031D6 RID: 12758 RVA: 0x000AB560 File Offset: 0x000A9760
|
|
private KeyContainerPermission Cast(IPermission target)
|
|
{
|
|
if (target == null)
|
|
{
|
|
return null;
|
|
}
|
|
KeyContainerPermission keyContainerPermission = target as KeyContainerPermission;
|
|
if (keyContainerPermission == null)
|
|
{
|
|
CodeAccessPermission.ThrowInvalidPermission(target, typeof(KeyContainerPermission));
|
|
}
|
|
return keyContainerPermission;
|
|
}
|
|
|
|
// Token: 0x04001471 RID: 5233
|
|
private const int version = 1;
|
|
|
|
// Token: 0x04001472 RID: 5234
|
|
private KeyContainerPermissionAccessEntryCollection _accessEntries;
|
|
|
|
// Token: 0x04001473 RID: 5235
|
|
private KeyContainerPermissionFlags _flags;
|
|
}
|
|
}
|