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 23package org.apache.harmony.security.x509; 24 25import java.util.Date; 26 27import org.apache.harmony.security.asn1.ASN1Sequence; 28import org.apache.harmony.security.asn1.ASN1Type; 29import org.apache.harmony.security.asn1.BerInputStream; 30 31/** 32 * The class encapsulates the ASN.1 DER encoding/decoding work 33 * with Validity structure which is the part of X.509 certificate 34 * (as specified in RFC 3280 - 35 * Internet X.509 Public Key Infrastructure. 36 * Certificate and Certificate Revocation List (CRL) Profile. 37 * http://www.ietf.org/rfc/rfc3280.txt): 38 * 39 * <pre> 40 * Validity ::= SEQUENCE { 41 * notBefore Time, 42 * notAfter Time 43 * } 44 * </pre> 45 */ 46public class Validity { 47 // the value of notBefore field of the structure 48 private final Date notBefore; 49 // the value of notAfter field of the structure 50 private final Date notAfter; 51 // the ASN.1 encoded form of Validity 52 private byte[] encoding; 53 54 /** 55 * TODO 56 * @param notBefore: Date 57 * @param notAfter: Date 58 */ 59 public Validity(Date notBefore, Date notAfter) { 60 this.notBefore = notBefore; 61 this.notAfter = notAfter; 62 } 63 64 /** 65 * Returns the value of notBefore field of the structure. 66 * @return notBefore 67 */ 68 public Date getNotBefore() { 69 return notBefore; 70 } 71 72 /** 73 * Returns the value of notAfter field of the structure. 74 * @return notAfter 75 */ 76 public Date getNotAfter() { 77 return notAfter; 78 } 79 80 /** 81 * Returns ASN.1 encoded form of this X.509 Validity value. 82 * @return a byte array containing ASN.1 encode form. 83 */ 84 public byte[] getEncoded() { 85 if (encoding == null) { 86 encoding = ASN1.encode(this); 87 } 88 return encoding; 89 } 90 91 /** 92 * ASN.1 DER X.509 Validity encoder/decoder class. 93 */ 94 public static final ASN1Sequence ASN1 95 = new ASN1Sequence(new ASN1Type[] {Time.ASN1, Time.ASN1 }) { 96 97 protected Object getDecodedObject(BerInputStream in) { 98 Object[] values = (Object[]) in.content; 99 return new Validity((Date) values[0], (Date) values[1]); 100 } 101 102 protected void getValues(Object object, Object[] values) { 103 104 Validity validity = (Validity) object; 105 106 values[0] = validity.notBefore; 107 values[1] = validity.notAfter; 108 } 109 }; 110} 111