RecipientInformationStore.cs 2.3 KB

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