OptionalValidity.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf
  6. {
  7. public class OptionalValidity
  8. : Asn1Encodable
  9. {
  10. private readonly Time notBefore;
  11. private readonly Time notAfter;
  12. private OptionalValidity(Asn1Sequence seq)
  13. {
  14. foreach (Asn1TaggedObject tObj in seq)
  15. {
  16. if (tObj.TagNo == 0)
  17. {
  18. notBefore = Time.GetInstance(tObj, true);
  19. }
  20. else
  21. {
  22. notAfter = Time.GetInstance(tObj, true);
  23. }
  24. }
  25. }
  26. public static OptionalValidity GetInstance(object obj)
  27. {
  28. if (obj == null || obj is OptionalValidity)
  29. return (OptionalValidity)obj;
  30. return new OptionalValidity(Asn1Sequence.GetInstance(obj));
  31. }
  32. public OptionalValidity(Time notBefore, Time notAfter)
  33. {
  34. this.notBefore = notBefore;
  35. this.notAfter = notAfter;
  36. }
  37. public virtual Time NotBefore
  38. {
  39. get { return notBefore; }
  40. }
  41. public virtual Time NotAfter
  42. {
  43. get { return notAfter; }
  44. }
  45. /**
  46. * <pre>
  47. * OptionalValidity ::= SEQUENCE {
  48. * notBefore [0] Time OPTIONAL,
  49. * notAfter [1] Time OPTIONAL } --at least one MUST be present
  50. * </pre>
  51. * @return a basic ASN.1 object representation.
  52. */
  53. public override Asn1Object ToAsn1Object()
  54. {
  55. Asn1EncodableVector v = new Asn1EncodableVector();
  56. v.AddOptionalTagged(true, 0, notBefore);
  57. v.AddOptionalTagged(true, 1, notAfter);
  58. return new DerSequence(v);
  59. }
  60. }
  61. }
  62. #pragma warning restore
  63. #endif