using System;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Mono.Security;
namespace System.Security.Policy
{
/// Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be inherited.
// Token: 0x020005A7 RID: 1447
[ComVisible(true)]
[Serializable]
public sealed class Zone : IBuiltInEvidence, IIdentityPermissionFactory
{
/// Initializes a new instance of the class with the zone from which a code assembly originates.
/// The zone of origin for the associated code assembly.
/// The parameter is not a valid .
// 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;
}
/// Gets the zone from which the code assembly originates.
/// The zone from which the code assembly originates.
// Token: 0x17000A64 RID: 2660
// (get) Token: 0x06003501 RID: 13569 RVA: 0x000B6A70 File Offset: 0x000B4C70
public SecurityZone SecurityZone
{
get
{
return this.zone;
}
}
/// Creates an equivalent copy of the evidence object.
/// A new, identical copy of the evidence object.
// Token: 0x06003502 RID: 13570 RVA: 0x000B6A78 File Offset: 0x000B4C78
public object Copy()
{
return new Zone(this.zone);
}
/// Creates an identity permission that corresponds to the current instance of the evidence class.
/// A for the specified evidence.
/// The evidence set from which to construct the identity permission.
// Token: 0x06003503 RID: 13571 RVA: 0x000B6A88 File Offset: 0x000B4C88
public IPermission CreateIdentityPermission(Evidence evidence)
{
return new ZoneIdentityPermission(this.zone);
}
/// Creates a new zone with the specified URL.
/// A new zone with the specified URL.
/// The URL from which to create the zone.
/// The parameter is null.
// 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);
}
/// Compares the current evidence object to the specified object for equivalence.
/// true if the two objects are equal; otherwise, false.
/// The evidence object to test for equivalence with the current object.
/// The parameter is not a object.
// 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;
}
/// Gets the hash code of the current zone.
/// The hash code of the current zone.
// Token: 0x06003506 RID: 13574 RVA: 0x000B6B68 File Offset: 0x000B4D68
public override int GetHashCode()
{
return (int)this.zone;
}
/// Returns a string representation of the current .
/// A representation of the current .
// 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;
}
}