RecipientEncryptedKey.cs 2.4 KB

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