OtherCertID.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  7. {
  8. /// <remarks>
  9. /// <code>
  10. /// OtherCertID ::= SEQUENCE {
  11. /// otherCertHash OtherHash,
  12. /// issuerSerial IssuerSerial OPTIONAL
  13. /// }
  14. /// </code>
  15. /// </remarks>
  16. public class OtherCertID
  17. : Asn1Encodable
  18. {
  19. private readonly OtherHash otherCertHash;
  20. private readonly IssuerSerial issuerSerial;
  21. public static OtherCertID GetInstance(
  22. object obj)
  23. {
  24. if (obj == null || obj is OtherCertID)
  25. return (OtherCertID) obj;
  26. if (obj is Asn1Sequence)
  27. return new OtherCertID((Asn1Sequence) obj);
  28. throw new ArgumentException(
  29. "Unknown object in 'OtherCertID' factory: "
  30. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  31. "obj");
  32. }
  33. private OtherCertID(
  34. Asn1Sequence seq)
  35. {
  36. if (seq == null)
  37. throw new ArgumentNullException("seq");
  38. if (seq.Count < 1 || seq.Count > 2)
  39. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  40. this.otherCertHash = OtherHash.GetInstance(seq[0].ToAsn1Object());
  41. if (seq.Count > 1)
  42. {
  43. this.issuerSerial = IssuerSerial.GetInstance(seq[1].ToAsn1Object());
  44. }
  45. }
  46. public OtherCertID(
  47. OtherHash otherCertHash)
  48. : this(otherCertHash, null)
  49. {
  50. }
  51. public OtherCertID(
  52. OtherHash otherCertHash,
  53. IssuerSerial issuerSerial)
  54. {
  55. if (otherCertHash == null)
  56. throw new ArgumentNullException("otherCertHash");
  57. this.otherCertHash = otherCertHash;
  58. this.issuerSerial = issuerSerial;
  59. }
  60. public OtherHash OtherCertHash
  61. {
  62. get { return otherCertHash; }
  63. }
  64. public IssuerSerial IssuerSerial
  65. {
  66. get { return issuerSerial; }
  67. }
  68. public override Asn1Object ToAsn1Object()
  69. {
  70. Asn1EncodableVector v = new Asn1EncodableVector(
  71. otherCertHash.ToAsn1Object());
  72. if (issuerSerial != null)
  73. {
  74. v.Add(issuerSerial.ToAsn1Object());
  75. }
  76. return new DerSequence(v);
  77. }
  78. }
  79. }
  80. #pragma warning restore
  81. #endif