SignerInformationStore.cs 3.3 KB

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