CertReqMsg.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf
  5. {
  6. public class CertReqMsg
  7. : Asn1Encodable
  8. {
  9. private readonly CertRequest certReq;
  10. private readonly ProofOfPossession popo;
  11. private readonly Asn1Sequence regInfo;
  12. private CertReqMsg(Asn1Sequence seq)
  13. {
  14. certReq = CertRequest.GetInstance(seq[0]);
  15. for (int pos = 1; pos < seq.Count; ++pos)
  16. {
  17. object o = seq[pos];
  18. if (o is Asn1TaggedObject || o is ProofOfPossession)
  19. {
  20. popo = ProofOfPossession.GetInstance(o);
  21. }
  22. else
  23. {
  24. regInfo = Asn1Sequence.GetInstance(o);
  25. }
  26. }
  27. }
  28. public static CertReqMsg GetInstance(object obj)
  29. {
  30. if (obj is CertReqMsg)
  31. return (CertReqMsg)obj;
  32. if (obj != null)
  33. return new CertReqMsg(Asn1Sequence.GetInstance(obj));
  34. return null;
  35. }
  36. public static CertReqMsg GetInstance(
  37. Asn1TaggedObject obj,
  38. bool isExplicit)
  39. {
  40. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  41. }
  42. /**
  43. * Creates a new CertReqMsg.
  44. * @param certReq CertRequest
  45. * @param popo may be null
  46. * @param regInfo may be null
  47. */
  48. public CertReqMsg(
  49. CertRequest certReq,
  50. ProofOfPossession popo,
  51. AttributeTypeAndValue[] regInfo)
  52. {
  53. if (certReq == null)
  54. throw new ArgumentNullException("certReq");
  55. this.certReq = certReq;
  56. this.popo = popo;
  57. if (regInfo != null)
  58. {
  59. this.regInfo = new DerSequence(regInfo);
  60. }
  61. }
  62. public virtual CertRequest CertReq
  63. {
  64. get { return certReq; }
  65. }
  66. public virtual ProofOfPossession Popo
  67. {
  68. get { return popo; }
  69. }
  70. public virtual AttributeTypeAndValue[] GetRegInfo()
  71. {
  72. if (regInfo == null)
  73. return null;
  74. AttributeTypeAndValue[] results = new AttributeTypeAndValue[regInfo.Count];
  75. for (int i = 0; i != results.Length; ++i)
  76. {
  77. results[i] = AttributeTypeAndValue.GetInstance(regInfo[i]);
  78. }
  79. return results;
  80. }
  81. /**
  82. * <pre>
  83. * CertReqMsg ::= SEQUENCE {
  84. * certReq CertRequest,
  85. * pop ProofOfPossession OPTIONAL,
  86. * -- content depends upon key type
  87. * regInfo SEQUENCE SIZE(1..MAX) OF AttributeTypeAndValue OPTIONAL }
  88. * </pre>
  89. * @return a basic ASN.1 object representation.
  90. */
  91. public override Asn1Object ToAsn1Object()
  92. {
  93. Asn1EncodableVector v = new Asn1EncodableVector(certReq);
  94. v.AddOptional(popo, regInfo);
  95. return new DerSequence(v);
  96. }
  97. }
  98. }
  99. #pragma warning restore
  100. #endif