2 // System.Security.Policy.Evidence
5 // Sean MacIsaac (macisaac@ximian.com)
6 // Nick Drochak (ndrochak@gol.com)
7 // Jackson Harper (Jackson@LatitudeGeo.com)
8 // Sebastien Pouliot (spouliot@motus.com)
10 // (C) 2001 Ximian, Inc.
11 // Portions (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.com)
15 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 using System.Collections;
39 using System.Security.Permissions;
41 namespace System.Security.Policy {
44 [MonoTODO ("Fix serialization compatibility with MS.NET")]
45 public sealed class Evidence : ICollection, IEnumerable {
48 private ArrayList hostEvidenceList;
49 private ArrayList assemblyEvidenceList;
53 hostEvidenceList = ArrayList.Synchronized (new ArrayList ());
54 assemblyEvidenceList = ArrayList.Synchronized (new ArrayList ());
57 public Evidence (Evidence evidence) : this ()
63 public Evidence (object[] hostEvidence, object[] assemblyEvidence) : this ()
65 if (null != hostEvidence)
66 hostEvidenceList.AddRange (hostEvidence);
67 if (null != assemblyEvidence)
68 assemblyEvidenceList.AddRange (assemblyEvidence);
77 return (hostEvidenceList.Count + assemblyEvidenceList.Count);
81 public bool IsReadOnly {
85 // LAMESPEC: Always TRUE (not FALSE)
86 public bool IsSynchronized {
91 get { return _locked; }
93 new SecurityPermission (SecurityPermissionFlag.ControlEvidence).Demand ();
98 public object SyncRoot {
106 public void AddAssembly (object id)
108 assemblyEvidenceList.Add (id);
111 public void AddHost (object id)
114 new SecurityPermission (SecurityPermissionFlag.ControlEvidence).Demand ();
116 hostEvidenceList.Add (id);
119 public void CopyTo (Array array, int index)
121 if (hostEvidenceList.Count > 0)
122 hostEvidenceList.CopyTo (array, index);
123 if (assemblyEvidenceList.Count > 0)
124 assemblyEvidenceList.CopyTo (array, index + hostEvidenceList.Count);
127 public IEnumerator GetEnumerator ()
129 return new EvidenceEnumerator (hostEvidenceList.GetEnumerator (),
130 assemblyEvidenceList.GetEnumerator ());
133 public IEnumerator GetAssemblyEnumerator ()
135 return assemblyEvidenceList.GetEnumerator ();
138 public IEnumerator GetHostEnumerator ()
140 return hostEvidenceList.GetEnumerator ();
143 public void Merge (Evidence evidence)
145 IEnumerator hostenum, assemblyenum;
147 hostenum = evidence.GetHostEnumerator ();
148 while( hostenum.MoveNext () ) {
149 AddHost (hostenum.Current);
152 assemblyenum = evidence.GetAssemblyEnumerator ();
153 while( assemblyenum.MoveNext () ) {
154 AddAssembly (assemblyenum.Current);
158 private class EvidenceEnumerator : IEnumerator {
160 private IEnumerator currentEnum, hostEnum, assemblyEnum;
162 public EvidenceEnumerator (IEnumerator hostenum, IEnumerator assemblyenum)
164 this.hostEnum = hostenum;
165 this.assemblyEnum = assemblyenum;
166 currentEnum = hostEnum;
169 public bool MoveNext ()
171 bool ret = currentEnum.MoveNext ();
173 if ( !ret && hostEnum == currentEnum ) {
174 currentEnum = assemblyEnum;
175 ret = assemblyEnum.MoveNext ();
184 assemblyEnum.Reset ();
185 currentEnum = hostEnum;
188 public object Current {
190 return currentEnum.Current;