New test.
[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-2005 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.Runtime.InteropServices;
33 using System.Security.Cryptography;
34
35 namespace System.Security.Permissions {
36
37         [Serializable]
38         [ComVisible (true)]
39         public sealed class KeyContainerPermissionAccessEntry {
40
41                 private KeyContainerPermissionFlags _flags;
42                 private string _containerName;
43                 private int _spec;
44                 private string _store;
45                 private string _providerName;
46                 private int _type;
47
48
49                 public KeyContainerPermissionAccessEntry (CspParameters csp, KeyContainerPermissionFlags flags)
50                 {
51                         if (csp == null)
52                                 throw new ArgumentNullException ("csp");
53
54                         ProviderName = csp.ProviderName;
55                         ProviderType = csp.ProviderType;
56                         KeyContainerName = csp.KeyContainerName;
57                         KeySpec = csp.KeyNumber;
58                         Flags = flags;
59                 }
60
61                 public KeyContainerPermissionAccessEntry (string keyContainerName, KeyContainerPermissionFlags flags)
62                 {
63                         KeyContainerName = keyContainerName;
64                         Flags = flags;
65                 }
66
67                 public KeyContainerPermissionAccessEntry (string keyStore, string providerName, int providerType, 
68                         string keyContainerName, int keySpec, KeyContainerPermissionFlags flags)
69                 {
70                         KeyStore = keyStore;
71                         ProviderName = providerName;
72                         ProviderType = providerType;
73                         KeyContainerName = keyContainerName;
74                         KeySpec = keySpec;
75                         Flags = flags;
76                 }
77
78
79                 public KeyContainerPermissionFlags Flags {
80                         get { return _flags; }
81                         set {
82                                 if ((value & KeyContainerPermissionFlags.AllFlags) != 0) {
83                                         string msg = String.Format (Locale.GetText ("Invalid enum {0}"), value);
84                                         throw new ArgumentException (msg, "KeyContainerPermissionFlags");
85                                 }
86                                 _flags = value;
87                         }
88                 }
89
90                 public string KeyContainerName {
91                         get { return _containerName; }
92                         set { _containerName = value; }
93                 }
94
95                 public int KeySpec {
96                         get { return _spec; }
97                         set { _spec = value; }
98                 }
99
100                 public string KeyStore {
101                         get { return _store; }
102                         set { _store = value; }
103                 }
104
105                 public string ProviderName {
106                         get { return _providerName; }
107                         set { _providerName = value; }
108                 }
109
110                 public int ProviderType {
111                         get { return _type; }
112                         set { _type = value; }
113                 }
114
115
116                 public override bool Equals (object obj)
117                 {
118                         if (obj == null)
119                                 return false;
120                         KeyContainerPermissionAccessEntry kcpae = (obj as KeyContainerPermissionAccessEntry);
121                         if (kcpae == null)
122                                 return false;
123                         if (_flags != kcpae._flags)
124                                 return false;
125                         if (_containerName != kcpae._containerName)
126                                 return false;
127                         if (_store != kcpae._store)
128                                 return false;
129                         if (_providerName != kcpae._providerName)
130                                 return false;
131                         if (_type != kcpae._type)
132                                 return false;
133                         return true;
134                 }
135
136                 public override int GetHashCode ()
137                 {
138                         int result = _type ^ _spec ^ (int) _flags;
139                         if (_containerName != null)
140                                 result ^= _containerName.GetHashCode ();
141                         if (_store != null)
142                                 result ^= _store.GetHashCode ();
143                         if (_providerName != null)
144                                 result ^= _providerName.GetHashCode ();
145                         return result;
146                 }
147         }
148 }
149
150 #endif