163 lines
6.1 KiB
C#
163 lines
6.1 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Permissions;
|
|
using Mono.Security;
|
|
|
|
namespace System.Security.Policy
|
|
{
|
|
/// <summary>Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be inherited.</summary>
|
|
// Token: 0x020005A7 RID: 1447
|
|
[ComVisible(true)]
|
|
[Serializable]
|
|
public sealed class Zone : IBuiltInEvidence, IIdentityPermissionFactory
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Policy.Zone" /> class with the zone from which a code assembly originates.</summary>
|
|
/// <param name="zone">The zone of origin for the associated code assembly. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="zone" /> parameter is not a valid <see cref="T:System.Security.SecurityZone" />. </exception>
|
|
// Token: 0x060034FD RID: 13565 RVA: 0x000B69BC File Offset: 0x000B4BBC
|
|
public Zone(SecurityZone zone)
|
|
{
|
|
if (!Enum.IsDefined(typeof(SecurityZone), zone))
|
|
{
|
|
string text = string.Format(Locale.GetText("Invalid zone {0}."), zone);
|
|
throw new ArgumentException(text, "zone");
|
|
}
|
|
this.zone = zone;
|
|
}
|
|
|
|
// Token: 0x060034FE RID: 13566 RVA: 0x000B6A14 File Offset: 0x000B4C14
|
|
int IBuiltInEvidence.GetRequiredSize(bool verbose)
|
|
{
|
|
return 3;
|
|
}
|
|
|
|
// Token: 0x060034FF RID: 13567 RVA: 0x000B6A18 File Offset: 0x000B4C18
|
|
int IBuiltInEvidence.InitFromBuffer(char[] buffer, int position)
|
|
{
|
|
int num = (int)buffer[position++];
|
|
num += (int)buffer[position++];
|
|
return position;
|
|
}
|
|
|
|
// Token: 0x06003500 RID: 13568 RVA: 0x000B6A3C File Offset: 0x000B4C3C
|
|
int IBuiltInEvidence.OutputToBuffer(char[] buffer, int position, bool verbose)
|
|
{
|
|
buffer[position++] = '\u0003';
|
|
buffer[position++] = (char)(this.zone >> 16);
|
|
buffer[position++] = (char)(this.zone & (SecurityZone)65535);
|
|
return position;
|
|
}
|
|
|
|
/// <summary>Gets the zone from which the code assembly originates.</summary>
|
|
/// <returns>The zone from which the code assembly originates.</returns>
|
|
// Token: 0x17000A64 RID: 2660
|
|
// (get) Token: 0x06003501 RID: 13569 RVA: 0x000B6A70 File Offset: 0x000B4C70
|
|
public SecurityZone SecurityZone
|
|
{
|
|
get
|
|
{
|
|
return this.zone;
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates an equivalent copy of the evidence object.</summary>
|
|
/// <returns>A new, identical copy of the evidence object.</returns>
|
|
// Token: 0x06003502 RID: 13570 RVA: 0x000B6A78 File Offset: 0x000B4C78
|
|
public object Copy()
|
|
{
|
|
return new Zone(this.zone);
|
|
}
|
|
|
|
/// <summary>Creates an identity permission that corresponds to the current instance of the <see cref="T:System.Security.Policy.Zone" /> evidence class.</summary>
|
|
/// <returns>A <see cref="T:System.Security.Permissions.ZoneIdentityPermission" /> for the specified <see cref="T:System.Security.Policy.Zone" /> evidence.</returns>
|
|
/// <param name="evidence">The evidence set from which to construct the identity permission. </param>
|
|
// Token: 0x06003503 RID: 13571 RVA: 0x000B6A88 File Offset: 0x000B4C88
|
|
public IPermission CreateIdentityPermission(Evidence evidence)
|
|
{
|
|
return new ZoneIdentityPermission(this.zone);
|
|
}
|
|
|
|
/// <summary>Creates a new zone with the specified URL.</summary>
|
|
/// <returns>A new zone with the specified URL.</returns>
|
|
/// <param name="url">The URL from which to create the zone. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="url" /> parameter is null. </exception>
|
|
// Token: 0x06003504 RID: 13572 RVA: 0x000B6A98 File Offset: 0x000B4C98
|
|
[MonoTODO("Not user configurable yet")]
|
|
public static Zone CreateFromUrl(string url)
|
|
{
|
|
if (url == null)
|
|
{
|
|
throw new ArgumentNullException("url");
|
|
}
|
|
SecurityZone securityZone = SecurityZone.NoZone;
|
|
if (url.Length == 0)
|
|
{
|
|
return new Zone(securityZone);
|
|
}
|
|
Uri uri = new Uri(url);
|
|
if (securityZone == SecurityZone.NoZone)
|
|
{
|
|
if (uri.IsFile)
|
|
{
|
|
if (File.Exists(uri.LocalPath))
|
|
{
|
|
securityZone = SecurityZone.MyComputer;
|
|
}
|
|
else if (string.Compare("FILE://", 0, url, 0, 7, true, CultureInfo.InvariantCulture) == 0)
|
|
{
|
|
securityZone = SecurityZone.Intranet;
|
|
}
|
|
else
|
|
{
|
|
securityZone = SecurityZone.Internet;
|
|
}
|
|
}
|
|
else if (uri.IsLoopback)
|
|
{
|
|
securityZone = SecurityZone.Intranet;
|
|
}
|
|
else
|
|
{
|
|
securityZone = SecurityZone.Internet;
|
|
}
|
|
}
|
|
return new Zone(securityZone);
|
|
}
|
|
|
|
/// <summary>Compares the current <see cref="T:System.Security.Policy.Zone" /> evidence object to the specified object for equivalence.</summary>
|
|
/// <returns>true if the two <see cref="T:System.Security.Policy.Zone" /> objects are equal; otherwise, false.</returns>
|
|
/// <param name="o">The <see cref="T:System.Security.Policy.Zone" /> evidence object to test for equivalence with the current object. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="o" /> parameter is not a <see cref="T:System.Security.Policy.Zone" /> object. </exception>
|
|
// Token: 0x06003505 RID: 13573 RVA: 0x000B6B3C File Offset: 0x000B4D3C
|
|
public override bool Equals(object o)
|
|
{
|
|
Zone zone = o as Zone;
|
|
return zone != null && zone.zone == this.zone;
|
|
}
|
|
|
|
/// <summary>Gets the hash code of the current zone.</summary>
|
|
/// <returns>The hash code of the current zone.</returns>
|
|
// Token: 0x06003506 RID: 13574 RVA: 0x000B6B68 File Offset: 0x000B4D68
|
|
public override int GetHashCode()
|
|
{
|
|
return (int)this.zone;
|
|
}
|
|
|
|
/// <summary>Returns a string representation of the current <see cref="T:System.Security.Policy.Zone" />.</summary>
|
|
/// <returns>A representation of the current <see cref="T:System.Security.Policy.Zone" />.</returns>
|
|
// Token: 0x06003507 RID: 13575 RVA: 0x000B6B70 File Offset: 0x000B4D70
|
|
public override string ToString()
|
|
{
|
|
SecurityElement securityElement = new SecurityElement("System.Security.Policy.Zone");
|
|
securityElement.AddAttribute("version", "1");
|
|
securityElement.AddChild(new SecurityElement("Zone", this.zone.ToString()));
|
|
return securityElement.ToString();
|
|
}
|
|
|
|
// Token: 0x0400158B RID: 5515
|
|
private SecurityZone zone;
|
|
}
|
|
}
|