RecipientIdentifier.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms
  6. {
  7. public class RecipientIdentifier
  8. : Asn1Encodable, IAsn1Choice
  9. {
  10. private Asn1Encodable id;
  11. public RecipientIdentifier(
  12. IssuerAndSerialNumber id)
  13. {
  14. this.id = id;
  15. }
  16. public RecipientIdentifier(
  17. Asn1OctetString id)
  18. {
  19. this.id = new DerTaggedObject(false, 0, id);
  20. }
  21. public RecipientIdentifier(
  22. Asn1Object id)
  23. {
  24. this.id = id;
  25. }
  26. /**
  27. * return a RecipientIdentifier object from the given object.
  28. *
  29. * @param o the object we want converted.
  30. * @exception ArgumentException if the object cannot be converted.
  31. */
  32. public static RecipientIdentifier GetInstance(
  33. object o)
  34. {
  35. if (o == null || o is RecipientIdentifier)
  36. return (RecipientIdentifier)o;
  37. if (o is IssuerAndSerialNumber)
  38. return new RecipientIdentifier((IssuerAndSerialNumber) o);
  39. if (o is Asn1OctetString)
  40. return new RecipientIdentifier((Asn1OctetString) o);
  41. if (o is Asn1Object)
  42. return new RecipientIdentifier((Asn1Object) o);
  43. throw new ArgumentException(
  44. "Illegal object in RecipientIdentifier: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
  45. }
  46. public bool IsTagged
  47. {
  48. get { return (id is Asn1TaggedObject); }
  49. }
  50. public Asn1Encodable ID
  51. {
  52. get
  53. {
  54. if (id is Asn1TaggedObject)
  55. {
  56. return Asn1OctetString.GetInstance((Asn1TaggedObject) id, false);
  57. }
  58. return IssuerAndSerialNumber.GetInstance(id);
  59. }
  60. }
  61. /**
  62. * Produce an object suitable for an Asn1OutputStream.
  63. * <pre>
  64. * RecipientIdentifier ::= CHOICE {
  65. * issuerAndSerialNumber IssuerAndSerialNumber,
  66. * subjectKeyIdentifier [0] SubjectKeyIdentifier
  67. * }
  68. *
  69. * SubjectKeyIdentifier ::= OCTET STRING
  70. * </pre>
  71. */
  72. public override Asn1Object ToAsn1Object()
  73. {
  74. return id.ToAsn1Object();
  75. }
  76. }
  77. }
  78. #pragma warning restore
  79. #endif