Tue Sep 10 12:12:51 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Security.Policy / Zone.cs
1 //
2 // System.Security.Policy.Zone
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 //
9 using System;
10 using System.Security;
11 using System.Security.Permissions;
12
13 namespace System.Security.Policy
14 {
15         public sealed class Zone : IIdentityPermissionFactory, IBuiltInEvidence
16         {
17                 SecurityZone zone;
18                 
19                 public Zone (SecurityZone zone)
20                 {
21                         if (!Enum.IsDefined (typeof (SecurityZone), zone))
22                                 throw new ArgumentException ("invalid zone");
23
24                         this.zone = zone;
25                 }
26
27                 public object Copy ()
28                 {
29                         return new Zone (zone);
30                 }
31
32                 public IPermission CreateIdentityPermission (Evidence evidence)
33                 {
34                         return new ZoneIdentityPermission (zone);
35                 }
36
37                 [MonoTODO("This depends on zone configuration in IE")]
38                 public static Zone CreateFromUrl (string url)
39                 {
40                         throw new NotImplementedException ();
41                 }
42
43                 public override bool Equals (object o)
44                 {
45                         if (!(o is Zone))
46                                 return false;
47
48                         return (((Zone) o).zone == zone);
49                 }
50
51                 public override int GetHashCode ()
52                 {
53                         return (int) zone;
54                 }
55
56                 public override string ToString ()
57                 {
58                         SecurityElement se = new SecurityElement (GetType ().FullName);
59                         se.AddAttribute ("version", "1");
60                         se.AddChild (new SecurityElement ("Zone", zone.ToString ()));
61
62                         return se.ToString ();
63                 }
64
65                 int IBuiltInEvidence.GetRequiredSize (bool verbose)
66                 {
67                         return 3;
68                 }
69
70                 int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position) {
71                         int new_zone = (int) buffer [position++];
72                         new_zone += buffer [position++];
73                         return position;
74                 }
75
76                 int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose)
77                 {
78                         buffer [position++] = '\x0003';
79                         buffer [position++] = (char) (((int) zone) >> 16);
80                         buffer [position++] = (char) (((int) zone) & 0x0FFFF);
81                         return position;
82                 }
83
84                 public SecurityZone SecurityZone
85                 {
86                         get { return zone; }
87                 }
88         }
89 }
90