2 // System.Security.Policy.ApplicationTrustCollection class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004-2005 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 : ICollection, IEnumerable {
38 private ArrayList _list;
40 internal ApplicationTrustCollection ()
42 _list = new ArrayList ();
47 public const string ApplicationTrustProperty = "ApplicationTrust";
48 public const string InstallReferenceIdentifier = "{3f471841-eef2-47d6-89c0-d028f03a4ad5}";
53 get { return _list.Count; }
56 public bool IsSynchronized {
57 get { return false; } // always false
60 public object SyncRoot {
61 get { return this; } // self
64 public ApplicationTrust this [int index] {
65 get { return (ApplicationTrust) _list [index]; }
69 public ApplicationTrust this [string appFullName] {
70 get { return (ApplicationTrust) _list [0]; }
75 public int Add (ApplicationTrust trust)
78 throw new ArgumentNullException ("trust");
79 if (trust.ApplicationIdentity == null) {
80 throw new ArgumentException (Locale.GetText (
81 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
84 return _list.Add (trust);
87 public void AddRange (ApplicationTrust[] trusts)
90 throw new ArgumentNullException ("trusts");
92 foreach (ApplicationTrust t in trusts) {
93 if (t.ApplicationIdentity == null) {
94 throw new ArgumentException (Locale.GetText (
95 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
101 public void AddRange (ApplicationTrustCollection trusts)
104 throw new ArgumentNullException ("trusts");
106 foreach (ApplicationTrust t in trusts) {
107 if (t.ApplicationIdentity == null) {
108 throw new ArgumentException (Locale.GetText (
109 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
120 public void CopyTo (ApplicationTrust[] array, int index)
122 _list.CopyTo (array, index);
125 void ICollection.CopyTo (Array array, int index)
127 _list.CopyTo (array, index);
130 [MonoTODO ("missing MatchExactVersion")]
131 public ApplicationTrustCollection Find (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch)
133 ApplicationTrustCollection coll = new ApplicationTrustCollection ();
134 foreach (ApplicationTrust t in _list) {
135 if (t.ApplicationIdentity.Equals (applicationIdentity)) {
136 switch (versionMatch) {
137 case ApplicationVersionMatch.MatchAllVersions:
140 case ApplicationVersionMatch.MatchExactVersion:
141 // TODO: version is encoded in a fullname ?
149 public ApplicationTrustEnumerator GetEnumerator ()
151 return new ApplicationTrustEnumerator (this);
154 IEnumerator IEnumerable.GetEnumerator ()
156 return (IEnumerator) new ApplicationTrustEnumerator (this);
159 public void Remove (ApplicationTrust trust)
162 throw new ArgumentNullException ("trust");
163 if (trust.ApplicationIdentity == null) {
164 throw new ArgumentException (Locale.GetText (
165 "ApplicationTrust.ApplicationIdentity can't be null."), "trust");
168 RemoveAllInstances (trust);
171 [MonoTODO ("missing MatchExactVersion (relies on Find)")]
172 public void Remove (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch)
174 ApplicationTrustCollection coll = Find (applicationIdentity, versionMatch);
175 foreach (ApplicationTrust t in coll) {
176 RemoveAllInstances (t);
180 public void RemoveRange (ApplicationTrust[] trusts)
183 throw new ArgumentNullException ("trusts");
185 foreach (ApplicationTrust t in trusts) {
186 RemoveAllInstances (t);
190 public void RemoveRange (ApplicationTrustCollection trusts)
193 throw new ArgumentNullException ("trusts");
195 foreach (ApplicationTrust t in trusts) {
196 RemoveAllInstances (t);
202 internal void RemoveAllInstances (ApplicationTrust trust)
204 for (int i=_list.Count - 1; i >= 0; i--) {
205 if (trust.Equals (_list [i]))