namespace com.hitrust.b2b.Security.Certificates { using com.hitrust.b2b.Security; using System; using System.Collections; public class CertificateStoreCollection : CertificateStore { private ArrayList m_Stores; public CertificateStoreCollection(CertificateStore[] stores) : base(SspiProvider.CertOpenStore(new IntPtr(11), 0, IntPtr.Zero, 0, null), false) { if (stores == null) { throw new ArgumentNullException(); } for (int i = 0; i < stores.Length; i++) { if (stores[i].ToString() == this.ToString()) { throw new ArgumentException("A certificate store collection cannot hold other certificate store collections."); } } for (int j = 0; j < stores.Length; j++) { if (SspiProvider.CertAddStoreToCollection(base.Handle, stores[j].Handle, 0, 0) == 0) { throw new CertificateException("Could not add the store to the collection."); } } this.m_Stores = new ArrayList(); this.m_Stores.AddRange(stores); } public CertificateStoreCollection(CertificateStoreCollection collection) : base(SspiProvider.CertOpenStore(new IntPtr(11), 0, IntPtr.Zero, 0, null), false) { if (collection == null) { throw new ArgumentNullException(); } this.m_Stores = new ArrayList(collection.m_Stores); for (int i = 0; i < this.m_Stores.Count; i++) { if (SspiProvider.CertAddStoreToCollection(base.Handle, ((CertificateStore) this.m_Stores[i]).Handle, 0, 0) == 0) { throw new CertificateException("Could not add the store to the collection."); } } } public void AddStore(CertificateStore store) { if (store == null) { throw new ArgumentNullException(); } if (store.ToString() == this.ToString()) { throw new ArgumentException("A certificate store collection cannot hold other certificate store collections."); } if (SspiProvider.CertAddStoreToCollection(base.Handle, store.Handle, 0, 0) == 0) { throw new CertificateException("Could not add the store to the collection."); } this.m_Stores.Add(store); } public void RemoveStore(CertificateStore store) { if (store == null) { throw new ArgumentNullException(); } SspiProvider.CertRemoveStoreFromCollection(base.Handle, store.Handle); this.m_Stores.Remove(store); } } }