MQVuserKeyingMaterial.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.Ecc
  6. {
  7. public class MQVuserKeyingMaterial
  8. : Asn1Encodable
  9. {
  10. private OriginatorPublicKey ephemeralPublicKey;
  11. private Asn1OctetString addedukm;
  12. public MQVuserKeyingMaterial(
  13. OriginatorPublicKey ephemeralPublicKey,
  14. Asn1OctetString addedukm)
  15. {
  16. // TODO Check ephemeralPublicKey not null
  17. this.ephemeralPublicKey = ephemeralPublicKey;
  18. this.addedukm = addedukm;
  19. }
  20. private MQVuserKeyingMaterial(
  21. Asn1Sequence seq)
  22. {
  23. // TODO Check seq has either 1 or 2 elements
  24. this.ephemeralPublicKey = OriginatorPublicKey.GetInstance(seq[0]);
  25. if (seq.Count > 1)
  26. {
  27. this.addedukm = Asn1OctetString.GetInstance(
  28. (Asn1TaggedObject)seq[1], true);
  29. }
  30. }
  31. /**
  32. * return an AuthEnvelopedData object from a tagged object.
  33. *
  34. * @param obj the tagged object holding the object we want.
  35. * @param isExplicit true if the object is meant to be explicitly
  36. * tagged false otherwise.
  37. * @throws ArgumentException if the object held by the
  38. * tagged object cannot be converted.
  39. */
  40. public static MQVuserKeyingMaterial GetInstance(
  41. Asn1TaggedObject obj,
  42. bool isExplicit)
  43. {
  44. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  45. }
  46. /**
  47. * return an AuthEnvelopedData object from the given object.
  48. *
  49. * @param obj the object we want converted.
  50. * @throws ArgumentException if the object cannot be converted.
  51. */
  52. public static MQVuserKeyingMaterial GetInstance(
  53. object obj)
  54. {
  55. if (obj == null || obj is MQVuserKeyingMaterial)
  56. {
  57. return (MQVuserKeyingMaterial)obj;
  58. }
  59. if (obj is Asn1Sequence)
  60. {
  61. return new MQVuserKeyingMaterial((Asn1Sequence)obj);
  62. }
  63. throw new ArgumentException("Invalid MQVuserKeyingMaterial: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  64. }
  65. public OriginatorPublicKey EphemeralPublicKey
  66. {
  67. get { return ephemeralPublicKey; }
  68. }
  69. public Asn1OctetString AddedUkm
  70. {
  71. get { return addedukm; }
  72. }
  73. /**
  74. * Produce an object suitable for an Asn1OutputStream.
  75. * <pre>
  76. * MQVuserKeyingMaterial ::= SEQUENCE {
  77. * ephemeralPublicKey OriginatorPublicKey,
  78. * addedukm [0] EXPLICIT UserKeyingMaterial OPTIONAL }
  79. * </pre>
  80. */
  81. public override Asn1Object ToAsn1Object()
  82. {
  83. Asn1EncodableVector v = new Asn1EncodableVector(ephemeralPublicKey);
  84. v.AddOptionalTagged(true, 0, addedukm);
  85. return new DerSequence(v);
  86. }
  87. }
  88. }
  89. #pragma warning restore
  90. #endif