diff options
Diffstat (limited to 'crypto/src/cms/RecipientInformationStore.cs')
-rw-r--r-- | crypto/src/cms/RecipientInformationStore.cs | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/crypto/src/cms/RecipientInformationStore.cs b/crypto/src/cms/RecipientInformationStore.cs index 33b472f9d..06d093805 100644 --- a/crypto/src/cms/RecipientInformationStore.cs +++ b/crypto/src/cms/RecipientInformationStore.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Org.BouncyCastle.Utilities; @@ -7,26 +7,25 @@ namespace Org.BouncyCastle.Cms { public class RecipientInformationStore { - private readonly IList all; //ArrayList[RecipientInformation] - private readonly IDictionary table = Platform.CreateHashtable(); // Hashtable[RecipientID, ArrayList[RecipientInformation]] + private readonly IList<RecipientInformation> m_all; + private readonly IDictionary<RecipientID, IList<RecipientInformation>> m_table = + new Dictionary<RecipientID, IList<RecipientInformation>>(); - public RecipientInformationStore( - ICollection recipientInfos) + public RecipientInformationStore(IEnumerable<RecipientInformation> recipientInfos) { foreach (RecipientInformation recipientInformation in recipientInfos) { RecipientID rid = recipientInformation.RecipientID; - IList list = (IList)table[rid]; - if (list == null) - { - table[rid] = list = Platform.CreateArrayList(1); + if (!m_table.TryGetValue(rid, out var list)) + { + m_table[rid] = list = new List<RecipientInformation>(1); } list.Add(recipientInformation); } - this.all = Platform.CreateArrayList(recipientInfos); + this.m_all = new List<RecipientInformation>(recipientInfos); } public RecipientInformation this[RecipientID selector] @@ -41,12 +40,12 @@ namespace Org.BouncyCastle.Cms * @param selector to identify a recipient * @return a single RecipientInformation object. Null if none matches. */ - public RecipientInformation GetFirstRecipient( - RecipientID selector) + public RecipientInformation GetFirstRecipient(RecipientID selector) { - IList list = (IList) table[selector]; + if (!m_table.TryGetValue(selector, out var list)) + return null; - return list == null ? null : (RecipientInformation) list[0]; + return list[0]; } /** @@ -56,7 +55,7 @@ namespace Org.BouncyCastle.Cms */ public int Count { - get { return all.Count; } + get { return m_all.Count; } } /** @@ -64,9 +63,9 @@ namespace Org.BouncyCastle.Cms * * @return a collection of recipients. */ - public ICollection GetRecipients() + public IList<RecipientInformation> GetRecipients() { - return Platform.CreateArrayList(all); + return new List<RecipientInformation>(m_all); } /** @@ -75,12 +74,12 @@ namespace Org.BouncyCastle.Cms * @param selector a recipient id to select against. * @return a collection of RecipientInformation objects. */ - public ICollection GetRecipients( - RecipientID selector) + public IList<RecipientInformation> GetRecipients(RecipientID selector) { - IList list = (IList)table[selector]; + if (!m_table.TryGetValue(selector, out var list)) + return new List<RecipientInformation>(0); - return list == null ? Platform.CreateArrayList() : Platform.CreateArrayList(list); + return new List<RecipientInformation>(list); } } } |