RootCaKeyUpdateContent.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  5. {
  6. /**
  7. * GenMsg: {id-it 20}, RootCaCertValue | < absent >
  8. * GenRep: {id-it 18}, RootCaKeyUpdateContent | < absent >
  9. * <p>
  10. * RootCaCertValue ::= CMPCertificate
  11. * </p><p>
  12. * RootCaKeyUpdateValue ::= RootCaKeyUpdateContent
  13. * </p><p>
  14. * RootCaKeyUpdateContent ::= SEQUENCE {
  15. * newWithNew CMPCertificate,
  16. * newWithOld [0] CMPCertificate OPTIONAL,
  17. * oldWithNew [1] CMPCertificate OPTIONAL
  18. * }
  19. * </p>
  20. */
  21. public class RootCaKeyUpdateContent
  22. : Asn1Encodable
  23. {
  24. public static RootCaKeyUpdateContent GetInstance(object obj)
  25. {
  26. if (obj is RootCaKeyUpdateContent rootCaKeyUpdateContent)
  27. return rootCaKeyUpdateContent;
  28. if (obj != null)
  29. return new RootCaKeyUpdateContent(Asn1Sequence.GetInstance(obj));
  30. return null;
  31. }
  32. private readonly CmpCertificate m_newWithNew;
  33. private readonly CmpCertificate m_newWithOld;
  34. private readonly CmpCertificate m_oldWithNew;
  35. public RootCaKeyUpdateContent(CmpCertificate newWithNew, CmpCertificate newWithOld, CmpCertificate oldWithNew)
  36. {
  37. if (newWithNew == null)
  38. throw new ArgumentNullException(nameof(newWithNew));
  39. m_newWithNew = newWithNew;
  40. m_newWithOld = newWithOld;
  41. m_oldWithNew = oldWithNew;
  42. }
  43. private RootCaKeyUpdateContent(Asn1Sequence seq)
  44. {
  45. if (seq.Count < 1 || seq.Count > 3)
  46. throw new ArgumentException("expected sequence of 1 to 3 elements only");
  47. CmpCertificate newWithNew;
  48. CmpCertificate newWithOld = null;
  49. CmpCertificate oldWithNew = null;
  50. newWithNew = CmpCertificate.GetInstance(seq[0]);
  51. for (int pos = 1; pos < seq.Count; ++pos)
  52. {
  53. Asn1TaggedObject ato = Asn1TaggedObject.GetInstance(seq[pos]);
  54. if (ato.TagNo == 0)
  55. {
  56. newWithOld = CmpCertificate.GetInstance(ato, true);
  57. }
  58. else if (ato.TagNo == 1)
  59. {
  60. oldWithNew = CmpCertificate.GetInstance(ato, true);
  61. }
  62. }
  63. m_newWithNew = newWithNew;
  64. m_newWithOld = newWithOld;
  65. m_oldWithNew = oldWithNew;
  66. }
  67. public virtual CmpCertificate NewWithNew => m_newWithNew;
  68. public virtual CmpCertificate NewWithOld => m_newWithOld;
  69. public virtual CmpCertificate OldWithNew => m_oldWithNew;
  70. public override Asn1Object ToAsn1Object()
  71. {
  72. Asn1EncodableVector v = new Asn1EncodableVector(m_newWithNew);
  73. v.AddOptionalTagged(true, 0, m_newWithOld);
  74. v.AddOptionalTagged(true, 1, m_oldWithNew);
  75. return new DerSequence(v);
  76. }
  77. }
  78. }
  79. #pragma warning restore
  80. #endif