1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @author Alexander Y. Kleymenov 20 * @version $Revision$ 21 */ 22 23 package org.apache.harmony.security.x509; 24 25 import java.util.Date; 26 import org.apache.harmony.security.asn1.ASN1Sequence; 27 import org.apache.harmony.security.asn1.ASN1Type; 28 import org.apache.harmony.security.asn1.BerInputStream; 29 30 /** 31 * The class encapsulates the ASN.1 DER encoding/decoding work 32 * with Validity structure which is the part of X.509 certificate 33 * (as specified in RFC 3280 - 34 * Internet X.509 Public Key Infrastructure. 35 * Certificate and Certificate Revocation List (CRL) Profile. 36 * http://www.ietf.org/rfc/rfc3280.txt): 37 * 38 * <pre> 39 * Validity ::= SEQUENCE { 40 * notBefore Time, 41 * notAfter Time 42 * } 43 * </pre> 44 */ 45 public class Validity { 46 // the value of notBefore field of the structure 47 private final Date notBefore; 48 // the value of notAfter field of the structure 49 private final Date notAfter; 50 // the ASN.1 encoded form of Validity 51 private byte[] encoding; 52 53 /** 54 * TODO 55 * @param notBefore: Date 56 * @param notAfter: Date 57 */ 58 public Validity(Date notBefore, Date notAfter) { 59 this.notBefore = notBefore; 60 this.notAfter = notAfter; 61 } 62 63 /** 64 * Returns the value of notBefore field of the structure. 65 * @return notBefore 66 */ 67 public Date getNotBefore() { 68 return notBefore; 69 } 70 71 /** 72 * Returns the value of notAfter field of the structure. 73 * @return notAfter 74 */ 75 public Date getNotAfter() { 76 return notAfter; 77 } 78 79 /** 80 * Returns ASN.1 encoded form of this X.509 Validity value. 81 * @return a byte array containing ASN.1 encode form. 82 */ 83 public byte[] getEncoded() { 84 if (encoding == null) { 85 encoding = ASN1.encode(this); 86 } 87 return encoding; 88 } 89 90 /** 91 * ASN.1 DER X.509 Validity encoder/decoder class. 92 */ 93 public static final ASN1Sequence ASN1 94 = new ASN1Sequence(new ASN1Type[] {Time.ASN1, Time.ASN1 }) { 95 96 protected Object getDecodedObject(BerInputStream in) { 97 Object[] values = (Object[]) in.content; 98 return new Validity((Date) values[0], (Date) values[1]); 99 } 100 101 protected void getValues(Object object, Object[] values) { 102 103 Validity validity = (Validity) object; 104 105 values[0] = validity.notBefore; 106 values[1] = validity.notAfter; 107 } 108 }; 109 } 110