CertAnnContent.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * CertAnnContent ::= CMPCertificate
  11. */
  12. public class CertAnnContent
  13. : CmpCertificate
  14. {
  15. public static new CertAnnContent GetInstance(object obj)
  16. {
  17. // TODO[cmp]
  18. if (obj == null)
  19. return null;
  20. if (obj is CertAnnContent content)
  21. return content;
  22. if (obj is CmpCertificate cmpCertificate)
  23. return GetInstance(cmpCertificate.GetEncoded());
  24. if (obj is byte[] bs)
  25. {
  26. try
  27. {
  28. obj = Asn1Object.FromByteArray(bs);
  29. }
  30. catch (IOException)
  31. {
  32. throw new ArgumentException("Invalid encoding in CertAnnContent");
  33. }
  34. }
  35. if (obj is Asn1Sequence)
  36. return new CertAnnContent(X509CertificateStructure.GetInstance(obj));
  37. // TODO[cmp]
  38. if (obj is Asn1TaggedObject taggedObject)
  39. return new CertAnnContent(taggedObject.TagNo, taggedObject.GetObject());
  40. throw new ArgumentException("Invalid object: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), nameof(obj));
  41. }
  42. public static new CertAnnContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
  43. {
  44. // TODO[cmp]
  45. if (taggedObject == null)
  46. return null;
  47. if (!declaredExplicit)
  48. throw new ArgumentException("tag must be explicit");
  49. // TODO[cmp]
  50. return GetInstance(taggedObject.GetObject());
  51. }
  52. public CertAnnContent(int type, Asn1Object otherCert)
  53. : base(type, otherCert)
  54. {
  55. }
  56. public CertAnnContent(X509CertificateStructure x509v3PKCert)
  57. : base(x509v3PKCert)
  58. {
  59. }
  60. }
  61. }
  62. #pragma warning restore
  63. #endif