2004-06-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / corlib / System.Security.Policy / StrongName.cs
1 //
2 // StrongName.cs: Strong Name
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using System;
11 using System.Security.Permissions;
12 using System.Text;
13
14 namespace System.Security.Policy {
15
16 [Serializable]
17 public sealed class StrongName : IIdentityPermissionFactory, IBuiltInEvidence {
18
19         private StrongNamePublicKeyBlob publickey;
20         private string name;
21         private Version version;
22
23         public StrongName (StrongNamePublicKeyBlob blob, string name, Version version) 
24         {
25                 if (blob == null)
26                         throw new ArgumentNullException ("blob");
27                 if (name == null)
28                         throw new ArgumentNullException ("name");
29                 if (version == null)
30                         throw new ArgumentNullException ("version");
31
32                 publickey = blob;
33                 this.name = name;
34                 this.version = version;
35         }
36
37         public string Name { 
38                 get { return name; }
39         }
40
41         public StrongNamePublicKeyBlob PublicKey { 
42                 get { return publickey; }
43         }
44
45         public Version Version { 
46                 get { return version; }
47         }
48
49         public object Copy () 
50         {
51                 return (object) new StrongName (publickey, name, version);
52         }
53
54         public IPermission CreateIdentityPermission (Evidence evidence) 
55         {
56                 return new StrongNameIdentityPermission (publickey, name, version);
57         }
58
59         public override bool Equals (object o) 
60         {
61                 if (!(o is StrongName))
62                         return false;
63                 StrongName sn = (o as StrongName);
64                 if (name != sn.Name)
65                         return false;
66                 if (!Version.Equals (sn.Version))
67                         return false;
68                 return PublicKey.Equals (sn.PublicKey);
69         }
70
71         public override int GetHashCode () 
72         {
73                 return publickey.GetHashCode ();
74         }
75
76         public override string ToString () 
77         {
78                 SecurityElement element = new SecurityElement (typeof (System.Security.Policy.StrongName).Name);
79                 element.AddAttribute ("version", "1");
80                 element.AddAttribute ("Key", publickey.ToString ());
81                 element.AddAttribute ("Name", name);
82                 element.AddAttribute ("Version", version.ToString ());
83                 return element.ToString ();
84         }
85
86         // interface IBuiltInEvidence
87
88         [MonoTODO]
89         int IBuiltInEvidence.GetRequiredSize (bool verbose) 
90         {
91                 return 0;
92         }
93
94         [MonoTODO]
95         int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position) 
96         {
97                 return 0;
98         }
99
100         [MonoTODO]
101         int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose) 
102         {
103                 return 0;
104         }
105 }
106
107 }