SignerInformationStore
using Org.BouncyCastle.Utilities.Collections;
using System.Collections;
using System.Collections.Generic;
namespace Org.BouncyCastle.Cms
{
public class SignerInformationStore : IEnumerable<SignerInformation>, IEnumerable
{
private readonly List<SignerInformation> m_all;
private readonly Dictionary<SignerID, List<SignerInformation>> m_table = new Dictionary<SignerID, List<SignerInformation>>();
public SignerInformation this[SignerID selector] {
get {
return GetFirstSigner(selector);
}
}
public int Count => m_all.Count;
internal List<SignerInformation> SignersInternal => m_all;
public SignerInformationStore(SignerInformation signerInfo)
{
m_all = new List<SignerInformation>(1) {
signerInfo
};
m_table[signerInfo.SignerID] = m_all;
}
public SignerInformationStore(IEnumerable<SignerInformation> signerInfos)
{
m_all = new List<SignerInformation>(signerInfos);
foreach (SignerInformation item in m_all) {
SignerID signerID = item.SignerID;
if (!m_table.TryGetValue(signerID, out List<SignerInformation> value)) {
value = new List<SignerInformation>(1);
m_table[signerID] = value;
}
value.Add(item);
}
}
public SignerInformation GetFirstSigner(SignerID selector)
{
if (m_table.TryGetValue(selector, out List<SignerInformation> value))
return value[0];
return null;
}
public IList<SignerInformation> GetSigners()
{
return new List<SignerInformation>(m_all);
}
public IList<SignerInformation> GetSigners(SignerID selector)
{
if (m_table.TryGetValue(selector, out List<SignerInformation> value))
return new List<SignerInformation>(value);
return new List<SignerInformation>(0);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public IEnumerator<SignerInformation> GetEnumerator()
{
return CollectionUtilities.Proxy(m_all).GetEnumerator();
}
}
}