01: package org.bouncycastle.asn1.crmf;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1TaggedObject;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERSequence;
09: import org.bouncycastle.asn1.x509.Time;
10:
11: import java.util.Enumeration;
12:
13: public class OptionalValidity extends ASN1Encodable {
14: private Time notBefore;
15: private Time notAfter;
16:
17: private OptionalValidity(ASN1Sequence seq) {
18: Enumeration en = seq.getObjects();
19: while (en.hasMoreElements()) {
20: ASN1TaggedObject tObj = (ASN1TaggedObject) en.nextElement();
21:
22: if (tObj.getTagNo() == 0) {
23: notBefore = Time.getInstance(tObj, false);
24: } else {
25: notAfter = Time.getInstance(tObj, false);
26: }
27: }
28: }
29:
30: public static OptionalValidity getInstance(Object o) {
31: if (o instanceof OptionalValidity) {
32: return (OptionalValidity) o;
33: }
34:
35: if (o instanceof ASN1Sequence) {
36: return new OptionalValidity((ASN1Sequence) o);
37: }
38:
39: throw new IllegalArgumentException("Invalid object: "
40: + o.getClass().getName());
41: }
42:
43: /**
44: * <pre>
45: * OptionalValidity ::= SEQUENCE {
46: * notBefore [0] Time OPTIONAL,
47: * notAfter [1] Time OPTIONAL } --at least one MUST be present
48: * </pre>
49: * @return a basic ASN.1 object representation.
50: */
51: public DERObject toASN1Object() {
52: ASN1EncodableVector v = new ASN1EncodableVector();
53:
54: v.add(notBefore);
55: v.add(notAfter);
56:
57: return new DERSequence(v);
58: }
59: }
|