2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System.Security.Permissions / KeyContainerPermissionAccessEntry.cs
1 //
2 // System.Security.Permissions.KeyContainerPermissionAccessEntry class
3 //
4 // Author
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if NET_2_0
30
31 using System.Globalization;
32 using System.Security.Cryptography;
33
34 namespace System.Security.Permissions {
35
36         [Serializable]
37         public sealed class KeyContainerPermissionAccessEntry {
38
39                 private KeyContainerPermissionFlags _flags;
40                 private string _containerName;
41                 private int _spec;
42                 private string _store;
43                 private string _providerName;
44                 private int _type;
45
46
47                 public KeyContainerPermissionAccessEntry (CspParameters csp, KeyContainerPermissionFlags flags)
48                 {
49                         if (csp == null)
50                                 throw new ArgumentNullException ("csp");
51
52                         ProviderName = csp.ProviderName;
53                         ProviderType = csp.ProviderType;
54                         KeyContainerName = csp.KeyContainerName;
55                         KeySpec = csp.KeyNumber;
56                         Flags = flags;
57                 }
58
59                 public KeyContainerPermissionAccessEntry (string keyContainerName, KeyContainerPermissionFlags flags)
60                 {
61                         KeyContainerName = keyContainerName;
62                         Flags = flags;
63                 }
64
65                 public KeyContainerPermissionAccessEntry (string keyStore, string providerName, int providerType, 
66                         string keyContainerName, int keySpec, KeyContainerPermissionFlags flags)
67                 {
68                         KeyStore = keyStore;
69                         ProviderName = providerName;
70                         ProviderType = providerType;
71                         KeyContainerName = keyContainerName;
72                         KeySpec = keySpec;
73                         Flags = flags;
74                 }
75
76
77                 public KeyContainerPermissionFlags Flags {
78                         get { return _flags; }
79                         set {
80                                 if ((value & KeyContainerPermissionFlags.AllFlags) != 0) {
81                                         string msg = String.Format (Locale.GetText ("Invalid enum {0}"), value);
82                                         throw new ArgumentException (msg, "KeyContainerPermissionFlags");
83                                 }
84                                 _flags = value;
85                         }
86                 }
87
88                 public string KeyContainerName {
89                         get { return _containerName; }
90                         set { _containerName = value; }
91                 }
92
93                 public int KeySpec {
94                         get { return _spec; }
95                         set { _spec = value; }
96                 }
97
98                 public string KeyStore {
99                         get { return _store; }
100                         set { _store = value; }
101                 }
102
103                 public string ProviderName {
104                         get { return _providerName; }
105                         set { _providerName = value; }
106                 }
107
108                 public int ProviderType {
109                         get { return _type; }
110                         set { _type = value; }
111                 }
112
113
114                 public override bool Equals (object obj)
115                 {
116                         if (obj == null)
117                                 return false;
118                         KeyContainerPermissionAccessEntry kcpae = (obj as KeyContainerPermissionAccessEntry);
119                         if (kcpae == null)
120                                 return false;
121                         if (_flags != kcpae._flags)
122                                 return false;
123                         if (_containerName != kcpae._containerName)
124                                 return false;
125                         if (_store != kcpae._store)
126                                 return false;
127                         if (_providerName != kcpae._providerName)
128                                 return false;
129                         if (_type != kcpae._type)
130                                 return false;
131                         return true;
132                 }
133
134                 public override int GetHashCode ()
135                 {
136                         int result = _type ^ _spec ^ (int) _flags;
137                         if (_containerName != null)
138                                 result ^= _containerName.GetHashCode ();
139                         if (_store != null)
140                                 result ^= _store.GetHashCode ();
141                         if (_providerName != null)
142                                 result ^= _providerName.GetHashCode ();
143                         return result;
144                 }
145         }
146 }
147
148 #endif