1 package org.bouncycastle.asn1.x509; 2 3 import org.bouncycastle.asn1.ASN1Encodable; 4 import org.bouncycastle.asn1.ASN1EncodableVector; 5 import org.bouncycastle.asn1.ASN1Sequence; 6 import org.bouncycastle.asn1.DERGeneralizedTime; 7 import org.bouncycastle.asn1.DERObject; 8 import org.bouncycastle.asn1.DERSequence; 9 10 public class AttCertValidityPeriod 11 extends ASN1Encodable 12 { 13 DERGeneralizedTime notBeforeTime; 14 DERGeneralizedTime notAfterTime; 15 16 public static AttCertValidityPeriod getInstance( 17 Object obj) 18 { 19 if (obj instanceof AttCertValidityPeriod) 20 { 21 return (AttCertValidityPeriod)obj; 22 } 23 else if (obj instanceof ASN1Sequence) 24 { 25 return new AttCertValidityPeriod((ASN1Sequence)obj); 26 } 27 28 throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName()); 29 } 30 31 public AttCertValidityPeriod( 32 ASN1Sequence seq) 33 { 34 if (seq.size() != 2) 35 { 36 throw new IllegalArgumentException("Bad sequence size: " 37 + seq.size()); 38 } 39 40 notBeforeTime = DERGeneralizedTime.getInstance(seq.getObjectAt(0)); 41 notAfterTime = DERGeneralizedTime.getInstance(seq.getObjectAt(1)); 42 } 43 44 /** 45 * @param notBeforeTime 46 * @param notAfterTime 47 */ 48 public AttCertValidityPeriod( 49 DERGeneralizedTime notBeforeTime, 50 DERGeneralizedTime notAfterTime) 51 { 52 this.notBeforeTime = notBeforeTime; 53 this.notAfterTime = notAfterTime; 54 } 55 56 public DERGeneralizedTime getNotBeforeTime() 57 { 58 return notBeforeTime; 59 } 60 61 public DERGeneralizedTime getNotAfterTime() 62 { 63 return notAfterTime; 64 } 65 66 /** 67 * Produce an object suitable for an ASN1OutputStream. 68 * <pre> 69 * AttCertValidityPeriod ::= SEQUENCE { 70 * notBeforeTime GeneralizedTime, 71 * notAfterTime GeneralizedTime 72 * } 73 * </pre> 74 */ 75 public DERObject toASN1Object() 76 { 77 ASN1EncodableVector v = new ASN1EncodableVector(); 78 79 v.add(notBeforeTime); 80 v.add(notAfterTime); 81 82 return new DERSequence(v); 83 } 84 } 85