OobCert.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  8. {
  9. /**
  10. * OOBCert ::= CMPCertificate
  11. */
  12. public class OobCert
  13. : CmpCertificate
  14. {
  15. public static new OobCert GetInstance(object obj)
  16. {
  17. if (obj == null)
  18. return null;
  19. if (obj is OobCert oobCert)
  20. return oobCert;
  21. if (obj is CmpCertificate cmpCertificate)
  22. return GetInstance(cmpCertificate.GetEncoded());
  23. if (obj is byte[] bs)
  24. {
  25. try
  26. {
  27. obj = Asn1Object.FromByteArray(bs);
  28. }
  29. catch (IOException)
  30. {
  31. throw new ArgumentException("Invalid encoding in OobCert");
  32. }
  33. }
  34. if (obj is Asn1Sequence seq)
  35. return new OobCert(X509CertificateStructure.GetInstance(obj));
  36. if (obj is Asn1TaggedObject taggedObject)
  37. return new OobCert(taggedObject.TagNo, taggedObject.GetObject());
  38. throw new ArgumentException("Invalid object: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), nameof(obj));
  39. }
  40. public static new OobCert GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
  41. {
  42. if (taggedObject == null)
  43. return null;
  44. if (!declaredExplicit)
  45. throw new ArgumentException("tag must be explicit");
  46. return GetInstance(taggedObject.GetObject());
  47. }
  48. public OobCert(int type, Asn1Encodable otherCert)
  49. : base(type, otherCert)
  50. {
  51. }
  52. public OobCert(X509CertificateStructure x509v3PKCert)
  53. : base(x509v3PKCert)
  54. {
  55. }
  56. }
  57. }
  58. #pragma warning restore
  59. #endif