KeyAgreeRecipientIdentifier.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 KeyAgreeRecipientIdentifier
  8. : Asn1Encodable, IAsn1Choice
  9. {
  10. /**
  11. * return an KeyAgreeRecipientIdentifier object from a tagged object.
  12. *
  13. * @param obj the tagged object holding the object we want.
  14. * @param isExplicit true if the object is meant to be explicitly
  15. * tagged false otherwise.
  16. * @exception ArgumentException if the object held by the
  17. * tagged object cannot be converted.
  18. */
  19. public static KeyAgreeRecipientIdentifier GetInstance(
  20. Asn1TaggedObject obj,
  21. bool isExplicit)
  22. {
  23. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  24. }
  25. /**
  26. * return an KeyAgreeRecipientIdentifier object from the given object.
  27. *
  28. * @param obj the object we want converted.
  29. * @exception ArgumentException if the object cannot be converted.
  30. */
  31. public static KeyAgreeRecipientIdentifier GetInstance(
  32. object obj)
  33. {
  34. if (obj == null || obj is KeyAgreeRecipientIdentifier)
  35. return (KeyAgreeRecipientIdentifier)obj;
  36. if (obj is Asn1Sequence)
  37. return new KeyAgreeRecipientIdentifier(IssuerAndSerialNumber.GetInstance(obj));
  38. if (obj is Asn1TaggedObject && ((Asn1TaggedObject)obj).TagNo == 0)
  39. {
  40. return new KeyAgreeRecipientIdentifier(RecipientKeyIdentifier.GetInstance(
  41. (Asn1TaggedObject)obj, false));
  42. }
  43. throw new ArgumentException("Invalid KeyAgreeRecipientIdentifier: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  44. }
  45. private readonly IssuerAndSerialNumber issuerSerial;
  46. private readonly RecipientKeyIdentifier rKeyID;
  47. public KeyAgreeRecipientIdentifier(
  48. IssuerAndSerialNumber issuerSerial)
  49. {
  50. this.issuerSerial = issuerSerial;
  51. }
  52. public KeyAgreeRecipientIdentifier(
  53. RecipientKeyIdentifier rKeyID)
  54. {
  55. this.rKeyID = rKeyID;
  56. }
  57. public IssuerAndSerialNumber IssuerAndSerialNumber
  58. {
  59. get { return issuerSerial; }
  60. }
  61. public RecipientKeyIdentifier RKeyID
  62. {
  63. get { return rKeyID; }
  64. }
  65. /**
  66. * Produce an object suitable for an Asn1OutputStream.
  67. * <pre>
  68. * KeyAgreeRecipientIdentifier ::= CHOICE {
  69. * issuerAndSerialNumber IssuerAndSerialNumber,
  70. * rKeyId [0] IMPLICIT RecipientKeyIdentifier
  71. * }
  72. * </pre>
  73. */
  74. public override Asn1Object ToAsn1Object()
  75. {
  76. if (issuerSerial != null)
  77. {
  78. return issuerSerial.ToAsn1Object();
  79. }
  80. return new DerTaggedObject(false, 0, rKeyID);
  81. }
  82. }
  83. }
  84. #pragma warning restore
  85. #endif