01: package org.bouncycastle.asn1.x509;
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.DERGeneralizedTime;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.DERTaggedObject;
11:
12: import java.util.Enumeration;
13:
14: /**
15: * <pre>
16: * PrivateKeyUsagePeriod ::= SEQUENCE {
17: * notBefore [0] GeneralizedTime OPTIONAL,
18: * notAfter [1] GeneralizedTime OPTIONAL }
19: * </pre>
20: */
21: public class PrivateKeyUsagePeriod extends ASN1Encodable {
22: public static PrivateKeyUsagePeriod getInstance(Object obj) {
23: if (obj instanceof PrivateKeyUsagePeriod) {
24: return (PrivateKeyUsagePeriod) obj;
25: }
26:
27: if (obj instanceof ASN1Sequence) {
28: return new PrivateKeyUsagePeriod((ASN1Sequence) obj);
29: }
30:
31: if (obj instanceof X509Extension) {
32: return getInstance(X509Extension
33: .convertValueToObject((X509Extension) obj));
34: }
35:
36: throw new IllegalArgumentException(
37: "unknown object in getInstance");
38: }
39:
40: private DERGeneralizedTime _notBefore, _notAfter;
41:
42: private PrivateKeyUsagePeriod(ASN1Sequence seq) {
43: Enumeration en = seq.getObjects();
44: while (en.hasMoreElements()) {
45: ASN1TaggedObject tObj = (ASN1TaggedObject) en.nextElement();
46:
47: if (tObj.getTagNo() == 0) {
48: _notBefore = DERGeneralizedTime
49: .getInstance(tObj, false);
50: } else if (tObj.getTagNo() == 1) {
51: _notAfter = DERGeneralizedTime.getInstance(tObj, false);
52: }
53: }
54: }
55:
56: public DERGeneralizedTime getNotBefore() {
57: return _notBefore;
58: }
59:
60: public DERGeneralizedTime getNotAfter() {
61: return _notAfter;
62: }
63:
64: public DERObject toASN1Object() {
65: ASN1EncodableVector v = new ASN1EncodableVector();
66:
67: if (_notBefore != null) {
68: v.add(new DERTaggedObject(false, 0, _notBefore));
69: }
70: if (_notAfter != null) {
71: v.add(new DERTaggedObject(false, 1, _notAfter));
72: }
73:
74: return new DERSequence(v);
75: }
76: }
|