PopoPrivKey.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf
  6. {
  7. public class PopoPrivKey
  8. : Asn1Encodable, IAsn1Choice
  9. {
  10. public const int thisMessage = 0;
  11. public const int subsequentMessage = 1;
  12. public const int dhMAC = 2;
  13. public const int agreeMAC = 3;
  14. public const int encryptedKey = 4;
  15. private readonly int tagNo;
  16. private readonly Asn1Encodable obj;
  17. private PopoPrivKey(Asn1TaggedObject obj)
  18. {
  19. this.tagNo = obj.TagNo;
  20. switch (tagNo)
  21. {
  22. case thisMessage:
  23. this.obj = DerBitString.GetInstance(obj, false);
  24. break;
  25. case subsequentMessage:
  26. this.obj = SubsequentMessage.ValueOf(DerInteger.GetInstance(obj, false).IntValueExact);
  27. break;
  28. case dhMAC:
  29. this.obj = DerBitString.GetInstance(obj, false);
  30. break;
  31. case agreeMAC:
  32. this.obj = PKMacValue.GetInstance(obj, false);
  33. break;
  34. case encryptedKey:
  35. this.obj = EnvelopedData.GetInstance(obj, false);
  36. break;
  37. default:
  38. throw new ArgumentException("unknown tag in PopoPrivKey", "obj");
  39. }
  40. }
  41. public static PopoPrivKey GetInstance(Asn1TaggedObject tagged, bool isExplicit)
  42. {
  43. return new PopoPrivKey(Asn1TaggedObject.GetInstance(tagged, true));
  44. }
  45. public PopoPrivKey(SubsequentMessage msg)
  46. {
  47. this.tagNo = subsequentMessage;
  48. this.obj = msg;
  49. }
  50. public virtual int Type
  51. {
  52. get { return tagNo; }
  53. }
  54. public virtual Asn1Encodable Value
  55. {
  56. get { return obj; }
  57. }
  58. /**
  59. * <pre>
  60. * PopoPrivKey ::= CHOICE {
  61. * thisMessage [0] BIT STRING, -- Deprecated
  62. * -- possession is proven in this message (which contains the private
  63. * -- key itself (encrypted for the CA))
  64. * subsequentMessage [1] SubsequentMessage,
  65. * -- possession will be proven in a subsequent message
  66. * dhMAC [2] BIT STRING, -- Deprecated
  67. * agreeMAC [3] PKMACValue,
  68. * encryptedKey [4] EnvelopedData }
  69. * </pre>
  70. */
  71. public override Asn1Object ToAsn1Object()
  72. {
  73. return new DerTaggedObject(false, tagNo, obj);
  74. }
  75. }
  76. }
  77. #pragma warning restore
  78. #endif