<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />

RecipientInformationStore

using Org.BouncyCastle.Utilities.Collections; using System.Collections; using System.Collections.Generic; namespace Org.BouncyCastle.Cms { public class RecipientInformationStore : IEnumerable<RecipientInformation>, IEnumerable { private readonly List<RecipientInformation> m_all; private readonly Dictionary<RecipientID, List<RecipientInformation>> m_table = new Dictionary<RecipientID, List<RecipientInformation>>(); public RecipientInformation this[RecipientID selector] { get { return GetFirstRecipient(selector); } } public int Count => m_all.Count; internal List<RecipientInformation> RecipientsInternal => m_all; public RecipientInformationStore(RecipientInformation recipientInfo) { m_all = new List<RecipientInformation>(1) { recipientInfo }; m_table[recipientInfo.RecipientID] = m_all; } public RecipientInformationStore(IEnumerable<RecipientInformation> recipientInfos) { m_all = new List<RecipientInformation>(recipientInfos); foreach (RecipientInformation item in m_all) { RecipientID recipientID = item.RecipientID; if (!m_table.TryGetValue(recipientID, out List<RecipientInformation> value)) value = (m_table[recipientID] = new List<RecipientInformation>(1)); value.Add(item); } } public RecipientInformation GetFirstRecipient(RecipientID selector) { if (!m_table.TryGetValue(selector, out List<RecipientInformation> value)) return null; return value[0]; } public IList<RecipientInformation> GetRecipients() { return new List<RecipientInformation>(m_all); } public IList<RecipientInformation> GetRecipients(RecipientID selector) { if (!m_table.TryGetValue(selector, out List<RecipientInformation> value)) return new List<RecipientInformation>(0); return new List<RecipientInformation>(value); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public IEnumerator<RecipientInformation> GetEnumerator() { return CollectionUtilities.Proxy(m_all).GetEnumerator(); } } }