1414public class OptionalValidity
1515 extends ASN1Object
1616{
17+ public static OptionalValidity getInstance (Object o )
18+ {
19+ if (o instanceof OptionalValidity )
20+ {
21+ return (OptionalValidity )o ;
22+ }
23+
24+ if (o != null )
25+ {
26+ return new OptionalValidity (ASN1Sequence .getInstance (o ));
27+ }
28+
29+ return null ;
30+ }
31+
32+ public static OptionalValidity getInstance (ASN1TaggedObject taggedObject , boolean declaredExplicit )
33+ {
34+ return new OptionalValidity (ASN1Sequence .getInstance (taggedObject , declaredExplicit ));
35+ }
36+
37+ public static OptionalValidity getTagged (ASN1TaggedObject taggedObject , boolean declaredExplicit )
38+ {
39+ return new OptionalValidity (ASN1Sequence .getTagged (taggedObject , declaredExplicit ));
40+ }
41+
1742 private Time notBefore ;
1843 private Time notAfter ;
1944
@@ -26,35 +51,22 @@ private OptionalValidity(ASN1Sequence seq)
2651
2752 if (tObj .getTagNo () == 0 )
2853 {
29- notBefore = Time .getInstance (tObj , true );
54+ notBefore = Time .getInstance (tObj , true ); // CHOICE
3055 }
3156 else
3257 {
33- notAfter = Time .getInstance (tObj , true );
58+ notAfter = Time .getInstance (tObj , true ); // CHOICE
3459 }
3560 }
36- }
3761
38- public static OptionalValidity getInstance (Object o )
39- {
40- if (o instanceof OptionalValidity )
41- {
42- return (OptionalValidity )o ;
43- }
44-
45- if (o != null )
46- {
47- return new OptionalValidity (ASN1Sequence .getInstance (o ));
48- }
49-
50- return null ;
62+ // TODO[crmf] Validate the "at least one" rule after parsing?
5163 }
5264
5365 public OptionalValidity (Time notBefore , Time notAfter )
5466 {
5567 if (notBefore == null && notAfter == null )
5668 {
57- throw new IllegalArgumentException ("at least one of notBefore/notAfter must not be null ." );
69+ throw new IllegalArgumentException ("at least one of notBefore/notAfter MUST be present ." );
5870 }
5971
6072 this .notBefore = notBefore ;
@@ -74,9 +86,12 @@ public Time getNotAfter()
7486 /**
7587 * <pre>
7688 * OptionalValidity ::= SEQUENCE {
77- * notBefore [0] Time OPTIONAL,
78- * notAfter [1] Time OPTIONAL } --at least one MUST be present
89+ * notBefore [0] Time OPTIONAL,
90+ * notAfter [1] Time OPTIONAL } --at least one MUST be present
91+ *
92+ * Time ::= CHOICE { ... }
7993 * </pre>
94+ *
8095 * @return a basic ASN.1 object representation.
8196 */
8297 public ASN1Primitive toASN1Primitive ()
@@ -85,12 +100,12 @@ public ASN1Primitive toASN1Primitive()
85100
86101 if (notBefore != null )
87102 {
88- v .add (new DERTaggedObject (true , 0 , notBefore ));
103+ v .add (new DERTaggedObject (true , 0 , notBefore )); // CHOICE
89104 }
90105
91106 if (notAfter != null )
92107 {
93- v .add (new DERTaggedObject (true , 1 , notAfter ));
108+ v .add (new DERTaggedObject (true , 1 , notAfter )); // CHOICE
94109 }
95110
96111 return new DERSequence (v );
0 commit comments