SignerInformationStore.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms
  6. {
  7. public class SignerInformationStore
  8. {
  9. private readonly IList<SignerInformation> all;
  10. private readonly IDictionary<SignerID, IList<SignerInformation>> m_table =
  11. new Dictionary<SignerID, IList<SignerInformation>>();
  12. /**
  13. * Create a store containing a single SignerInformation object.
  14. *
  15. * @param signerInfo the signer information to contain.
  16. */
  17. public SignerInformationStore(SignerInformation signerInfo)
  18. {
  19. this.all = new List<SignerInformation>(1);
  20. this.all.Add(signerInfo);
  21. SignerID sid = signerInfo.SignerID;
  22. m_table[sid] = all;
  23. }
  24. /**
  25. * Create a store containing a collection of SignerInformation objects.
  26. *
  27. * @param signerInfos a collection signer information objects to contain.
  28. */
  29. public SignerInformationStore(IEnumerable<SignerInformation> signerInfos)
  30. {
  31. foreach (SignerInformation signer in signerInfos)
  32. {
  33. SignerID sid = signer.SignerID;
  34. if (!m_table.TryGetValue(sid, out var list))
  35. {
  36. m_table[sid] = list = new List<SignerInformation>(1);
  37. }
  38. list.Add(signer);
  39. }
  40. this.all = new List<SignerInformation>(signerInfos);
  41. }
  42. /**
  43. * Return the first SignerInformation object that matches the
  44. * passed in selector. Null if there are no matches.
  45. *
  46. * @param selector to identify a signer
  47. * @return a single SignerInformation object. Null if none matches.
  48. */
  49. public SignerInformation GetFirstSigner(SignerID selector)
  50. {
  51. if (m_table.TryGetValue(selector, out var list))
  52. return list[0];
  53. return null;
  54. }
  55. /// <summary>The number of signers in the collection.</summary>
  56. public int Count
  57. {
  58. get { return all.Count; }
  59. }
  60. /// <returns>An ICollection of all signers in the collection</returns>
  61. public IList<SignerInformation> GetSigners()
  62. {
  63. return new List<SignerInformation>(all);
  64. }
  65. /**
  66. * Return possible empty collection with signers matching the passed in SignerID
  67. *
  68. * @param selector a signer id to select against.
  69. * @return a collection of SignerInformation objects.
  70. */
  71. public IList<SignerInformation> GetSigners(SignerID selector)
  72. {
  73. if (m_table.TryGetValue(selector, out var list))
  74. return new List<SignerInformation>(list);
  75. return new List<SignerInformation>(0);
  76. }
  77. }
  78. }
  79. #pragma warning restore
  80. #endif