2 // System.Security.Policy.ApplicationTrustCollection class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using System
.Collections
;
32 using System
.Globalization
;
34 namespace System
.Security
.Policy
{
36 public sealed class ApplicationTrustCollection
: CollectionBase
{
38 internal ApplicationTrustCollection ()
44 public ApplicationTrust
this [int index
] {
45 get { return (ApplicationTrust) InnerList [index]; }
46 set { InnerList [index] = value; }
51 public int Add (ApplicationTrust trust
)
54 throw new ArgumentNullException ("trust");
55 if (trust
.ApplicationIdentity
== null) {
56 throw new ArgumentException (Locale
.GetText (
57 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
60 return InnerList
.Add (trust
);
63 public void AddRange (ApplicationTrust
[] trusts
)
66 throw new ArgumentNullException ("trusts");
68 foreach (ApplicationTrust t
in trusts
) {
69 if (t
.ApplicationIdentity
== null) {
70 throw new ArgumentException (Locale
.GetText (
71 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
77 public void AddRange (ApplicationTrustCollection trusts
)
80 throw new ArgumentNullException ("trusts");
82 foreach (ApplicationTrust t
in trusts
) {
83 if (t
.ApplicationIdentity
== null) {
84 throw new ArgumentException (Locale
.GetText (
85 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
91 public bool Contains (ApplicationTrust trust
)
93 return (IndexOf (trust
) >= 0);
96 public void CopyTo (ApplicationTrust
[] array
, int index
)
98 InnerList
.CopyTo (array
, index
);
101 [MonoTODO ("missing MatchExactVersion")]
102 public ApplicationTrustCollection
Find (ApplicationIdentity applicationIdentity
, ApplicationVersionMatch versionMatch
)
104 ApplicationTrustCollection coll
= new ApplicationTrustCollection ();
105 foreach (ApplicationTrust t
in InnerList
) {
106 if (t
.ApplicationIdentity
.Equals (applicationIdentity
)) {
107 switch (versionMatch
) {
108 case ApplicationVersionMatch
.MatchAllVersions
:
111 case ApplicationVersionMatch
.MatchExactVersion
:
112 // TODO: version is encoded in a fullname ?
120 public new ApplicationTrustEnumerator
GetEnumerator ()
122 return new ApplicationTrustEnumerator (this);
125 public int IndexOf (ApplicationTrust trust
)
128 throw new ArgumentNullException ("trust");
130 for (int i
=0; i
< InnerList
.Count
; i
++) {
131 if (trust
.Equals (InnerList
[i
]))
137 public void Insert (int index
, ApplicationTrust trust
)
140 throw new ArgumentNullException ("trust");
142 InnerList
.Insert (index
, trust
);
145 public void Remove (ApplicationTrust trust
)
148 throw new ArgumentNullException ("trust");
149 if (trust
.ApplicationIdentity
== null) {
150 throw new ArgumentException (Locale
.GetText (
151 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
154 RemoveAllInstances (trust
);
157 [MonoTODO ("missing MatchExactVersion (relies on Find)")]
158 public void Remove (ApplicationIdentity applicationIdentity
, ApplicationVersionMatch versionMatch
)
160 ApplicationTrustCollection coll
= Find (applicationIdentity
, versionMatch
);
161 foreach (ApplicationTrust t
in coll
) {
162 RemoveAllInstances (t
);
166 public void RemoveRange (ApplicationTrust
[] trusts
)
169 throw new ArgumentNullException ("trusts");
171 foreach (ApplicationTrust t
in trusts
) {
172 RemoveAllInstances (t
);
176 public void RemoveRange (ApplicationTrustCollection trusts
)
179 throw new ArgumentNullException ("trusts");
181 foreach (ApplicationTrust t
in trusts
) {
182 RemoveAllInstances (t
);
188 internal void RemoveAllInstances (ApplicationTrust trust
)
190 for (int i
=InnerList
.Count
- 1; i
>= 0; i
--) {
191 if (trust
.Equals (InnerList
[i
]))
192 InnerList
.RemoveAt (i
);