RecipientInformationStore.cs 2.6 KB

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